From b9a5399b78f5da678e3ee56a0f25571adff641b8 Mon Sep 17 00:00:00 2001 From: Paul Daulby Date: Thu, 24 Oct 2019 15:26:22 +0100 Subject: [PATCH 1/2] feat(#1488): allow Custom generators to be used in constraints --- docs/GettingStarted.md | 8 +++---- docs/UserGuide.md | 24 +++++++++++++++---- docs/user/Schema.md | 2 +- examples/a-valid-isin/profile.json | 2 +- examples/actor-names/profile.json | 2 +- examples/anyOf/profile.json | 2 +- examples/date-after/profile.json | 2 +- examples/datetime-after-dynamic/profile.json | 2 +- examples/datetime-after/profile.json | 2 +- .../profile.json | 2 +- .../datetime-equal-to-dynamic/profile.json | 2 +- examples/datetime-equal-to/profile.json | 2 +- .../datetime-offset-working-days/profile.json | 2 +- examples/demo-trades-smaller/profile.json | 2 +- examples/demo-trades/profile.json | 2 +- examples/duplicates/profile.json | 2 +- examples/formatting/profile.json | 2 +- examples/from-file-weighted/profile.json | 2 +- examples/from-file/profile.json | 2 +- .../profile.json | 2 +- .../profile.json | 2 +- .../integer-range-with-blacklist/profile.json | 2 +- examples/integer-range/profile.json | 2 +- examples/multiple-fileds/profile.json | 2 +- examples/names/profile.json | 2 +- examples/partial-contradictions/profile.json | 2 +- examples/partitioning/profile.json | 2 +- examples/real-number-range/profile.json | 2 +- examples/regex-contains/profile.json | 2 +- .../profile.json | 2 +- examples/regex-intersect/profile.json | 2 +- examples/regex/profile.json | 2 +- examples/setwise-combination/profile.json | 2 +- examples/shorter-than/profile.json | 2 +- examples/string/profile.json | 2 +- examples/unique/profile.json | 2 +- examples/user-account/profile.json | 2 +- .../cucumber/features/CustomGenerator.feature | 8 +++++++ .../testframework/steps/StringValueStep.java | 6 +++++ .../utils/CucumberTestState.java | 6 +++++ .../endtoend/loadfiletest.profile.json | 2 +- .../endtoend/testprofile.profile.json | 2 +- .../deg/profile/ConstraintDeserializer.java | 2 ++ .../deg/profile/common/ConstraintType.java | 1 + .../common/ConstraintTypeJsonProperty.java | 1 + .../constraints/GeneratorConstraintDto.java | 17 +++++++++++++ .../reader/AtomicConstraintReader.java | 7 +++++- .../profileschema/datahelix.schema.json | 21 +++++++++++++++- .../ProfileSchemaImmutabilityTests.java | 3 +++ .../reader/JsonProfileReaderTests.java | 5 ++-- .../invalid/allof-misspelled.json | 2 +- .../invalid/allof-not-enough-items.json | 2 +- .../invalid/anyof-misspelled.json | 2 +- .../invalid/anyof-not-enough-items.json | 2 +- .../invalid/constraint-empty.json | 2 +- .../invalid/constraint-field-invalid-is.json | 2 +- ...aint-field-is-null-with-value-numeric.json | 2 +- ...raint-field-is-null-with-value-string.json | 2 +- .../constraint-field-misspelled-is.json | 2 +- .../invalid/constraint-invalid-key.json | 2 +- .../invalid/constraints-field-misspelled.json | 2 +- .../containingRegex-value-numeric.json | 2 +- .../invalid/containingRegex-value-object.json | 2 +- ...after-dynamic-with-incorrect-relation.json | 2 +- .../invalid/datetime-after-misspelled.json | 2 +- .../datetime-afterorat-misspelled.json | 2 +- .../datetime-afterorat-value-invalid.json | 2 +- .../invalid/datetime-before-misspelled.json | 2 +- .../datetime-before-value-invalid.json | 2 +- .../datetime-beforeorat-misspelled.json | 2 +- .../datetime-beforeorat-value-invalid.json | 2 +- .../datetime-equalto-datetime-misspelled.json | 2 +- .../datetime-equalto-decimal-misspelled.json | 2 +- .../datetime-equalto-integer-misspelled.json | 2 +- .../datetime-equalto-string-misspelled.json | 2 +- .../invalid/empty-constraint.json | 2 +- .../invalid/field-is-with-extra-key.json | 2 +- .../invalid/field-missing-is.json | 2 +- .../invalid/fields-array-empty.json | 2 +- .../invalid/greaterThan-max.json | 2 +- .../invalid/greaterThanOrEqualTo-max.json | 2 +- .../invalid/if-else-invalid-type.json | 2 +- .../invalid/if-else-misspelled.json | 2 +- .../invalid/if-else-without-then.json | 2 +- .../test-profiles/invalid/if-extra-key.json | 2 +- .../invalid/if-invalid-type.json | 2 +- .../test-profiles/invalid/if-misspelled.json | 2 +- .../invalid/if-then-invalid-type.json | 2 +- .../invalid/if-then-misspelled.json | 2 +- .../test-profiles/invalid/lessThan-min.json | 2 +- .../invalid/lessThanOrEqualTo-min.json | 2 +- .../invalid/matchingRegex-value-numeric.json | 2 +- .../invalid/matchingRegex-value-object.json | 2 +- .../invalid/missing-constraint.json | 2 +- .../test-profiles/invalid/no-fields.json | 2 +- .../test-profiles/invalid/no-rules.json | 2 +- .../test-profiles/invalid/simple-if.json | 2 +- .../v0-2-features-in-v0-1-profile.json | 2 +- 98 files changed, 181 insertions(+), 98 deletions(-) create mode 100644 orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/CustomGenerator.feature create mode 100644 profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDto.java diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index 15fca751b..1a95f9774 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -40,7 +40,7 @@ We'll start by generating data for a trivial schema. Using your favourite text e ```json { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [{ "name": "firstName", "type": "string" }], "rules": [] } @@ -111,7 +111,7 @@ Update the JSON profile as follows: ```json { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [{ "name": "firstName", "type": "string" }], "rules": [ { @@ -190,7 +190,7 @@ We'll expand the example profile to add a new `age` field, a not-null integer in ```json { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [ { "name": "firstName", "type": "string" }, { "name": "age", "type": "integer" } @@ -237,7 +237,7 @@ Finally, we'll add a field for National Insurance number. In this case, the cons ```json { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [ { "name": "firstName", "type": "string" }, { "name": "age", "type": "integer" }, diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 0a758d569..f066bbdfd 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -56,6 +56,7 @@ 7. [Custom Generators](#custom-generator) 1. [adding](#adding-custom-generator) 2. [using](#using-custom-generator) + 3. [using as constraint](#using-custom-generator-as-constraint) 8. [Running a Profile](#Running-a-Profile) 1. [Command Line Arguments](#Command-Line-Arguments) @@ -87,9 +88,9 @@ This section will walk you through creating basic profiles with which you can ge Profiles are JSON documents consisting of three sections, the schema version, the list of fields and the rules. - **Schema Version** - Dictates the method of serialisation of the profile in order for the generator to -interpret the profile fields and rules. The latest version is 0.7. +interpret the profile fields and rules. The latest version is ``` - "schemaVersion": "0.7", + "schemaVersion": "0.16", ``` - **List of Fields** - An array of column headings is defined with unique "name" keys. ``` @@ -140,7 +141,7 @@ These three sections are combined to form the [complete profile](#Example-Profil ## Example Profile { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [ { "name": "Column 1", @@ -668,7 +669,6 @@ While it's not prohibited, wrapping conditional constraints in any other kind of - # Custom Generators
@@ -704,6 +704,22 @@ This will use the "lorem ipsum" example custom generator. To use your own, put the name of your generator instead of "lorem ipsum" +## using Custom Generators as Constraint +
+ +You can also use custom generators as constraints + + +```javascript +{ "field": "field1", "generator": "lorem ipsum" } +``` + +Custom generators can be used in "anyOf" grammatical constraints, as well as in the "then" and "else" parts of conditional constraints + +To combine generators with sets and equalTo, you will need to create a 'matchingFunction' when building the custom generator. Which should be a function that returns true if a value is one the custom generator could produce. + +To be able negate the custom generator, or use in the 'if' section of an if then statement, you must define the 'negated Generator' when building the custom generator. Which should return values that the custom generator should not produce. + # Running a Profile
diff --git a/docs/user/Schema.md b/docs/user/Schema.md index 508241753..28dad662c 100644 --- a/docs/user/Schema.md +++ b/docs/user/Schema.md @@ -3,7 +3,7 @@ ## Sample file ```javascript { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "description": "A dataset about financial products", "fields": [ diff --git a/examples/a-valid-isin/profile.json b/examples/a-valid-isin/profile.json index 630561deb..656e99b99 100644 --- a/examples/a-valid-isin/profile.json +++ b/examples/a-valid-isin/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "isin", diff --git a/examples/actor-names/profile.json b/examples/actor-names/profile.json index 0f62dc469..8faad2720 100644 --- a/examples/actor-names/profile.json +++ b/examples/actor-names/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "forename", diff --git a/examples/anyOf/profile.json b/examples/anyOf/profile.json index b24feea53..0dec5cc8f 100644 --- a/examples/anyOf/profile.json +++ b/examples/anyOf/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/examples/date-after/profile.json b/examples/date-after/profile.json index e75163333..611d53e88 100644 --- a/examples/date-after/profile.json +++ b/examples/date-after/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "date", diff --git a/examples/datetime-after-dynamic/profile.json b/examples/datetime-after-dynamic/profile.json index 1ab56923a..99bd46687 100644 --- a/examples/datetime-after-dynamic/profile.json +++ b/examples/datetime-after-dynamic/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "field1", diff --git a/examples/datetime-after/profile.json b/examples/datetime-after/profile.json index d36777c44..162c8f902 100644 --- a/examples/datetime-after/profile.json +++ b/examples/datetime-after/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "date", diff --git a/examples/datetime-equal-to-dynamic-offset/profile.json b/examples/datetime-equal-to-dynamic-offset/profile.json index d0b723c8b..53492aa06 100644 --- a/examples/datetime-equal-to-dynamic-offset/profile.json +++ b/examples/datetime-equal-to-dynamic-offset/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "first", diff --git a/examples/datetime-equal-to-dynamic/profile.json b/examples/datetime-equal-to-dynamic/profile.json index 240f2fd32..bdcf2b614 100644 --- a/examples/datetime-equal-to-dynamic/profile.json +++ b/examples/datetime-equal-to-dynamic/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "first", diff --git a/examples/datetime-equal-to/profile.json b/examples/datetime-equal-to/profile.json index 9d9009c7e..0ce24f24c 100644 --- a/examples/datetime-equal-to/profile.json +++ b/examples/datetime-equal-to/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "date", diff --git a/examples/datetime-offset-working-days/profile.json b/examples/datetime-offset-working-days/profile.json index e2753824e..f69d4ac27 100644 --- a/examples/datetime-offset-working-days/profile.json +++ b/examples/datetime-offset-working-days/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "foo", diff --git a/examples/demo-trades-smaller/profile.json b/examples/demo-trades-smaller/profile.json index 81a850c40..c7824bca6 100644 --- a/examples/demo-trades-smaller/profile.json +++ b/examples/demo-trades-smaller/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "tradeId", diff --git a/examples/demo-trades/profile.json b/examples/demo-trades/profile.json index 5f424b0c0..a98ff9779 100644 --- a/examples/demo-trades/profile.json +++ b/examples/demo-trades/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "tradeId", diff --git a/examples/duplicates/profile.json b/examples/duplicates/profile.json index d965544b2..098a6256d 100644 --- a/examples/duplicates/profile.json +++ b/examples/duplicates/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "a", diff --git a/examples/formatting/profile.json b/examples/formatting/profile.json index e1b7589b5..242a2efd9 100644 --- a/examples/formatting/profile.json +++ b/examples/formatting/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "decimal", diff --git a/examples/from-file-weighted/profile.json b/examples/from-file-weighted/profile.json index 187f1b67e..badbe6331 100644 --- a/examples/from-file-weighted/profile.json +++ b/examples/from-file-weighted/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "name", diff --git a/examples/from-file/profile.json b/examples/from-file/profile.json index 187f1b67e..badbe6331 100644 --- a/examples/from-file/profile.json +++ b/examples/from-file/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "name", diff --git a/examples/hard-contradiction-null-validation/profile.json b/examples/hard-contradiction-null-validation/profile.json index c956d3cc7..57fa50e9b 100644 --- a/examples/hard-contradiction-null-validation/profile.json +++ b/examples/hard-contradiction-null-validation/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "Column 1", diff --git a/examples/hard-contradiction-range-and-granular/profile.json b/examples/hard-contradiction-range-and-granular/profile.json index 5fafe7801..ac94f791d 100644 --- a/examples/hard-contradiction-range-and-granular/profile.json +++ b/examples/hard-contradiction-range-and-granular/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "Column 1", diff --git a/examples/integer-range-with-blacklist/profile.json b/examples/integer-range-with-blacklist/profile.json index 3263c5358..ca3c70a70 100644 --- a/examples/integer-range-with-blacklist/profile.json +++ b/examples/integer-range-with-blacklist/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "an_integer", diff --git a/examples/integer-range/profile.json b/examples/integer-range/profile.json index 01d416ba8..afd3a2e96 100644 --- a/examples/integer-range/profile.json +++ b/examples/integer-range/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "an_integer", diff --git a/examples/multiple-fileds/profile.json b/examples/multiple-fileds/profile.json index 220179436..8ea898acd 100644 --- a/examples/multiple-fileds/profile.json +++ b/examples/multiple-fileds/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "field1", diff --git a/examples/names/profile.json b/examples/names/profile.json index d84067435..fa52ebd89 100644 --- a/examples/names/profile.json +++ b/examples/names/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "forename", diff --git a/examples/partial-contradictions/profile.json b/examples/partial-contradictions/profile.json index bd5b8260b..c11e07d98 100644 --- a/examples/partial-contradictions/profile.json +++ b/examples/partial-contradictions/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "Column 1", diff --git a/examples/partitioning/profile.json b/examples/partitioning/profile.json index 1c37d7e74..9ee3bf3b6 100644 --- a/examples/partitioning/profile.json +++ b/examples/partitioning/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "p1f1", diff --git a/examples/real-number-range/profile.json b/examples/real-number-range/profile.json index c2a62a4b9..949160316 100644 --- a/examples/real-number-range/profile.json +++ b/examples/real-number-range/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "a_number", diff --git a/examples/regex-contains/profile.json b/examples/regex-contains/profile.json index 6013a0794..a22143288 100644 --- a/examples/regex-contains/profile.json +++ b/examples/regex-contains/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "first_name", diff --git a/examples/regex-intersect-with-blacklist/profile.json b/examples/regex-intersect-with-blacklist/profile.json index 4cf46bde1..3f33ce5f0 100644 --- a/examples/regex-intersect-with-blacklist/profile.json +++ b/examples/regex-intersect-with-blacklist/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "first_name", diff --git a/examples/regex-intersect/profile.json b/examples/regex-intersect/profile.json index d0863ee02..2bf149758 100644 --- a/examples/regex-intersect/profile.json +++ b/examples/regex-intersect/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "first_name", diff --git a/examples/regex/profile.json b/examples/regex/profile.json index 011cb0182..5ff8a6560 100644 --- a/examples/regex/profile.json +++ b/examples/regex/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "first_name", diff --git a/examples/setwise-combination/profile.json b/examples/setwise-combination/profile.json index 17d08e5b4..69bb6afcb 100644 --- a/examples/setwise-combination/profile.json +++ b/examples/setwise-combination/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "a", diff --git a/examples/shorter-than/profile.json b/examples/shorter-than/profile.json index 627e7f5e7..37846bbb0 100644 --- a/examples/shorter-than/profile.json +++ b/examples/shorter-than/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "first_name", diff --git a/examples/string/profile.json b/examples/string/profile.json index 1901e15d5..37de01d10 100644 --- a/examples/string/profile.json +++ b/examples/string/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "rules": [], "fields": [ { diff --git a/examples/unique/profile.json b/examples/unique/profile.json index 00b09ebfe..b4c9a1198 100644 --- a/examples/unique/profile.json +++ b/examples/unique/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "id", diff --git a/examples/user-account/profile.json b/examples/user-account/profile.json index c4ed1a5d3..e9e6c5058 100644 --- a/examples/user-account/profile.json +++ b/examples/user-account/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "user_id", diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/CustomGenerator.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/CustomGenerator.feature new file mode 100644 index 000000000..304f253b1 --- /dev/null +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/CustomGenerator.feature @@ -0,0 +1,8 @@ +Feature: Generator use custom generators. + + Scenario: custom lorem ipsum generator can output rows + Given the generation strategy is Random + And the generator can generate at most 1 rows + And there is a field foo + And foo uses custom generator "lorem ipsum" + Then the generator can generate at most 1 rows diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/StringValueStep.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/StringValueStep.java index d950b0474..2a66924a0 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/StringValueStep.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/StringValueStep.java @@ -123,6 +123,12 @@ public void producedDataShouldContainStringValuesOutOfRangeForField(String field value -> !isLengthBetweenInclusively(min, max).apply(value)); } + + @When("^([A-z0-9]+) uses custom generator \"(.*)\"$") + public void customGenerator(String fieldName, String value) { + state.addConstraint(fieldName, ConstraintType.EQUAL_TO, value); + } + private Function isLengthBetweenInclusively(int minInclusive, int maxInclusive){ return value -> isLongerThanOrEqual(value, minInclusive) && isShorterThanOrEqual(value, maxInclusive); } diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java index 1d2e2e178..9cad043d2 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java @@ -232,6 +232,12 @@ private ConstraintDTO createConstraint(String fieldName, ConstraintType type, Ob field = fieldName; value = (String) _value; }}; + case GENERATOR: + return new GeneratorConstraintDto() + {{ + field = fieldName; + generator = (String) _value; + }}; default: return null; } diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/loadfiletest.profile.json b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/loadfiletest.profile.json index 5f208dd8b..f7fc11442 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/loadfiletest.profile.json +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/loadfiletest.profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "fields": [ { "name": "foo", diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/testprofile.profile.json b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/testprofile.profile.json index fcf59c6af..c1c5c3a6d 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/testprofile.profile.json +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/testprofile.profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.15", + "schemaVersion": "0.16", "description": "Testing Profile", "fields": [ { diff --git a/profile/src/main/java/com/scottlogic/deg/profile/ConstraintDeserializer.java b/profile/src/main/java/com/scottlogic/deg/profile/ConstraintDeserializer.java index 65739998c..3d1576f83 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/ConstraintDeserializer.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/ConstraintDeserializer.java @@ -84,6 +84,8 @@ public ConstraintDTO deserialize(JsonParser jsonParser, DeserializationContext c return mapper.treeToValue(node, BeforeOrAtConstraintDTO.class); case BEFORE_OR_AT_FIELD: return mapper.treeToValue(node, BeforeOrAtFieldConstraintDTO.class); + case GENERATOR: + return mapper.treeToValue(node, GeneratorConstraintDto.class); case NOT: return mapper.treeToValue(node, NotConstraintDTO.class); case ANY_OF: diff --git a/profile/src/main/java/com/scottlogic/deg/profile/common/ConstraintType.java b/profile/src/main/java/com/scottlogic/deg/profile/common/ConstraintType.java index 20126b817..5a2e08a2d 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/common/ConstraintType.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/common/ConstraintType.java @@ -34,6 +34,7 @@ public enum ConstraintType { BEFORE_FIELD(ConstraintTypeJsonProperty.BEFORE_FIELD), BEFORE_OR_AT(ConstraintTypeJsonProperty.BEFORE_OR_AT), BEFORE_OR_AT_FIELD(ConstraintTypeJsonProperty.BEFORE_OR_AT_FIELD), + GENERATOR(ConstraintTypeJsonProperty.GENERATOR), NOT(ConstraintTypeJsonProperty.NOT), ANY_OF(ConstraintTypeJsonProperty.ANY_OF), ALL_OF(ConstraintTypeJsonProperty.ALL_OF), diff --git a/profile/src/main/java/com/scottlogic/deg/profile/common/ConstraintTypeJsonProperty.java b/profile/src/main/java/com/scottlogic/deg/profile/common/ConstraintTypeJsonProperty.java index 196182063..296d7589b 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/common/ConstraintTypeJsonProperty.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/common/ConstraintTypeJsonProperty.java @@ -28,6 +28,7 @@ public class ConstraintTypeJsonProperty { public static final String BEFORE_FIELD = "beforeField"; public static final String BEFORE_OR_AT = "beforeOrAt"; public static final String BEFORE_OR_AT_FIELD = "beforeOrAtField"; + public static final String GENERATOR = "generator"; public static final String NOT = "not"; public static final String ANY_OF = "anyOf"; public static final String ALL_OF = "allOf"; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDto.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDto.java new file mode 100644 index 000000000..e1d423ffb --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDto.java @@ -0,0 +1,17 @@ +package com.scottlogic.deg.profile.dtos.constraints; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.scottlogic.deg.profile.common.ConstraintType; +import com.scottlogic.deg.profile.common.ConstraintTypeJsonProperty; + +@JsonDeserialize(as = GeneratorConstraintDto.class) +public class GeneratorConstraintDto extends AtomicConstraintDTO { + + @JsonProperty(ConstraintTypeJsonProperty.GENERATOR) + public String generator; + + public GeneratorConstraintDto() { + super(ConstraintType.GENERATOR); + } +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintReader.java index aaf888890..86d6c05b1 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/AtomicConstraintReader.java @@ -23,6 +23,7 @@ import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.profile.constraints.Constraint; import com.scottlogic.deg.generator.profile.constraints.atomic.*; +import com.scottlogic.deg.profile.custom.CustomConstraintFactory; import com.scottlogic.deg.profile.dtos.constraints.*; import org.jetbrains.annotations.Nullable; @@ -32,10 +33,12 @@ public class AtomicConstraintReader { private final FileReader fileReader; + private final CustomConstraintFactory customConstraintFactory; @Inject - public AtomicConstraintReader(FileReader fileReader) { + public AtomicConstraintReader(FileReader fileReader, CustomConstraintFactory customConstraintFactory) { this.fileReader = fileReader; + this.customConstraintFactory = customConstraintFactory; } public Constraint readAtomicConstraintDto(AtomicConstraintDTO dto, ProfileFields profileFields) { @@ -88,6 +91,8 @@ public Constraint readAtomicConstraintDto(AtomicConstraintDTO dto, ProfileFields return ((NullConstraintDTO)dto).isNull ? isNullConstraint : isNullConstraint.negate(); + case GENERATOR: + return customConstraintFactory.create(field, ((GeneratorConstraintDto)dto).generator); default: throw new InvalidProfileException("Atomic constraint type not found: " + dto); } diff --git a/profile/src/main/resources/profileschema/datahelix.schema.json b/profile/src/main/resources/profileschema/datahelix.schema.json index 5d68b9b99..ca74beb15 100644 --- a/profile/src/main/resources/profileschema/datahelix.schema.json +++ b/profile/src/main/resources/profileschema/datahelix.schema.json @@ -57,7 +57,7 @@ "definitions": { "schemaVersion": { "title": "The version of the DataHelix profile schema", - "const": "0.15" + "const": "0.16" }, "dataType": { "oneOf": [ @@ -196,6 +196,9 @@ }, "constraint": { "oneOf": [ + { + "$ref": "#/definitions/generatorConstraint" + }, { "$ref": "#/definitions/equalToConstraint" }, @@ -291,6 +294,22 @@ } ] }, + "generatorConstraint": { + "type": "object", + "additionalProperties": false, + "required": [ + "field", + "generator" + ], + "properties": { + "field": { + "type": "string" + }, + "generator": { + "$ref": "#/definitions/string" + } + } + }, "equalToConstraint": { "type": "object", "additionalProperties": false, diff --git a/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java b/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java index 9c3bd595d..06d5898a4 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java @@ -102,6 +102,9 @@ private static Set versionToHash() { versionToHash.add(new VersionHash( "0.15", "10dce72a089be2a68f1577adadabff74831d1c063b2e12028b16cbb371493062")); + versionToHash.add(new VersionHash( + "0.16", + "57f54d03ba86f5811f95e8ae5969e5b1fe62347cfc18cefe69fbf5130703522e")); return versionToHash; } diff --git a/profile/src/test/java/com/scottlogic/deg/profile/reader/JsonProfileReaderTests.java b/profile/src/test/java/com/scottlogic/deg/profile/reader/JsonProfileReaderTests.java index c1e339f20..980a38121 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/reader/JsonProfileReaderTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/reader/JsonProfileReaderTests.java @@ -48,8 +48,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.core.IsNull.nullValue; - - +import static org.mockito.Mockito.mock; public class JsonProfileReaderTests { @@ -82,7 +81,7 @@ public DistributedList listFromMapFile(String file, String Key) private JsonProfileReader jsonProfileReader = new JsonProfileReader( null, - new ConstraintReader(new AtomicConstraintReader(new MockFromFileReader())), + new ConstraintReader(new AtomicConstraintReader(new MockFromFileReader(), mock(CustomConstraintFactory.class))), new CustomConstraintFactory(new CustomGeneratorList())); private void givenJson(String json) { diff --git a/profile/src/test/resources/test-profiles/invalid/allof-misspelled.json b/profile/src/test/resources/test-profiles/invalid/allof-misspelled.json index 87f6f94b8..e8567310c 100644 --- a/profile/src/test/resources/test-profiles/invalid/allof-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/allof-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "constraints": [ diff --git a/profile/src/test/resources/test-profiles/invalid/allof-not-enough-items.json b/profile/src/test/resources/test-profiles/invalid/allof-not-enough-items.json index c76069701..9d307c912 100644 --- a/profile/src/test/resources/test-profiles/invalid/allof-not-enough-items.json +++ b/profile/src/test/resources/test-profiles/invalid/allof-not-enough-items.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "constraints": [ diff --git a/profile/src/test/resources/test-profiles/invalid/anyof-misspelled.json b/profile/src/test/resources/test-profiles/invalid/anyof-misspelled.json index c915a7998..af01f8126 100644 --- a/profile/src/test/resources/test-profiles/invalid/anyof-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/anyof-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "constraints": [ diff --git a/profile/src/test/resources/test-profiles/invalid/anyof-not-enough-items.json b/profile/src/test/resources/test-profiles/invalid/anyof-not-enough-items.json index 055a115ad..452b8b358 100644 --- a/profile/src/test/resources/test-profiles/invalid/anyof-not-enough-items.json +++ b/profile/src/test/resources/test-profiles/invalid/anyof-not-enough-items.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "constraints": [ diff --git a/profile/src/test/resources/test-profiles/invalid/constraint-empty.json b/profile/src/test/resources/test-profiles/invalid/constraint-empty.json index 6e30a1f73..45a0f9211 100644 --- a/profile/src/test/resources/test-profiles/invalid/constraint-empty.json +++ b/profile/src/test/resources/test-profiles/invalid/constraint-empty.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/constraint-field-invalid-is.json b/profile/src/test/resources/test-profiles/invalid/constraint-field-invalid-is.json index 930a03001..3c96981c7 100644 --- a/profile/src/test/resources/test-profiles/invalid/constraint-field-invalid-is.json +++ b/profile/src/test/resources/test-profiles/invalid/constraint-field-invalid-is.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/constraint-field-is-null-with-value-numeric.json b/profile/src/test/resources/test-profiles/invalid/constraint-field-is-null-with-value-numeric.json index ada306f62..f6d0da3ad 100644 --- a/profile/src/test/resources/test-profiles/invalid/constraint-field-is-null-with-value-numeric.json +++ b/profile/src/test/resources/test-profiles/invalid/constraint-field-is-null-with-value-numeric.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/constraint-field-is-null-with-value-string.json b/profile/src/test/resources/test-profiles/invalid/constraint-field-is-null-with-value-string.json index 5ac7f7164..b8e2d7fc8 100644 --- a/profile/src/test/resources/test-profiles/invalid/constraint-field-is-null-with-value-string.json +++ b/profile/src/test/resources/test-profiles/invalid/constraint-field-is-null-with-value-string.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/constraint-field-misspelled-is.json b/profile/src/test/resources/test-profiles/invalid/constraint-field-misspelled-is.json index 4001708c9..1f7a945c9 100644 --- a/profile/src/test/resources/test-profiles/invalid/constraint-field-misspelled-is.json +++ b/profile/src/test/resources/test-profiles/invalid/constraint-field-misspelled-is.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/constraint-invalid-key.json b/profile/src/test/resources/test-profiles/invalid/constraint-invalid-key.json index 07565ffeb..fc3fe6c7e 100644 --- a/profile/src/test/resources/test-profiles/invalid/constraint-invalid-key.json +++ b/profile/src/test/resources/test-profiles/invalid/constraint-invalid-key.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/constraints-field-misspelled.json b/profile/src/test/resources/test-profiles/invalid/constraints-field-misspelled.json index c5e40bb56..264640b0e 100644 --- a/profile/src/test/resources/test-profiles/invalid/constraints-field-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/constraints-field-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/containingRegex-value-numeric.json b/profile/src/test/resources/test-profiles/invalid/containingRegex-value-numeric.json index 74da7ea4f..9bd068259 100644 --- a/profile/src/test/resources/test-profiles/invalid/containingRegex-value-numeric.json +++ b/profile/src/test/resources/test-profiles/invalid/containingRegex-value-numeric.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [ { "name": "field1" diff --git a/profile/src/test/resources/test-profiles/invalid/containingRegex-value-object.json b/profile/src/test/resources/test-profiles/invalid/containingRegex-value-object.json index aa01f231b..906a4f420 100644 --- a/profile/src/test/resources/test-profiles/invalid/containingRegex-value-object.json +++ b/profile/src/test/resources/test-profiles/invalid/containingRegex-value-object.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [ { "name": "field1" diff --git a/profile/src/test/resources/test-profiles/invalid/date-after-dynamic-with-incorrect-relation.json b/profile/src/test/resources/test-profiles/invalid/date-after-dynamic-with-incorrect-relation.json index a6a8547e3..b01911096 100644 --- a/profile/src/test/resources/test-profiles/invalid/date-after-dynamic-with-incorrect-relation.json +++ b/profile/src/test/resources/test-profiles/invalid/date-after-dynamic-with-incorrect-relation.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [ { "name": "field1" diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-after-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-after-misspelled.json index 442caacd7..d9e2500cc 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-after-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-after-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-misspelled.json index 37dfc375d..349ffbf93 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-value-invalid.json b/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-value-invalid.json index 0962e6e9f..37307ae9a 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-value-invalid.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-value-invalid.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-before-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-before-misspelled.json index 1f70cf512..51688c78e 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-before-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-before-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-before-value-invalid.json b/profile/src/test/resources/test-profiles/invalid/datetime-before-value-invalid.json index b20d0c28c..3320dcc28 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-before-value-invalid.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-before-value-invalid.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-misspelled.json index cb7ce9262..472851de5 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-value-invalid.json b/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-value-invalid.json index 9abd4b1ad..62cd9ca36 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-value-invalid.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-value-invalid.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-equalto-datetime-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-equalto-datetime-misspelled.json index a3ecd6651..debd3d2ee 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-equalto-datetime-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-equalto-datetime-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-equalto-decimal-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-equalto-decimal-misspelled.json index 4b984710e..131346644 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-equalto-decimal-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-equalto-decimal-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-equalto-integer-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-equalto-integer-misspelled.json index ee10302fe..ab65afc46 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-equalto-integer-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-equalto-integer-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-equalto-string-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-equalto-string-misspelled.json index a3ecd6651..debd3d2ee 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-equalto-string-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-equalto-string-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/empty-constraint.json b/profile/src/test/resources/test-profiles/invalid/empty-constraint.json index 6e30a1f73..45a0f9211 100644 --- a/profile/src/test/resources/test-profiles/invalid/empty-constraint.json +++ b/profile/src/test/resources/test-profiles/invalid/empty-constraint.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/field-is-with-extra-key.json b/profile/src/test/resources/test-profiles/invalid/field-is-with-extra-key.json index 4c7dbb57a..9c16db564 100644 --- a/profile/src/test/resources/test-profiles/invalid/field-is-with-extra-key.json +++ b/profile/src/test/resources/test-profiles/invalid/field-is-with-extra-key.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/field-missing-is.json b/profile/src/test/resources/test-profiles/invalid/field-missing-is.json index 930a03001..3c96981c7 100644 --- a/profile/src/test/resources/test-profiles/invalid/field-missing-is.json +++ b/profile/src/test/resources/test-profiles/invalid/field-missing-is.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/fields-array-empty.json b/profile/src/test/resources/test-profiles/invalid/fields-array-empty.json index d6b374354..94f089dd4 100644 --- a/profile/src/test/resources/test-profiles/invalid/fields-array-empty.json +++ b/profile/src/test/resources/test-profiles/invalid/fields-array-empty.json @@ -1,5 +1,5 @@ { "fields": [], "rules": [], - "schemaVersion": "0.7" + "schemaVersion": "0.16" } \ No newline at end of file diff --git a/profile/src/test/resources/test-profiles/invalid/greaterThan-max.json b/profile/src/test/resources/test-profiles/invalid/greaterThan-max.json index d197e39eb..cb93ef764 100644 --- a/profile/src/test/resources/test-profiles/invalid/greaterThan-max.json +++ b/profile/src/test/resources/test-profiles/invalid/greaterThan-max.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/greaterThanOrEqualTo-max.json b/profile/src/test/resources/test-profiles/invalid/greaterThanOrEqualTo-max.json index 2514bea1a..d25665100 100644 --- a/profile/src/test/resources/test-profiles/invalid/greaterThanOrEqualTo-max.json +++ b/profile/src/test/resources/test-profiles/invalid/greaterThanOrEqualTo-max.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/if-else-invalid-type.json b/profile/src/test/resources/test-profiles/invalid/if-else-invalid-type.json index f08591f29..8097b20f7 100644 --- a/profile/src/test/resources/test-profiles/invalid/if-else-invalid-type.json +++ b/profile/src/test/resources/test-profiles/invalid/if-else-invalid-type.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/if-else-misspelled.json b/profile/src/test/resources/test-profiles/invalid/if-else-misspelled.json index bac0e5f2d..3661e3446 100644 --- a/profile/src/test/resources/test-profiles/invalid/if-else-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/if-else-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/if-else-without-then.json b/profile/src/test/resources/test-profiles/invalid/if-else-without-then.json index 7cafec941..f0ad57640 100644 --- a/profile/src/test/resources/test-profiles/invalid/if-else-without-then.json +++ b/profile/src/test/resources/test-profiles/invalid/if-else-without-then.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/if-extra-key.json b/profile/src/test/resources/test-profiles/invalid/if-extra-key.json index 77d937d7d..eb34de5d1 100644 --- a/profile/src/test/resources/test-profiles/invalid/if-extra-key.json +++ b/profile/src/test/resources/test-profiles/invalid/if-extra-key.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/if-invalid-type.json b/profile/src/test/resources/test-profiles/invalid/if-invalid-type.json index 28bedfefb..674a22c2b 100644 --- a/profile/src/test/resources/test-profiles/invalid/if-invalid-type.json +++ b/profile/src/test/resources/test-profiles/invalid/if-invalid-type.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/if-misspelled.json b/profile/src/test/resources/test-profiles/invalid/if-misspelled.json index e2ac6abce..3593a7caa 100644 --- a/profile/src/test/resources/test-profiles/invalid/if-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/if-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/if-then-invalid-type.json b/profile/src/test/resources/test-profiles/invalid/if-then-invalid-type.json index aadca3b54..2a7932d66 100644 --- a/profile/src/test/resources/test-profiles/invalid/if-then-invalid-type.json +++ b/profile/src/test/resources/test-profiles/invalid/if-then-invalid-type.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/if-then-misspelled.json b/profile/src/test/resources/test-profiles/invalid/if-then-misspelled.json index bdedbb79c..9777a8d5a 100644 --- a/profile/src/test/resources/test-profiles/invalid/if-then-misspelled.json +++ b/profile/src/test/resources/test-profiles/invalid/if-then-misspelled.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/lessThan-min.json b/profile/src/test/resources/test-profiles/invalid/lessThan-min.json index cd75d70c1..887742507 100644 --- a/profile/src/test/resources/test-profiles/invalid/lessThan-min.json +++ b/profile/src/test/resources/test-profiles/invalid/lessThan-min.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/lessThanOrEqualTo-min.json b/profile/src/test/resources/test-profiles/invalid/lessThanOrEqualTo-min.json index ddb37fd1d..8bafb89d7 100644 --- a/profile/src/test/resources/test-profiles/invalid/lessThanOrEqualTo-min.json +++ b/profile/src/test/resources/test-profiles/invalid/lessThanOrEqualTo-min.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/matchingRegex-value-numeric.json b/profile/src/test/resources/test-profiles/invalid/matchingRegex-value-numeric.json index 3deb20fd3..7b2c88c5b 100644 --- a/profile/src/test/resources/test-profiles/invalid/matchingRegex-value-numeric.json +++ b/profile/src/test/resources/test-profiles/invalid/matchingRegex-value-numeric.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [ { "name": "field1" diff --git a/profile/src/test/resources/test-profiles/invalid/matchingRegex-value-object.json b/profile/src/test/resources/test-profiles/invalid/matchingRegex-value-object.json index 90afa6b73..855234363 100644 --- a/profile/src/test/resources/test-profiles/invalid/matchingRegex-value-object.json +++ b/profile/src/test/resources/test-profiles/invalid/matchingRegex-value-object.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [ { "name": "field1" diff --git a/profile/src/test/resources/test-profiles/invalid/missing-constraint.json b/profile/src/test/resources/test-profiles/invalid/missing-constraint.json index 7d4b275a1..9c69029c9 100644 --- a/profile/src/test/resources/test-profiles/invalid/missing-constraint.json +++ b/profile/src/test/resources/test-profiles/invalid/missing-constraint.json @@ -7,6 +7,6 @@ "name": "field2" } ], - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [{"rule": "rule 1"}] } \ No newline at end of file diff --git a/profile/src/test/resources/test-profiles/invalid/no-fields.json b/profile/src/test/resources/test-profiles/invalid/no-fields.json index 8a3299abe..c06b7c098 100644 --- a/profile/src/test/resources/test-profiles/invalid/no-fields.json +++ b/profile/src/test/resources/test-profiles/invalid/no-fields.json @@ -15,5 +15,5 @@ ] } ], - "schemaVersion": "0.7" + "schemaVersion": "0.16" } \ No newline at end of file diff --git a/profile/src/test/resources/test-profiles/invalid/no-rules.json b/profile/src/test/resources/test-profiles/invalid/no-rules.json index 44296c1f1..7bff85e2c 100644 --- a/profile/src/test/resources/test-profiles/invalid/no-rules.json +++ b/profile/src/test/resources/test-profiles/invalid/no-rules.json @@ -7,5 +7,5 @@ "name": "field2" } ], - "schemaVersion": "0.7" + "schemaVersion": "0.16" } \ No newline at end of file diff --git a/profile/src/test/resources/test-profiles/invalid/simple-if.json b/profile/src/test/resources/test-profiles/invalid/simple-if.json index 67e30c67c..99c220094 100644 --- a/profile/src/test/resources/test-profiles/invalid/simple-if.json +++ b/profile/src/test/resources/test-profiles/invalid/simple-if.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "rules": [ { "rule": "rule 1", diff --git a/profile/src/test/resources/test-profiles/invalid/v0-2-features-in-v0-1-profile.json b/profile/src/test/resources/test-profiles/invalid/v0-2-features-in-v0-1-profile.json index d9047adc3..93dfd5018 100644 --- a/profile/src/test/resources/test-profiles/invalid/v0-2-features-in-v0-1-profile.json +++ b/profile/src/test/resources/test-profiles/invalid/v0-2-features-in-v0-1-profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.7", + "schemaVersion": "0.16", "fields": [ { "name": "first" From c98163948cecdca83cc54c47463e369361ebf1c0 Mon Sep 17 00:00:00 2001 From: willsalt-sl Date: Mon, 11 Nov 2019 16:57:38 +0000 Subject: [PATCH 2/2] #1488 Add missing copyright header and rename class to match others. --- .../utils/CucumberTestState.java | 2 +- .../dtos/constraints/ConstraintType.java | 2 +- .../constraints/GeneratorConstraintDTO.java | 29 +++++++++++++++++++ .../constraints/GeneratorConstraintDto.java | 13 --------- 4 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDTO.java delete mode 100644 profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDto.java diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java index a209eaf88..b35d15c22 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java @@ -226,7 +226,7 @@ private ConstraintDTO createConstraint(String fieldName, ConstraintType type, Ob value = (String) _value; }}; case GENERATOR: - return new GeneratorConstraintDto() + return new GeneratorConstraintDTO() {{ field = fieldName; generator = (String) _value; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java index 1456c14a1..b24b3feea 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/ConstraintType.java @@ -75,7 +75,7 @@ public enum ConstraintType { ALL_OF(AllOfConstraintDTO.NAME, AllOfConstraintDTO.class), IF(ConditionalConstraintDTO.NAME, ConditionalConstraintDTO.class), INVALID(InvalidConstraintDTO.NAME, InvalidConstraintDTO.class), - GENERATOR(GeneratorConstraintDto.NAME, GeneratorConstraintDto.class); + GENERATOR(GeneratorConstraintDTO.NAME, GeneratorConstraintDTO.class); public final String propertyName; public final Class clazz; diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDTO.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDTO.java new file mode 100644 index 000000000..d0797105e --- /dev/null +++ b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDTO.java @@ -0,0 +1,29 @@ +/* + * Copyright 2019 Scott Logic Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.scottlogic.deg.profile.dtos.constraints; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.scottlogic.deg.profile.dtos.constraints.atomic.AtomicConstraintDTO; + +@JsonDeserialize(as = GeneratorConstraintDTO.class) +public class GeneratorConstraintDTO extends AtomicConstraintDTO { + public static final String NAME = "generator"; + + @JsonProperty(NAME) + public String generator; +} diff --git a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDto.java b/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDto.java deleted file mode 100644 index ccb93055c..000000000 --- a/profile/src/main/java/com/scottlogic/deg/profile/dtos/constraints/GeneratorConstraintDto.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.scottlogic.deg.profile.dtos.constraints; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.scottlogic.deg.profile.dtos.constraints.atomic.AtomicConstraintDTO; - -@JsonDeserialize(as = GeneratorConstraintDto.class) -public class GeneratorConstraintDto extends AtomicConstraintDTO { - public static final String NAME = "generator"; - - @JsonProperty(NAME) - public String generator; -}