From 6e7a12393da6aaea90bd75cfa454a5029bebbba8 Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Tue, 1 Oct 2019 15:02:16 +0100 Subject: [PATCH 1/6] fix(#1382): Profile date value syntax simplified & Examples updated --- examples/date-after-dynamic/profile.json | 4 +--- examples/date-after/profile.json | 4 +--- .../date-equal-to-dynamic-offset/profile.json | 16 ++++---------- examples/date-equal-to-dynamic/profile.json | 4 +--- examples/date-equal-to/profile.json | 4 +--- examples/demo-trades-smaller/profile.json | 4 ++-- examples/demo-trades/profile.json | 6 +++--- examples/formatting/profile.json | 8 ++----- examples/user-account/profile.json | 8 ++----- .../atomic/AtomicConstraintValueReader.java | 21 ++++++++----------- 10 files changed, 26 insertions(+), 53 deletions(-) diff --git a/examples/date-after-dynamic/profile.json b/examples/date-after-dynamic/profile.json index 857126d24..598c560d1 100644 --- a/examples/date-after-dynamic/profile.json +++ b/examples/date-after-dynamic/profile.json @@ -25,9 +25,7 @@ { "field": "field1", "is": "after", - "value": { - "date": "8001-02-03T04:05:06.007" - } + "value": "8001-02-03T04:05:06.007" }, { "field": "field2", diff --git a/examples/date-after/profile.json b/examples/date-after/profile.json index 42e52fe4d..59de9db4b 100644 --- a/examples/date-after/profile.json +++ b/examples/date-after/profile.json @@ -13,9 +13,7 @@ { "field": "date", "is": "after", - "value": { - "date": "8001-02-03T04:05:06.007" - } + "value": "8001-02-03T04:05:06.007" } ] } diff --git a/examples/date-equal-to-dynamic-offset/profile.json b/examples/date-equal-to-dynamic-offset/profile.json index 538c0da73..bc93407ce 100644 --- a/examples/date-equal-to-dynamic-offset/profile.json +++ b/examples/date-equal-to-dynamic-offset/profile.json @@ -43,9 +43,7 @@ { "field": "first", "is": "after", - "value": { - "date": "8001-02-03T04:05:06.007" - } + "value": "8001-02-03T04:05:06.007" }, { "field": "second", @@ -64,9 +62,7 @@ { "field": "firstWorking", "is": "equalTo", - "value": { - "date": "2019-08-12T12:00:00.000" - } + "value": "2019-08-12T12:00:00.000" }, { "field": "secondWorking", @@ -78,16 +74,12 @@ { "field": "current", "is": "before", - "value": { - "date": "now" - } + "value": "now" }, { "field": "current", "is": "after", - "value": { - "date": "2019-06-01T12:00:00.000" - } + "value": "2019-06-01T12:00:00.000" } ] } diff --git a/examples/date-equal-to-dynamic/profile.json b/examples/date-equal-to-dynamic/profile.json index e96158935..7c3c59862 100644 --- a/examples/date-equal-to-dynamic/profile.json +++ b/examples/date-equal-to-dynamic/profile.json @@ -17,9 +17,7 @@ { "field": "first", "is": "after", - "value": { - "date": "8001-02-03T04:05:06.007" - } + "value": "8001-02-03T04:05:06.007" }, { "field": "second", diff --git a/examples/date-equal-to/profile.json b/examples/date-equal-to/profile.json index a101c950c..5c97536fb 100644 --- a/examples/date-equal-to/profile.json +++ b/examples/date-equal-to/profile.json @@ -13,9 +13,7 @@ { "field": "date", "is": "equalTo", - "value": { - "date": "2001-02-03T04:05:06.007" - } + "value": "2001-02-03T04:05:06.007" } ] } diff --git a/examples/demo-trades-smaller/profile.json b/examples/demo-trades-smaller/profile.json index 926c600b6..71a85d423 100644 --- a/examples/demo-trades-smaller/profile.json +++ b/examples/demo-trades-smaller/profile.json @@ -71,8 +71,8 @@ { "rule": "tradeDatetime", "constraints": [ - { "field": "tradeDatetime", "is": "after", "value": { "date": "2019-09-02T09:30:00.000" } }, - { "field": "tradeDatetime", "is": "before", "value": { "date": "2019-09-02T16:30:00.000" } } + { "field": "tradeDatetime", "is": "after", "value": "2019-09-02T09:30:00.000" }, + { "field": "tradeDatetime", "is": "before", "value": "2019-09-02T16:30:00.000" } ] } ] diff --git a/examples/demo-trades/profile.json b/examples/demo-trades/profile.json index d2f55a1e3..ee4da060d 100644 --- a/examples/demo-trades/profile.json +++ b/examples/demo-trades/profile.json @@ -101,15 +101,15 @@ "rule": "tradeDatetime", "constraints": [ { "field": "tradeDatetime", "is": "granularTo", "value": "millis" }, - { "field": "tradeDatetime", "is": "after", "value": { "date": "2019-09-02T09:30:00.000" } }, - { "field": "tradeDatetime", "is": "before", "value": { "date": "2019-09-02T16:30:00.000" } } + { "field": "tradeDatetime", "is": "after", "value":"2019-09-02T09:30:00.000" }, + { "field": "tradeDatetime", "is": "before", "value": "2019-09-02T16:30:00.000" } ] }, { "rule": "tradeDate", "constraints": [ { "field": "tradeDate", "is": "granularTo", "value": "days" }, - { "field": "tradeDate", "is": "equalTo", "value": { "date": "2019-09-02T00:00:00.000" } } + { "field": "tradeDate", "is": "equalTo", "value": "2019-09-02T00:00:00.000" } ] }, { diff --git a/examples/formatting/profile.json b/examples/formatting/profile.json index 8f289596b..a1221c654 100644 --- a/examples/formatting/profile.json +++ b/examples/formatting/profile.json @@ -40,16 +40,12 @@ { "field": "date1", "is": "equalTo", - "value": { - "date": "2001-02-03T04:05:06.007" - } + "value": "2001-02-03T04:05:06.007" }, { "field": "date2", "is": "equalTo", - "value": { - "date": "2001-02-03T04:05:06.007" - } + "value": "2001-02-03T04:05:06.007" }, { "field": "an_integer", diff --git a/examples/user-account/profile.json b/examples/user-account/profile.json index e84660c24..cc7d9e889 100644 --- a/examples/user-account/profile.json +++ b/examples/user-account/profile.json @@ -74,16 +74,12 @@ { "field": "creation_date", "is": "afterOrAt", - "value": { - "date": "2003-01-01T00:00:00.000" - } + "value": "2003-01-01T00:00:00.000" }, { "field": "creation_date", "is": "beforeOrAt", - "value": { - "date": "2020-01-01T00:00:00.000" - } + "value": "2020-01-01T00:00:00.000" } ] } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java index ea88cf2ec..27e1649e4 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java @@ -58,14 +58,16 @@ private DistributedSet getSet(Collection values, Types type) { } private Object getValue(Object value, Types type) { - if (value instanceof Map){ - return getDate((Map) value); + switch (type) { + case NUMERIC: + return getBigDecimal(value); + case STRING: + return value; + case DATETIME: + return ConstraintReaderHelpers.parseDate((String) value); + default: + throw new IllegalStateException("Unexpected value: " + type); } - if (type == Types.NUMERIC){ - return getBigDecimal(value); - } - - return value; } private Object getBigDecimal(Object value) { @@ -77,9 +79,4 @@ private Object getBigDecimal(Object value) { return bigDecimal; } - - - private OffsetDateTime getDate(Map value) { - return ConstraintReaderHelpers.parseDate((String) (value).get("date")); - } } From 646b8cf55134f437c901dcdc03fd284d963ab4d1 Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Wed, 2 Oct 2019 10:32:05 +0100 Subject: [PATCH 2/6] fix(#1382): Test profile jsons updated --- .../operators/grammatical/AnyOf.feature | 12 +- .../features/operators/grammatical/If.feature | 144 +++++++++--------- .../invalid/containingRegex-value-object.json | 2 +- ...after-dynamic-with-incorrect-relation.json | 4 +- .../invalid/datetime-after-misspelled.json | 2 +- .../invalid/datetime-after-value-invalid.json | 10 +- .../datetime-afterorat-misspelled.json | 2 +- .../invalid/datetime-before-misspelled.json | 2 +- .../datetime-beforeorat-misspelled.json | 2 +- .../datetime-equalto-datetime-misspelled.json | 2 +- .../invalid/matchingRegex-value-object.json | 2 +- .../v0-2-features-in-v0-1-profile.json | 4 +- .../profile-test-simple-datetimes-errors.json | 10 +- 13 files changed, 97 insertions(+), 101 deletions(-) diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/grammatical/AnyOf.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/grammatical/AnyOf.feature index 9cb3d5111..b3dfd4315 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/grammatical/AnyOf.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/grammatical/AnyOf.feature @@ -123,8 +123,8 @@ Feature: Values can be specified by using any of to set multiple constraints Given there is a constraint: """ { "anyOf": [ - { "field": "foo", "is": "after", "value": { "date": "2018-10-01T00:00:00.000" } }, - { "field": "foo", "is": "afterOrAt", "value": { "date": "2018-10-02T00:00:00.000" } } + { "field": "foo", "is": "after", "value": "2018-10-01T00:00:00.000" }, + { "field": "foo", "is": "afterOrAt", "value": "2018-10-02T00:00:00.000" } ]} """ And foo has type "datetime" @@ -147,15 +147,15 @@ Feature: Values can be specified by using any of to set multiple constraints Given there is a constraint: """ { "anyOf": [ - { "field": "foo", "is": "after", "value": { "date": "2018-10-01T00:00:00.000" } }, - { "field": "foo", "is": "afterOrAt", "value": { "date": "2018-10-02T00:00:00.000" } } + { "field": "foo", "is": "after", "value": "2018-10-01T00:00:00.000" }, + { "field": "foo", "is": "afterOrAt", "value": "2018-10-02T00:00:00.000" } ]} """ And there is a constraint: """ { "anyOf": [ - { "field": "foo", "is": "after", "value": { "date": "2018-10-03T00:00:00.000" } }, - { "field": "foo", "is": "afterOrAt", "value": { "date": "2018-10-04T00:00:00.000" } } + { "field": "foo", "is": "after", "value": "2018-10-03T00:00:00.000" }, + { "field": "foo", "is": "afterOrAt", "value": "2018-10-04T00:00:00.000" } ]} """ And foo has type "datetime" diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/grammatical/If.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/grammatical/If.feature index 9d40a6350..7189cd068 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/grammatical/If.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/grammatical/If.feature @@ -2524,9 +2524,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "after", "value": { "date": "2018-01-02T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } } + "if": { "field": "foo", "is": "after", "value": "2018-01-02T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2559,9 +2559,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-02-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "after", "value": { "date": "2010-01-04T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-02-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "after", "value": "2010-01-04T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2594,9 +2594,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "after", "value": { "date": "2010-01-04T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "after", "value": "2010-01-04T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2629,9 +2629,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "after", "value": { "date": "2020-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-04T00:00:00.000Z" } } + "if": { "field": "foo", "is": "after", "value": "2020-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-04T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2664,9 +2664,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "after", "value": { "date": "2020-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-04T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "after", "value": "2020-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-04T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2698,9 +2698,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "after", "value": { "date": "2020-01-01T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "after", "value": "2020-01-01T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2728,9 +2728,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "afterOrAt", "value": { "date": "2018-05-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } } + "if": { "field": "foo", "is": "afterOrAt", "value": "2018-05-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2763,9 +2763,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-05-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "afterOrAt", "value": { "date": "2010-01-04T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-05-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "afterOrAt", "value": "2010-01-04T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2799,9 +2799,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-06-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "afterOrAt", "value": { "date": "2010-01-04T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-06-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "afterOrAt", "value": "2010-01-04T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2839,9 +2839,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "afterOrAt", "value": { "date": "2020-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } } + "if": { "field": "foo", "is": "afterOrAt", "value": "2020-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2874,9 +2874,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "afterOrAt", "value": { "date": "2020-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "afterOrAt", "value": "2020-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2908,9 +2908,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "afterOrAt", "value": { "date": "2020-01-05T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "afterOrAt", "value": "2020-01-05T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2938,9 +2938,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "before", "value": { "date": "2018-02-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } } + "if": { "field": "foo", "is": "before", "value": "2018-02-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" } } """ Then the following data should be generated: @@ -2973,9 +2973,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "before", "value": { "date": "2010-01-03T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "before", "value": "2010-01-03T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" } } """ Then the following data should be generated: @@ -3009,9 +3009,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "before", "value": { "date": "2010-01-03T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" }, + "else": { "field": "bar", "is": "before", "value": "2010-01-03T00:00:00.000Z" } } """ Then the following data should be generated: @@ -3049,9 +3049,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "before", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-03T00:00:00.000Z" } } + "if": { "field": "foo", "is": "before", "value": "2010-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-03T00:00:00.000Z" } } """ Then the following data should be generated: @@ -3084,9 +3084,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "before", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-03T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "before", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-03T00:00:00.000Z" } } """ Then the following data should be generated: @@ -3118,9 +3118,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "before", "value": { "date": "2010-01-01T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "before", "value": "2010-01-01T00:00:00.000Z" } } """ Then the following data should be generated: @@ -3148,9 +3148,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "beforeOrAt", "value": { "date": "2018-02-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } } + "if": { "field": "foo", "is": "beforeOrAt", "value": "2018-02-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" } } """ Then the following data should be generated: @@ -3183,9 +3183,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "beforeOrAt", "value": { "date": "2010-01-03T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "beforeOrAt", "value": "2010-01-03T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" } } """ Then the following data should be generated: @@ -3220,9 +3220,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "beforeOrAt", "value": { "date": "2010-01-03T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" }, + "else": { "field": "bar", "is": "beforeOrAt", "value": "2010-01-03T00:00:00.000Z" } } """ Then the following data should be generated: @@ -3265,9 +3265,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "beforeOrAt", "value": { "date": "2009-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-05T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-03T00:00:00.000Z" } } + "if": { "field": "foo", "is": "beforeOrAt", "value": "2009-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-05T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-03T00:00:00.000Z" } } """ Then the following data should be generated: @@ -3300,9 +3300,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "beforeOrAt", "value": { "date": "2009-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-03T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "beforeOrAt", "value": "2009-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "equalTo", "value": "2010-01-03T00:00:00.000Z" } } """ Then the following data should be generated: @@ -3334,9 +3334,9 @@ Feature: Values can be specified by using if, then and else constraints And there is a constraint: """ { - "if": { "field": "foo", "is": "equalTo", "value": { "date": "2018-01-01T00:00:00.000Z" } }, - "then": { "field": "bar", "is": "equalTo", "value": { "date": "2010-01-01T00:00:00.000Z" } }, - "else": { "field": "bar", "is": "beforeOrAt", "value": { "date": "2009-01-01T00:00:00.000Z" } } + "if": { "field": "foo", "is": "equalTo", "value": "2018-01-01T00:00:00.000Z" }, + "then": { "field": "bar", "is": "equalTo", "value": "2010-01-01T00:00:00.000Z" }, + "else": { "field": "bar", "is": "beforeOrAt", "value": "2009-01-01T00:00:00.000Z" } } """ Then the following data should be generated: 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 f73b09c45..be188d172 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 @@ -12,7 +12,7 @@ "not": { "field": "field1", "is": "containingRegex", - "value": {"date": "0001-01-01T09:00:00.000"} + "value": "0001-01-01T09:00:00.000" } } ] 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 aff5dab58..dcbaf7e67 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 @@ -61,9 +61,7 @@ { "field": "field1", "is": "after", - "value": { - "date": "8001-02-03T04:05:06.007" - } + "value": "8001-02-03T04:05:06.007" }, { "field": "field2", 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 0145671a8..442caacd7 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 @@ -7,7 +7,7 @@ { "field": "field1", "is": "notafter", - "value": {"date": "2000-01-01T09:00:00.000"} + "value": "2000-01-01T09:00:00.000" } ] } diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-after-value-invalid.json b/profile/src/test/resources/test-profiles/invalid/datetime-after-value-invalid.json index 04c624d05..5bcdce1d6 100644 --- a/profile/src/test/resources/test-profiles/invalid/datetime-after-value-invalid.json +++ b/profile/src/test/resources/test-profiles/invalid/datetime-after-value-invalid.json @@ -47,27 +47,27 @@ { "field": "field1", "is": "notafter", - "value": {"date": "2000-01-01T09:00:00.000"} + "value": "2000-01-01T09:00:00.000" }, { "field": "field1", "is": "notafterOrAt", - "value": {"date": "2000-01-01T09:00:00.000"} + "value": "2000-01-01T09:00:00.000" }, { "field": "field1", "is": "notbefore", - "value": {"date": "2000-01-01T09:00:00.000"} + "value": "2000-01-01T09:00:00.000" }, { "field": "field1", "is": "notbeforeOrAt", - "value": {"date": "0001-01-01T09:00:00.000"} + "value": "0001-01-01T09:00:00.000" }, { "field": "field1", "is": "notequalTo", - "value": {"date": "0001-01-01T09:00:00.000"} + "value": "0001-01-01T09:00:00.000" } ] } 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 5e09909f0..37dfc375d 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 @@ -7,7 +7,7 @@ { "field": "field1", "is": "notafterOrAt", - "value": {"date": "2000-01-01T09:00:00.000"} + "value": "2000-01-01T09:00:00.000" } ] } 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 caffad4f9..1f70cf512 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 @@ -7,7 +7,7 @@ { "field": "field1", "is": "notbefore", - "value": {"date": "2000-01-01T09:00:00.000"} + "value": "2000-01-01T09:00:00.000" } ] } 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 8d490a1ae..cb7ce9262 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 @@ -7,7 +7,7 @@ { "field": "field1", "is": "notbeforeOrAt", - "value": {"date": "0001-01-01T09:00:00.000"} + "value": "0001-01-01T09:00:00.000" } ] } 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 f235b725d..a3ecd6651 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 @@ -7,7 +7,7 @@ { "field": "field1", "is": "notequalTo", - "value": {"date": "2000-01-01T09:00:00.000"} + "value": "2000-01-01T09:00:00.000" } ] } 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 c473e1246..9027cc1f9 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 @@ -12,7 +12,7 @@ "not": { "field": "field1", "is": "matchingRegex", - "value": {"date": "0001-01-01T09:00:00.000"} + "value": "0001-01-01T09:00:00.000" } } ] 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 acb55dac4..f6fc5bab0 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 @@ -35,9 +35,7 @@ { "field": "first", "is": "after", - "value": { - "date": "8001-02-03T04:05:06.007" - } + "value": "8001-02-03T04:05:06.007" }, { "field": "second", diff --git a/profile/src/test/resources/test-profiles/profile-test-simple-datetimes-errors.json b/profile/src/test/resources/test-profiles/profile-test-simple-datetimes-errors.json index 04c624d05..5bcdce1d6 100644 --- a/profile/src/test/resources/test-profiles/profile-test-simple-datetimes-errors.json +++ b/profile/src/test/resources/test-profiles/profile-test-simple-datetimes-errors.json @@ -47,27 +47,27 @@ { "field": "field1", "is": "notafter", - "value": {"date": "2000-01-01T09:00:00.000"} + "value": "2000-01-01T09:00:00.000" }, { "field": "field1", "is": "notafterOrAt", - "value": {"date": "2000-01-01T09:00:00.000"} + "value": "2000-01-01T09:00:00.000" }, { "field": "field1", "is": "notbefore", - "value": {"date": "2000-01-01T09:00:00.000"} + "value": "2000-01-01T09:00:00.000" }, { "field": "field1", "is": "notbeforeOrAt", - "value": {"date": "0001-01-01T09:00:00.000"} + "value": "0001-01-01T09:00:00.000" }, { "field": "field1", "is": "notequalTo", - "value": {"date": "0001-01-01T09:00:00.000"} + "value": "0001-01-01T09:00:00.000" } ] } From 582ff10f57b4261d1d3a96a2881aa8246142aafd Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Wed, 2 Oct 2019 12:54:07 +0100 Subject: [PATCH 3/6] fix(#1382): Updated documentation and fixed more tests --- docs/UserGuide.md | 20 ++++++------- docs/user/Schema.md | 2 +- .../testframework/steps/DateObject.java | 25 ---------------- .../testframework/steps/DateValueStep.java | 30 +++++++++---------- .../steps/TypeRegistryConfiguration.java | 4 +-- .../utils/GeneratorTestUtilities.java | 3 +- .../atomic/AtomicConstraintValueReader.java | 2 ++ .../profileschema/datahelix.schema.json | 29 ++++-------------- .../ConstraintValidationAndReadingTests.java | 13 ++------ 9 files changed, 38 insertions(+), 90 deletions(-) delete mode 100644 orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateObject.java diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 7c91fa633..20d11709e 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -252,10 +252,10 @@ Strings are sequences of unicode characters with a maximum length of 1000 charac ## DateTime -DateTimes represent specific moments in time, and are specified in profiles through specialised objects: +DateTimes represent specific moments in time, and are specified in profiles through specialised strings: ```javascript -{ "date": "2000-01-01T09:00:00.000" } +"2000-01-01T09:00:00.000" ``` The format is a subset of [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601); the date and time must be fully specified as above, @@ -317,7 +317,7 @@ The [grammatical `not` constraint](#Grammatical-Constraints) inverts a constrain OR { "field": "type", "is": "equalTo", "value": 23 } OR -{ "field": "type", "is": "equalTo", "value": { "date": "2001-02-03T04:05:06.007" } } +{ "field": "type", "is": "equalTo", "value": "2001-02-03T04:05:06.007" } ``` Is satisfied if `field`'s value is equal to `value` @@ -327,7 +327,7 @@ Is satisfied if `field`'s value is equal to `value` ### `inSet` _(field, values)_ ```javascript -{ "field": "type", "is": "inSet", "values": [ "X_092", 123, null, { "date": "2001-02-03T04:05:06.007" } ] } +{ "field": "type", "is": "inSet", "values": [ "X_092", 123, null, "2001-02-03T04:05:06.007" ] } ``` Is satisfied if `field`'s value is in the set `values` @@ -487,16 +487,16 @@ Is satisfied if `field` is a number less than or equal to `value`. Is satisfied if `field` has at least the [granularity](#Numeric-granularity) specified in `value`. ## DateTime constraints -All dates must be in format `yyyy-MM-ddTHH:mm:ss.SSS` and embedded in a _date-object_. The Z suffix can be included, but is not required. All datetimes are treated as UTC whether the Z suffix is included or not. +All dates must be in format `yyyy-MM-ddTHH:mm:ss.SSS` and the Z suffix can be included, but is not required. All datetimes are treated as UTC whether the Z suffix is included or not. -Example: `{ "date": "2001-02-03T04:05:06.007" }` +Example: `2001-02-03T04:05:06.007`
### `after` _(field, value)_ ```javascript -{ "field": "date", "is": "after", "value": { "date": "2018-09-01T00:00:00.000" } } +{ "field": "date", "is": "after", "value": "2018-09-01T00:00:00.000" } ``` Is satisfied if `field` is a datetime occurring after `value`. @@ -506,7 +506,7 @@ Is satisfied if `field` is a datetime occurring after `value`. ### `afterOrAt` _(field, value)_ ```javascript -{ "field": "date", "is": "afterOrAt", "value": { "date": "2018-09-01T00:00:00.000" } } +{ "field": "date", "is": "afterOrAt", "value": "2018-09-01T00:00:00.000" } ``` Is satisfied if `field` is a datetime occurring after or simultaneously with `value`. @@ -516,7 +516,7 @@ Is satisfied if `field` is a datetime occurring after or simultaneously with `va ### `before` _(field, value)_ ```javascript -{ "field": "date", "is": "before", "value": { "date": "2018-09-01T00:00:00.000" } } +{ "field": "date", "is": "before", "value": "2018-09-01T00:00:00.000" } ``` Is satisfied if `field` is a datetime occurring before `value`. @@ -526,7 +526,7 @@ Is satisfied if `field` is a datetime occurring before `value`. ### `beforeOrAt` _(field, value)_ ```javascript -{ "field": "date", "is": "beforeOrAt", "value": { "date": "2018-09-01T00:00:00.000" } } +{ "field": "date", "is": "beforeOrAt", "value": "2018-09-01T00:00:00.000" } ``` Is satisfied if `field` is a datetime occurring before or simultaneously with `value`. diff --git a/docs/user/Schema.md b/docs/user/Schema.md index ea4310d8c..2e08d221a 100644 --- a/docs/user/Schema.md +++ b/docs/user/Schema.md @@ -62,7 +62,7 @@ "then": { "allOf": [ { "field": "tariff", "is": "null" }, - { "field": "time", "is": "after", "value": { "date": "2014-01-01" } } + { "field": "time", "is": "after", "value": "2014-01-01" } ] }, "else": { "not": { "field": "tariff", "is": "null" } } diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateObject.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateObject.java deleted file mode 100644 index 557d15e77..000000000 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateObject.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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.orchestrator.cucumber.testframework.steps; - -import java.util.HashMap; - -public class DateObject extends HashMap { - public DateObject(String date){ - this.put("date", date); - } -} diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateValueStep.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateValueStep.java index 85fb061dd..3da1d4be4 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateValueStep.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/DateValueStep.java @@ -37,12 +37,12 @@ public DateValueStep(CucumberTestState state, CucumberTestHelper helper){ } @When("{fieldVar} is {operator} {date}") - public void whenFieldIsConstrainedByDateValue(String fieldName, String constraintName, DateObject value) { + public void whenFieldIsConstrainedByDateValue(String fieldName, String constraintName, String value) { state.addConstraint(fieldName, constraintName, value); } @When("{fieldVar} is anything but {operator} {date}") - public void whenFieldIsNotConstrainedByDateValue(String fieldName, String constraintName, DateObject value) { + public void whenFieldIsNotConstrainedByDateValue(String fieldName, String constraintName, String value) { state.addNotConstraint(fieldName, constraintName, value); } @@ -62,7 +62,7 @@ public void producedDataShouldContainAnythingButStringValuesForField(String fiel } @Then("{fieldVar} contains datetimes between {date} and {date} inclusively") - public void producedDataShouldContainDateTimeValuesInRangeForField(String fieldName, DateObject minInclusive, DateObject maxInclusive){ + public void producedDataShouldContainDateTimeValuesInRangeForField(String fieldName, String minInclusive, String maxInclusive){ helper.assertFieldContainsNullOrMatching( fieldName, OffsetDateTime.class, @@ -70,7 +70,7 @@ public void producedDataShouldContainDateTimeValuesInRangeForField(String fieldN } @Then("{fieldVar} contains datetimes outside {date} and {date}") - public void producedDataShouldContainDateTimeValuesOutOfRangeForField(String fieldName, DateObject min, DateObject max){ + public void producedDataShouldContainDateTimeValuesOutOfRangeForField(String fieldName, String min, String max){ helper.assertFieldContainsNullOrMatching( fieldName, OffsetDateTime.class, @@ -78,7 +78,7 @@ public void producedDataShouldContainDateTimeValuesOutOfRangeForField(String fie } @Then("{fieldVar} contains datetimes before or at {date}") - public void producedDataShouldContainDateTimeValuesBeforeForField(String fieldName, DateObject beforeInclusive){ + public void producedDataShouldContainDateTimeValuesBeforeForField(String fieldName, String beforeInclusive){ helper.assertFieldContainsNullOrMatching( fieldName, OffsetDateTime.class, @@ -86,30 +86,28 @@ public void producedDataShouldContainDateTimeValuesBeforeForField(String fieldNa } @Then("{fieldVar} contains datetimes after or at {date}") - public void producedDataShouldContainDateTimeValuesAfterForField(String fieldName, DateObject afterInclusive){ + public void producedDataShouldContainDateTimeValuesAfterForField(String fieldName, String afterInclusive){ helper.assertFieldContainsNullOrMatching( fieldName, OffsetDateTime.class, value -> isAfterOrAt(value, afterInclusive)); } - private Function isBetweenInclusively(DateObject minInclusive, DateObject maxInclusive){ + private Function isBetweenInclusively(String minInclusive, String maxInclusive){ return value -> isAfterOrAt(value, minInclusive) && isBeforeOrAt(value, maxInclusive); } - private OffsetDateTime getDateTime(DateObject dateObject){ - String dateString = (String)dateObject.get("date"); - return GeneratorTestUtilities.getOffsetDateTime(dateString); - } - - private boolean isAfterOrAt(OffsetDateTime date, DateObject minInclusiveObject){ - OffsetDateTime minInclusive = getDateTime(minInclusiveObject); + private boolean isAfterOrAt(OffsetDateTime date, String minInclusiveString){ + OffsetDateTime minInclusive = getDateTime(minInclusiveString); return date.equals(minInclusive) || date.isAfter(minInclusive); } - private boolean isBeforeOrAt(OffsetDateTime date, DateObject maxInclusiveObject){ - OffsetDateTime maxInclusive = getDateTime(maxInclusiveObject); + private boolean isBeforeOrAt(OffsetDateTime date, String maxInclusiveString){ + OffsetDateTime maxInclusive = getDateTime(maxInclusiveString); return date.equals(maxInclusive) || date.isBefore(maxInclusive); } + private OffsetDateTime getDateTime(String date){ + return GeneratorTestUtilities.getOffsetDateTime(date); + } } diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/TypeRegistryConfiguration.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/TypeRegistryConfiguration.java index 20c24cca0..bf0d75da3 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/TypeRegistryConfiguration.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/steps/TypeRegistryConfiguration.java @@ -66,8 +66,8 @@ public void configureTypeRegistry(TypeRegistry tr) { tr.defineParameterType(new ParameterType<>( "date", DateValueStep.DATE_REGEX, - DateObject.class, - DateObject::new)); + String.class, + this::extractConstraint)); } private void defineOperationParameterType(TypeRegistry tr){ diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/GeneratorTestUtilities.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/GeneratorTestUtilities.java index cb086b44b..e9b23b934 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/GeneratorTestUtilities.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/GeneratorTestUtilities.java @@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.scottlogic.deg.profile.reader.InvalidProfileException; -import com.scottlogic.deg.orchestrator.cucumber.testframework.steps.DateObject; import com.scottlogic.deg.orchestrator.cucumber.testframework.steps.DateValueStep; import org.junit.Assert; @@ -41,7 +40,7 @@ public static Object parseInput(String input) throws JsonParseException { if (input.startsWith("\"") && input.endsWith("\"")) { return input.substring(1, input.length() - 1); } else if (input.matches(DateValueStep.DATE_REGEX)) { - return new DateObject(input); + return input; } else if (input.equals("null")) { return null; } else if (input.matches("[+-]?(\\d+(\\.\\d+)?)")) { diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java index 27e1649e4..8c8823464 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java @@ -58,12 +58,14 @@ private DistributedSet getSet(Collection values, Types type) { } private Object getValue(Object value, Types type) { + if(value == null) return null; switch (type) { case NUMERIC: return getBigDecimal(value); case STRING: return value; case DATETIME: + if(value.equals("datetime")) return value; return ConstraintReaderHelpers.parseDate((String) value); default: throw new IllegalStateException("Unexpected value: " + type); diff --git a/profile/src/main/resources/profileschema/datahelix.schema.json b/profile/src/main/resources/profileschema/datahelix.schema.json index 02a6cc99f..12bbe9b80 100644 --- a/profile/src/main/resources/profileschema/datahelix.schema.json +++ b/profile/src/main/resources/profileschema/datahelix.schema.json @@ -55,9 +55,6 @@ }, "dataType": { "oneOf": [ - { - "$ref": "#/definitions/datetime" - }, { "$ref": "#/definitions/string" }, @@ -67,27 +64,17 @@ ] }, "datetime": { - "type": "object", - "additionalProperties": false, - "required": ["date"], - "default": { - "date": "2000-01-01T09:00:00.000" - }, - "properties": { - "additionalProperties": false, - "date": { - "title": "an ISO 8610 compatible string denoting a date and time", - "type": "string", - "default": "2000-01-01T09:00:00.000", - "oneOf": [ + "title": "an ISO 8610 compatible string denoting a date and time", + "$ref": "#/definitions/string", + "default": "2000-01-01T09:00:00.000", + "oneOf": [ { "pattern": "^(?!0000)[0-9]{4}-([0][0-9]|[1][0-2])-([0-2][0-9]|3[01])T([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9][.][0-9]{3}Z?$" }, { "enum": ["now"] }] - } - } + }, "numeric": { "type": "number", @@ -214,9 +201,6 @@ }, "value": { "oneOf": [ - { - "$ref": "#/definitions/datetime" - }, { "$ref": "#/definitions/numeric" }, @@ -553,9 +537,6 @@ "type": "array", "items": { "oneOf": [ - { - "$ref": "#/definitions/datetime" - }, { "$ref": "#/definitions/numeric" }, diff --git a/profile/src/test/java/com/scottlogic/deg/profile/reader/ConstraintValidationAndReadingTests.java b/profile/src/test/java/com/scottlogic/deg/profile/reader/ConstraintValidationAndReadingTests.java index f97d019d5..bd804848e 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/reader/ConstraintValidationAndReadingTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/reader/ConstraintValidationAndReadingTests.java @@ -59,13 +59,6 @@ public void before() { profileFields = new ProfileFields(fields); } - private static Object createDateObject(String dateStr) { - Map date = new HashMap<>(); - date.put("date", dateStr); - - return date; - } - private static Stream testProvider() { ConstraintDTO stringValueDto = new ConstraintDTO(); stringValueDto.field = "test"; @@ -79,7 +72,7 @@ private static Stream testProvider() { ConstraintDTO dateValueDto = new ConstraintDTO(); dateValueDto.field = "test"; - dateValueDto.value = createDateObject("2020-01-01T01:02:03.456"); + dateValueDto.value = "2020-01-01T01:02:03.456"; ConstraintDTO multipleValuesDto = new ConstraintDTO(); multipleValuesDto.field = "test"; @@ -325,7 +318,7 @@ public void shouldHandleExplicitHourOffsets() { } private void assertSuccessfulDateParse(String dateString, OffsetDateTime expectedDateTime) { - OffsetDateTime actualDateTime = tryParseConstraintDateTimeValue(createDateObject(dateString)); + OffsetDateTime actualDateTime = tryParseConstraintDateTimeValue(dateString); Assert.assertThat(actualDateTime, equalTo(expectedDateTime)); } @@ -333,7 +326,7 @@ private void assertSuccessfulDateParse(String dateString, OffsetDateTime expecte private void assertRejectedDateTimeParse(String dateString) { Assertions.assertThrows( InvalidProfileException.class, - () -> tryParseConstraintDateTimeValue(createDateObject(dateString))); + () -> tryParseConstraintDateTimeValue(dateString)); } private OffsetDateTime tryParseConstraintDateTimeValue(Object value) { From 41458efd516cab8c3b31012c9990c77e86e2e971 Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Wed, 2 Oct 2019 13:20:20 +0100 Subject: [PATCH 4/6] fix(#1382): Fixed more tests --- .../operators/temporal/AfterOrAt.feature | 5 -- .../operators/temporal/BeforeOrAt.feature | 6 -- .../atomic/AtomicConstraintValueReader.java | 6 +- .../datetime-after-value-date-misspelled.json | 20 ----- .../invalid/datetime-after-value-invalid.json | 83 ------------------- ...etime-afterorat-value-date-misspelled.json | 20 ----- ...datetime-before-value-date-misspelled.json | 20 ----- ...time-beforeorat-value-date-misspelled.json | 20 ----- .../profile-test-simple-datetimes-errors.json | 83 ------------------- 9 files changed, 4 insertions(+), 259 deletions(-) delete mode 100644 profile/src/test/resources/test-profiles/invalid/datetime-after-value-date-misspelled.json delete mode 100644 profile/src/test/resources/test-profiles/invalid/datetime-after-value-invalid.json delete mode 100644 profile/src/test/resources/test-profiles/invalid/datetime-afterorat-value-date-misspelled.json delete mode 100644 profile/src/test/resources/test-profiles/invalid/datetime-before-value-date-misspelled.json delete mode 100644 profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-value-date-misspelled.json delete mode 100644 profile/src/test/resources/test-profiles/profile-test-simple-datetimes-errors.json diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/AfterOrAt.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/AfterOrAt.feature index 93369565d..a9267d45c 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/AfterOrAt.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/AfterOrAt.feature @@ -49,11 +49,6 @@ Feature: User can specify that a datetime date is more than, or the same as, a s Then the profile is invalid because "Field \[foo\]: Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z" And no data is created - Scenario: Running beforeOrAt request that includes datetime field with date and time (YYYY-MM-DDTHH:MM:SS) values that has invalid format should fail - Given foo is after or at "2018-Jan-31stT00:00:00.000" - Then the profile is invalid because "Field \[foo\]: Dates should be expressed in object format e.g. \{ \"date\": \"yyyy-MM-ddTHH:mm:ss.SSS\[Z\]\" \}" - And no data is created - Scenario: Running afterOrAt request that includes datetime field with date and time (YYYY-MM-DDTHH:MM:SS) values that has leap year Given foo is after or at 2019-01-01T00:00:00.000Z And foo is in set: diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/BeforeOrAt.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/BeforeOrAt.feature index 0cdbceea0..eb989cc30 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/BeforeOrAt.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/BeforeOrAt.feature @@ -52,12 +52,6 @@ Feature: User can specify that a datetime date is lower than, or the same as, a Then the profile is invalid because "Field \[foo\]: Dates must be between 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z" And no data is created - Scenario: Running beforeOrAt request that includes datetime field with date and time (YYYY-MM-DDTHH:MM:SS) values that has invalid format should fail - Given foo is before or at "2018-Feb-01T00:00:00.000" - And the generator can generate at most 5 rows - Then the profile is invalid because "Field \[foo\]: Dates should be expressed in object format e.g. \{ \"date\": \"yyyy-MM-ddTHH:mm:ss.SSS\[Z\]\" \}" - And no data is created - @ignore #594 As a user I expect values to be emitted in descending order Scenario: Running beforeOrAt request that includes datetime field with date and time (YYYY-MM-DDTHH:MM:SS) values that has leap year Given foo is before or at 2024-01-01T00:00:00.000Z diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java index 8c8823464..e41d66995 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java @@ -58,14 +58,16 @@ private DistributedSet getSet(Collection values, Types type) { } private Object getValue(Object value, Types type) { - if(value == null) return null; + if(value == null || type == null) return value; switch (type) { case NUMERIC: return getBigDecimal(value); case STRING: return value; case DATETIME: - if(value.equals("datetime")) return value; + if(!(value instanceof String) || value.equals("datetime") || value.equals("years") || value.equals("months") + || value.equals("days") || value.equals("hours") || value.equals("minutes") + || value.equals("seconds") || value.equals("millis")) return value; return ConstraintReaderHelpers.parseDate((String) value); default: throw new IllegalStateException("Unexpected value: " + type); diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-after-value-date-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-after-value-date-misspelled.json deleted file mode 100644 index 8442bbe9a..000000000 --- a/profile/src/test/resources/test-profiles/invalid/datetime-after-value-date-misspelled.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "schemaVersion": "0.7", - "rules": [ - { - "rule": "rule 1", - "constraints": [ - { - "field": "field1", - "is": "after", - "value": {"adate": "2000-01-01T09:00:00.000"} - } - ] - } - ], - "fields": [ - { - "name": "field1" - } - ] -} \ No newline at end of file diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-after-value-invalid.json b/profile/src/test/resources/test-profiles/invalid/datetime-after-value-invalid.json deleted file mode 100644 index 5bcdce1d6..000000000 --- a/profile/src/test/resources/test-profiles/invalid/datetime-after-value-invalid.json +++ /dev/null @@ -1,83 +0,0 @@ -{ - "schemaVersion": "0.7", - "rules": [ - { - "rule": "rule 1", - "constraints": [ - { - "field": "field1", - "is": "after", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "afterOrAt", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "before", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "beforeOrAt", - "value": "0001-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "after", - "value": {"adate": "2000-01-01T09:00:00.000"} - }, - { - "field": "field1", - "is": "afterOrAt", - "value": {"adate": "2000-01-01T09:00:00.000"} - }, - { - "field": "field1", - "is": "before", - "value": {"adate": "2000-01-01T09:00:00.000"} - }, - { - "field": "field1", - "is": "beforeOrAt", - "value": {"adate": "0001-01-01T09:00:00.000"} - }, - { - "field": "field1", - "is": "notafter", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "notafterOrAt", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "notbefore", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "notbeforeOrAt", - "value": "0001-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "notequalTo", - "value": "0001-01-01T09:00:00.000" - } - ] - } - ], - "fields": [ - { - "name": "field1" - }, - { - "name": "field2" - } - ] -} \ No newline at end of file diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-value-date-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-value-date-misspelled.json deleted file mode 100644 index 1805134a2..000000000 --- a/profile/src/test/resources/test-profiles/invalid/datetime-afterorat-value-date-misspelled.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "schemaVersion": "0.7", - "rules": [ - { - "rule": "rule 1", - "constraints": [ - { - "field": "field1", - "is": "afterOrAt", - "value": {"adate": "2000-01-01T09:00:00.000"} - } - ] - } - ], - "fields": [ - { - "name": "field1" - } - ] -} \ No newline at end of file diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-before-value-date-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-before-value-date-misspelled.json deleted file mode 100644 index 6a730a80c..000000000 --- a/profile/src/test/resources/test-profiles/invalid/datetime-before-value-date-misspelled.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "schemaVersion": "0.7", - "rules": [ - { - "rule": "rule 1", - "constraints": [ - { - "field": "field1", - "is": "before", - "value": {"adate": "2000-01-01T09:00:00.000"} - } - ] - } - ], - "fields": [ - { - "name": "field1" - } - ] -} \ No newline at end of file diff --git a/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-value-date-misspelled.json b/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-value-date-misspelled.json deleted file mode 100644 index 5b6995d74..000000000 --- a/profile/src/test/resources/test-profiles/invalid/datetime-beforeorat-value-date-misspelled.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "schemaVersion": "0.7", - "rules": [ - { - "rule": "rule 1", - "constraints": [ - { - "field": "field1", - "is": "beforeOrAt", - "value": {"adate": "2000-01-01T09:00:00.000"} - } - ] - } - ], - "fields": [ - { - "name": "field1" - } - ] -} \ No newline at end of file diff --git a/profile/src/test/resources/test-profiles/profile-test-simple-datetimes-errors.json b/profile/src/test/resources/test-profiles/profile-test-simple-datetimes-errors.json deleted file mode 100644 index 5bcdce1d6..000000000 --- a/profile/src/test/resources/test-profiles/profile-test-simple-datetimes-errors.json +++ /dev/null @@ -1,83 +0,0 @@ -{ - "schemaVersion": "0.7", - "rules": [ - { - "rule": "rule 1", - "constraints": [ - { - "field": "field1", - "is": "after", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "afterOrAt", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "before", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "beforeOrAt", - "value": "0001-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "after", - "value": {"adate": "2000-01-01T09:00:00.000"} - }, - { - "field": "field1", - "is": "afterOrAt", - "value": {"adate": "2000-01-01T09:00:00.000"} - }, - { - "field": "field1", - "is": "before", - "value": {"adate": "2000-01-01T09:00:00.000"} - }, - { - "field": "field1", - "is": "beforeOrAt", - "value": {"adate": "0001-01-01T09:00:00.000"} - }, - { - "field": "field1", - "is": "notafter", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "notafterOrAt", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "notbefore", - "value": "2000-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "notbeforeOrAt", - "value": "0001-01-01T09:00:00.000" - }, - { - "field": "field1", - "is": "notequalTo", - "value": "0001-01-01T09:00:00.000" - } - ] - } - ], - "fields": [ - { - "name": "field1" - }, - { - "name": "field2" - } - ] -} \ No newline at end of file From cf934b62a1330cd43b49e2224c536e385b87293a Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Wed, 2 Oct 2019 15:46:07 +0100 Subject: [PATCH 5/6] fix(#1382): Updated schema to version 0.9 --- examples/a-valid-isin/profile.json | 2 +- examples/actor-names/profile.json | 2 +- examples/anyOf/profile.json | 2 +- examples/date-after-dynamic/profile.json | 2 +- examples/date-after/profile.json | 2 +- .../date-equal-to-dynamic-offset/profile.json | 2 +- examples/date-equal-to-dynamic/profile.json | 2 +- examples/date-equal-to/profile.json | 2 +- .../date-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/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 +- .../operators/general/EqualTo.feature | 2 + .../temporal/GranularTo-DateTime.feature | 6 --- .../validation/CorrectConstraintTypes.feature | 31 ++++--------- .../endtoend/JarExecuteTests.java | 15 ++++--- .../endtoend/loadfiletest.profile.json | 2 +- .../endtoend/testprofile.profile.json | 2 +- .../atomic/AtomicConstraintValueReader.java | 24 +++++----- .../profileschema/datahelix.schema.json | 28 +++++++++--- .../ProfileSchemaImmutabilityTests.java | 3 ++ .../dto/ProfileSchemaValidatorTests.java | 44 ++++++++----------- .../reader/JsonProfileReaderTests.java | 6 +-- 43 files changed, 112 insertions(+), 115 deletions(-) diff --git a/examples/a-valid-isin/profile.json b/examples/a-valid-isin/profile.json index 6efc42dd4..a3aa08221 100644 --- a/examples/a-valid-isin/profile.json +++ b/examples/a-valid-isin/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "isin", diff --git a/examples/actor-names/profile.json b/examples/actor-names/profile.json index acdfec8e3..8cc1ae076 100644 --- a/examples/actor-names/profile.json +++ b/examples/actor-names/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "forename", diff --git a/examples/anyOf/profile.json b/examples/anyOf/profile.json index c3fe581f4..bde7a61b5 100644 --- a/examples/anyOf/profile.json +++ b/examples/anyOf/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "rules": [ { "rule": "rule 1", diff --git a/examples/date-after-dynamic/profile.json b/examples/date-after-dynamic/profile.json index 598c560d1..e52f7494f 100644 --- a/examples/date-after-dynamic/profile.json +++ b/examples/date-after-dynamic/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "field1", diff --git a/examples/date-after/profile.json b/examples/date-after/profile.json index 59de9db4b..d0b33e19e 100644 --- a/examples/date-after/profile.json +++ b/examples/date-after/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "date", diff --git a/examples/date-equal-to-dynamic-offset/profile.json b/examples/date-equal-to-dynamic-offset/profile.json index bc93407ce..c9d951ba4 100644 --- a/examples/date-equal-to-dynamic-offset/profile.json +++ b/examples/date-equal-to-dynamic-offset/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "first", diff --git a/examples/date-equal-to-dynamic/profile.json b/examples/date-equal-to-dynamic/profile.json index 7c3c59862..30c1b5ee1 100644 --- a/examples/date-equal-to-dynamic/profile.json +++ b/examples/date-equal-to-dynamic/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "first", diff --git a/examples/date-equal-to/profile.json b/examples/date-equal-to/profile.json index 5c97536fb..614706617 100644 --- a/examples/date-equal-to/profile.json +++ b/examples/date-equal-to/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "date", diff --git a/examples/date-offset-working-days/profile.json b/examples/date-offset-working-days/profile.json index f6f7d3179..ddc7da273 100644 --- a/examples/date-offset-working-days/profile.json +++ b/examples/date-offset-working-days/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "foo", diff --git a/examples/demo-trades-smaller/profile.json b/examples/demo-trades-smaller/profile.json index 71a85d423..142f3833f 100644 --- a/examples/demo-trades-smaller/profile.json +++ b/examples/demo-trades-smaller/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "tradeId", diff --git a/examples/demo-trades/profile.json b/examples/demo-trades/profile.json index ee4da060d..a324242e7 100644 --- a/examples/demo-trades/profile.json +++ b/examples/demo-trades/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "tradeId", diff --git a/examples/duplicates/profile.json b/examples/duplicates/profile.json index 85e0c0497..932e59590 100644 --- a/examples/duplicates/profile.json +++ b/examples/duplicates/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "a", diff --git a/examples/formatting/profile.json b/examples/formatting/profile.json index a1221c654..d20f007e3 100644 --- a/examples/formatting/profile.json +++ b/examples/formatting/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "decimal", diff --git a/examples/from-file-weighted/profile.json b/examples/from-file-weighted/profile.json index 509bc755d..c71c950da 100644 --- a/examples/from-file-weighted/profile.json +++ b/examples/from-file-weighted/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "name", diff --git a/examples/from-file/profile.json b/examples/from-file/profile.json index 509bc755d..c71c950da 100644 --- a/examples/from-file/profile.json +++ b/examples/from-file/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "name", diff --git a/examples/hard-contradiction-null-validation/profile.json b/examples/hard-contradiction-null-validation/profile.json index 3e72116cb..1cdd7f022 100644 --- a/examples/hard-contradiction-null-validation/profile.json +++ b/examples/hard-contradiction-null-validation/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "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 5f605e43d..7d8e30523 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.8", + "schemaVersion": "0.9", "fields": [ { "name": "Column 1", diff --git a/examples/integer-range-with-blacklist/profile.json b/examples/integer-range-with-blacklist/profile.json index 3a39dad83..7c5a6be56 100644 --- a/examples/integer-range-with-blacklist/profile.json +++ b/examples/integer-range-with-blacklist/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "an_integer", diff --git a/examples/integer-range/profile.json b/examples/integer-range/profile.json index 6bb84a352..0f1a3acca 100644 --- a/examples/integer-range/profile.json +++ b/examples/integer-range/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "an_integer", diff --git a/examples/names/profile.json b/examples/names/profile.json index d4d3faf91..05bb28eb2 100644 --- a/examples/names/profile.json +++ b/examples/names/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "forename", diff --git a/examples/partial-contradictions/profile.json b/examples/partial-contradictions/profile.json index cc15c90d6..4efa88012 100644 --- a/examples/partial-contradictions/profile.json +++ b/examples/partial-contradictions/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "Column 1", diff --git a/examples/partitioning/profile.json b/examples/partitioning/profile.json index 9178c6976..a7d0162df 100644 --- a/examples/partitioning/profile.json +++ b/examples/partitioning/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "p1f1", diff --git a/examples/real-number-range/profile.json b/examples/real-number-range/profile.json index 9d70cc3b6..9c646e5cc 100644 --- a/examples/real-number-range/profile.json +++ b/examples/real-number-range/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "a_number", diff --git a/examples/regex-contains/profile.json b/examples/regex-contains/profile.json index 805608df7..2e1d8842d 100644 --- a/examples/regex-contains/profile.json +++ b/examples/regex-contains/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "first_name", diff --git a/examples/regex-intersect-with-blacklist/profile.json b/examples/regex-intersect-with-blacklist/profile.json index 04320ad3c..31ecaab2f 100644 --- a/examples/regex-intersect-with-blacklist/profile.json +++ b/examples/regex-intersect-with-blacklist/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "first_name", diff --git a/examples/regex-intersect/profile.json b/examples/regex-intersect/profile.json index b3265a95a..fe8071e6e 100644 --- a/examples/regex-intersect/profile.json +++ b/examples/regex-intersect/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "first_name", diff --git a/examples/regex/profile.json b/examples/regex/profile.json index 0f49a0a94..a79dcdfa2 100644 --- a/examples/regex/profile.json +++ b/examples/regex/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "first_name", diff --git a/examples/setwise-combination/profile.json b/examples/setwise-combination/profile.json index 109ac9c42..06f52a147 100644 --- a/examples/setwise-combination/profile.json +++ b/examples/setwise-combination/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "a", diff --git a/examples/shorter-than/profile.json b/examples/shorter-than/profile.json index 41dd18174..c4e0f51c2 100644 --- a/examples/shorter-than/profile.json +++ b/examples/shorter-than/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "first_name", diff --git a/examples/string/profile.json b/examples/string/profile.json index 5d8ab0c85..fd48610f6 100644 --- a/examples/string/profile.json +++ b/examples/string/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "rules": [], "fields": [ { diff --git a/examples/unique/profile.json b/examples/unique/profile.json index cff54e36e..a2f9b2ac4 100644 --- a/examples/unique/profile.json +++ b/examples/unique/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "id", diff --git a/examples/user-account/profile.json b/examples/user-account/profile.json index cc7d9e889..c203a3b89 100644 --- a/examples/user-account/profile.json +++ b/examples/user-account/profile.json @@ -1,5 +1,5 @@ { - "schemaVersion": "0.8", + "schemaVersion": "0.9", "fields": [ { "name": "user_id", diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/general/EqualTo.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/general/EqualTo.feature index 45c2d6689..409f86dcb 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/general/EqualTo.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/general/EqualTo.feature @@ -47,12 +47,14 @@ Feature: User can specify that a value is equalTo a required value Scenario: Running an 'equalTo' of an invalid date value should fail with an error message Given there is a field foo + And foo has type "datetime" And foo is equal to 2010-13-40T00:00:00.000Z Then the profile is invalid because "Field \[foo\]: Date string '2010-13-40T00:00:00.000Z' must be in ISO-8601 format: yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between \(inclusive\) 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z" And no data is created Scenario: Running an 'equalTo' request that includes an invalid time value should fail with an error message Given there is a field foo + And foo has type "datetime" And foo is equal to 2010-01-01T55:00:00.000Z Then the profile is invalid because "Field \[foo\]: Date string '2010-01-01T55:00:00.000Z' must be in ISO-8601 format: yyyy-MM-ddTHH:mm:ss.SSS\[Z\] between \(inclusive\) 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z" And no data is created diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/GranularTo-DateTime.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/GranularTo-DateTime.feature index 524913913..8f58d0877 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/GranularTo-DateTime.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/operators/temporal/GranularTo-DateTime.feature @@ -90,9 +90,3 @@ Feature: User can specify that datetime fields are granular to a certain unit Then the following data should be generated: | foo | | 2000-01-01T00:00:01.000Z | - - - Scenario: Applying an invalid datetime granularTo constraint fails with an appropriate error - Given foo is granular to "decades" - Then the profile is invalid because "Field \[foo\]: Must be one of the supported datetime units \(millis, seconds, minutes, hours, days, months, years\)" - And no data is created diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/validation/CorrectConstraintTypes.feature b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/validation/CorrectConstraintTypes.feature index 9c6140df2..24c82dd50 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/validation/CorrectConstraintTypes.feature +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/features/validation/CorrectConstraintTypes.feature @@ -1,14 +1,14 @@ Feature: Correct Constraint Types, validation exceptions should be raised if the wrong typed constraint is applied to a field -Scenario: Running a 'inSet' request alongside a contradicting ofType = string should produce null -Given there is a field foo -And foo has type "string" -And foo is in set: -| 1 | -| 2 | -| 3 | -And foo has type "string" -Then the profile is invalid because "Field \[foo\]: is type STRING , but you are trying to apply a inSet constraint which requires NUMERIC" + Scenario: Running a 'inSet' request alongside a contradicting ofType = string should produce null + Given there is a field foo + And foo has type "string" + And foo is in set: + | 1 | + | 2 | + | 3 | + And foo has type "string" + Then the profile is invalid because "Field \[foo\]: is type STRING , but you are trying to apply a inSet constraint which requires NUMERIC" Scenario Outline: constraints cannot be applied to fields Given there is a field foo @@ -25,12 +25,7 @@ Then the profile is invalid because "Field \[foo\]: is type STRING , but you are | string | granularTo | NUMERIC | granular to 0.1 | STRING | | string | equalTo | NUMERIC | equal to 1 | STRING | - | string | after | DATETIME | after 2000-01-01T00:00:00.000Z | STRING | - | string | afterOrAt | DATETIME | after or at 2000-01-01T00:00:00.000Z| STRING | - | string | before | DATETIME | before 2000-01-01T00:00:00.000Z | STRING | - | string | beforeOrAt | DATETIME | before or at 2000-01-01T00:00:00.000Z| STRING | | string | granularTo | DATETIME | granular to "seconds" | STRING | - | string | equalTo | DATETIME | equal to 2000-01-01T00:00:00.000Z | STRING | | datetime| greaterThan | NUMERIC | greater than 4 | DATETIME | | datetime| greaterThanOrEqualTo | NUMERIC | greater than or equal to 4 | DATETIME | @@ -39,19 +34,11 @@ Then the profile is invalid because "Field \[foo\]: is type STRING , but you are | datetime| granularTo | NUMERIC | granular to 0.1 | DATETIME | | datetime| equalTo | NUMERIC | equal to 1 | DATETIME | - | datetime| matchingRegex | STRING | matching regex "ab" | DATETIME | - | datetime| containingRegex | STRING | containing regex "ab" | DATETIME | | datetime| ofLength | STRING | of length 3 | DATETIME | | datetime| shorterThan | STRING | shorter than 3 | DATETIME | | datetime| longerThan | STRING | longer than 3 | DATETIME | - | datetime| equalTo | STRING | equal to "test" | DATETIME | - | decimal | after | DATETIME | after 2000-01-01T00:00:00.000Z | NUMERIC | - | decimal | afterOrAt | DATETIME | after or at 2000-01-01T00:00:00.000Z| NUMERIC | - | decimal | before | DATETIME | before 2000-01-01T00:00:00.000Z | NUMERIC | - | decimal | beforeOrAt | DATETIME | before or at 2000-01-01T00:00:00.000Z| NUMERIC| | decimal | granularTo | DATETIME | granular to "seconds" | NUMERIC | - | decimal | equalTo | DATETIME | equal to 2000-01-01T00:00:00.000Z | NUMERIC | | decimal | matchingRegex | STRING | matching regex "ab" | NUMERIC | | decimal | containingRegex | STRING | containing regex "ab" | NUMERIC | diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/JarExecuteTests.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/JarExecuteTests.java index 23f3f42c1..d5fbbd383 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/JarExecuteTests.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/endtoend/JarExecuteTests.java @@ -28,9 +28,9 @@ public class JarExecuteTests { private String errorMessageOnFailure = "Jar test failed. This may have been caused by one of the following:" + - "1) You have not built the jar. \n Try running Gradle Build. \n" + - "2) System.out is being printed to (which interferes with streaming output) e.g. using 'printStackTrace'.\n" + - "3) There is a bug in code conditional on whether it is running inside the JAR, e.g. in SupportedVersionsGetter. \n"; + "1) You have not built the jar. \n Try running Gradle Build. \n" + + "2) System.out is being printed to (which interferes with streaming output) e.g. using 'printStackTrace'.\n" + + "3) There is a bug in code conditional on whether it is running inside the JAR, e.g. in SupportedVersionsGetter. \n"; @Test void generateSuccessfullyFromJar() throws Exception { @@ -38,7 +38,7 @@ void generateSuccessfullyFromJar() throws Exception { List collectedOutput = collectOutputAndCloseProcess(p); - assertEquals(Arrays.asList("foo", "\"Generation successful\""), collectedOutput, errorMessageOnFailure); + assertOnOutput(collectedOutput, "\"Generation successful\""); } @Test @@ -47,7 +47,12 @@ void generateSuccessfullyFromJarAndLoadFile() throws Exception { List collectedOutput = collectOutputAndCloseProcess(p); - assertEquals(Arrays.asList("foo", "\"Generated successfully from file\""), collectedOutput, "Either load from file no longer works, or " + errorMessageOnFailure); + assertOnOutput(collectedOutput, "\"Generated successfully from file\""); + } + + private void assertOnOutput(List collectedOutput, String message) { + assertEquals("foo", collectedOutput.get(collectedOutput.size() - 2), errorMessageOnFailure); + assertEquals(message, collectedOutput.get(collectedOutput.size() - 1), errorMessageOnFailure); } private Process setupProcess(final String profile) throws IOException { 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 32e36fab3..60f6b2d9e 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.8", + "schemaVersion": "0.9", "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 0000bc681..7db36943a 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.8", + "schemaVersion": "0.9", "description": "Testing Profile", "fields": [ { diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java index e41d66995..ded9fb44c 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java @@ -58,20 +58,18 @@ private DistributedSet getSet(Collection values, Types type) { } private Object getValue(Object value, Types type) { - if(value == null || type == null) return value; - switch (type) { - case NUMERIC: - return getBigDecimal(value); - case STRING: - return value; - case DATETIME: - if(!(value instanceof String) || value.equals("datetime") || value.equals("years") || value.equals("months") - || value.equals("days") || value.equals("hours") || value.equals("minutes") - || value.equals("seconds") || value.equals("millis")) return value; - return ConstraintReaderHelpers.parseDate((String) value); - default: - throw new IllegalStateException("Unexpected value: " + type); + if (type != null) { + switch (type) { + case NUMERIC: + return getBigDecimal(value); + case DATETIME: + if (!(value instanceof String) || value.equals("datetime") || value.equals("years") || value.equals("months") + || value.equals("days") || value.equals("hours") || value.equals("minutes") + || value.equals("seconds") || value.equals("millis")) return value; + return ConstraintReaderHelpers.parseDate((String) value); + } } + return value; } private Object getBigDecimal(Object value) { diff --git a/profile/src/main/resources/profileschema/datahelix.schema.json b/profile/src/main/resources/profileschema/datahelix.schema.json index 12bbe9b80..f86aa8f35 100644 --- a/profile/src/main/resources/profileschema/datahelix.schema.json +++ b/profile/src/main/resources/profileschema/datahelix.schema.json @@ -51,10 +51,13 @@ "definitions": { "schemaVersion": { "title": "The version of the DataHelix profile schema", - "const": "0.8" + "const": "0.9" }, "dataType": { - "oneOf": [ + "anyOf": [ + { + "$ref": "#/definitions/datetime" + }, { "$ref": "#/definitions/string" }, @@ -65,7 +68,7 @@ }, "datetime": { "title": "an ISO 8610 compatible string denoting a date and time", - "$ref": "#/definitions/string", + "type": "string", "default": "2000-01-01T09:00:00.000", "oneOf": [ { @@ -89,7 +92,14 @@ "string": { "type": "string", "maxLength": 1000, - "default": "string" + "default": "string", + "noneOf": [ + { + "pattern": "^(?!0000)[0-9]{4}-([0][0-9]|[1][0-2])-([0-2][0-9]|3[01])T([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9][.][0-9]{3}Z?$" + }, + { + "enum": ["now"] + }] }, "fieldDefinition": { "title": "The field definitions of a field to generate data for", @@ -200,7 +210,10 @@ ] }, "value": { - "oneOf": [ + "anyOf": [ + { + "$ref": "#/definitions/datetime" + }, { "$ref": "#/definitions/numeric" }, @@ -536,7 +549,10 @@ "values": { "type": "array", "items": { - "oneOf": [ + "anyOf": [ + { + "$ref": "#/definitions/datetime" + }, { "$ref": "#/definitions/numeric" }, 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 e0f3b3039..a3e1bafc0 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/ProfileSchemaImmutabilityTests.java @@ -85,6 +85,9 @@ private static Set versionToHash() { versionToHash.add(new VersionHash( "0.8", "a92498b428e5866eab85a011c5c071afd11ebd76520714e2a301968e06b1997e")); + versionToHash.add(new VersionHash( + "0.9", + "3e84866fba173ce6528da8994acf7a60fd879ae472246482b0e29ec2b7906321")); return versionToHash; } diff --git a/profile/src/test/java/com/scottlogic/deg/profile/dto/ProfileSchemaValidatorTests.java b/profile/src/test/java/com/scottlogic/deg/profile/dto/ProfileSchemaValidatorTests.java index d4ec399a7..3cd828bd3 100644 --- a/profile/src/test/java/com/scottlogic/deg/profile/dto/ProfileSchemaValidatorTests.java +++ b/profile/src/test/java/com/scottlogic/deg/profile/dto/ProfileSchemaValidatorTests.java @@ -207,20 +207,12 @@ void validate_dateEqualToDynamicOffset_isValid() { " \"rules\": [" + " {" + " \"constraints\": [" + - " { \"field\": \"first\", \"is\": \"after\", \"value\": {" + - " \"date\": \"8001-02-03T04:05:06.007\" }" + - " }," + + " { \"field\": \"first\", \"is\": \"after\", \"value\": \"8001-02-03T04:05:06.007\" }," + " { \"field\": \"second\", \"is\": \"equalTo\", \"otherField\": \"first\", \"offset\": 3, \"offsetUnit\": \"days\" }," + - " { \"field\": \"firstWorking\", \"is\": \"equalTo\", \"value\": {" + - " \"date\": \"2019-08-12T12:00:00.000\" }" + - " }," + + " { \"field\": \"firstWorking\", \"is\": \"equalTo\", \"value\": \"2019-08-12T12:00:00.000\" }," + " { \"field\": \"secondWorking\", \"is\": \"equalTo\", \"otherField\": \"firstWorking\", \"offset\": 8, \"offsetUnit\": \"working days\" }," + - " { \"field\": \"current\", \"is\": \"before\", \"value\": {" + - " \"date\": \"now\" }" + - " }," + - " { \"field\": \"current\", \"is\": \"after\", \"value\": {" + - " \"date\": \"2019-06-01T12:00:00.000\" }" + - " } ] } ]" + + " { \"field\": \"current\", \"is\": \"before\", \"value\": \"now\" }," + + " { \"field\": \"current\", \"is\": \"after\", \"value\": \"2019-06-01T12:00:00.000\" } ] } ]" + "}"; validator.validateProfile(profile, schema); @@ -311,10 +303,10 @@ void validate_simpleInSet_isValid() { " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [\"%ggg\", \"test\"] }," + " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [3, 32] }," + " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [\"%ggg\", 32] }," + - " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [\"%ggg\", {\"date\": \"2000-01-01T09:00:00.000\"}] }," + - " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [4, {\"date\": \"2000-01-01T09:00:00.000\"}] }," + - " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [{\"date\": \"2000-01-01T09:00:00.000\"}, {\"date\": \"2000-01-01T09:00:00.000\"}] }," + - " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [\"%ggg\", {\"date\": \"2000-01-01T09:00:00.000\"}, 54] }" + + " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [\"%ggg\", \"2000-01-01T09:00:00.000\"] }," + + " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [4, \"2000-01-01T09:00:00.000\"] }," + + " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [\"2000-01-01T09:00:00.000\", \"2000-01-01T09:00:00.000\"] }," + + " { \"field\": \"field1\", \"is\": \"inSet\", \"values\": [\"%ggg\", \"2000-01-01T09:00:00.000\", 54] }" + " ] } ]" + "}"; @@ -470,16 +462,16 @@ void validate_simpleDateTimes_isValid() { " {" + " \"rule\": \"rule 1\"," + " \"constraints\": [" + - " { \"field\": \"field1\", \"is\": \"after\", \"value\": {\"date\": \"2000-01-01T09:00:00.000\"} }," + - " { \"field\": \"field1\", \"is\": \"afterOrAt\", \"value\": {\"date\": \"2000-01-01T09:00:00.000\"} }," + - " { \"field\": \"field1\", \"is\": \"before\", \"value\": {\"date\": \"2000-01-01T09:00:00.000\"} }," + - " { \"field\": \"field1\", \"is\": \"beforeOrAt\", \"value\": {\"date\": \"0001-01-01T09:00:00.000\"} }," + - " { \"field\": \"field1\", \"is\": \"equalTo\", \"value\": {\"date\": \"0001-01-01T09:00:00.000\"} }," + - " { \"not\": { \"field\": \"field1\", \"is\": \"after\", \"value\": {\"date\": \"2000-01-01T09:00:00.000\"} } }," + - " { \"not\": { \"field\": \"field1\", \"is\": \"afterOrAt\", \"value\": {\"date\": \"2000-01-01T09:00:00.000\"} } }," + - " { \"not\": { \"field\": \"field1\", \"is\": \"before\", \"value\": {\"date\": \"2000-01-01T09:00:00.000\"} } }," + - " { \"not\": { \"field\": \"field1\", \"is\": \"beforeOrAt\", \"value\": {\"date\": \"0001-01-01T09:00:00.000\"} } }," + - " { \"not\": { \"field\": \"field1\", \"is\": \"equalTo\", \"value\": {\"date\": \"0001-01-01T09:00:00.000\"} } }" + + " { \"field\": \"field1\", \"is\": \"after\", \"value\": \"2000-01-01T09:00:00.000\"}," + + " { \"field\": \"field1\", \"is\": \"afterOrAt\", \"value\": \"2000-01-01T09:00:00.000\"}," + + " { \"field\": \"field1\", \"is\": \"before\", \"value\": \"2000-01-01T09:00:00.000\"}," + + " { \"field\": \"field1\", \"is\": \"beforeOrAt\", \"value\": \"0001-01-01T09:00:00.000\"}," + + " { \"field\": \"field1\", \"is\": \"equalTo\", \"value\": \"0001-01-01T09:00:00.000\"}," + + " { \"not\": { \"field\": \"field1\", \"is\": \"after\", \"value\": \"2000-01-01T09:00:00.000\"} }," + + " { \"not\": { \"field\": \"field1\", \"is\": \"afterOrAt\", \"value\": \"2000-01-01T09:00:00.000\"} }," + + " { \"not\": { \"field\": \"field1\", \"is\": \"before\", \"value\": \"2000-01-01T09:00:00.000\"} }," + + " { \"not\": { \"field\": \"field1\", \"is\": \"beforeOrAt\", \"value\": \"0001-01-01T09:00:00.000\"} }," + + " { \"not\": { \"field\": \"field1\", \"is\": \"equalTo\", \"value\": \"0001-01-01T09:00:00.000\"} }" + " ]" + " }" + " ]" + 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 9eaeaf644..25b3419d7 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 @@ -592,8 +592,8 @@ public void shouldAllowValidISO8601DateTime() throws IOException { " \"rules\": [" + " {" + " \"constraints\": [" + - " { \"field\": \"foo\", \"is\": \"afterOrAt\", \"value\": { \"date\": \"2019-01-01T00:00:00.000\" } }," + - " { \"field\": \"foo\", \"is\": \"before\", \"value\": { \"date\": \"2019-01-03T00:00:00.000\" } }" + + " { \"field\": \"foo\", \"is\": \"afterOrAt\", \"value\": \"2019-01-01T00:00:00.000\" }," + + " { \"field\": \"foo\", \"is\": \"before\", \"value\": \"2019-01-03T00:00:00.000\" }" + " ]" + " }" + " ]" + @@ -667,7 +667,7 @@ public void shouldRejectNonISO8601DateTime() { " ]" + "}"); - expectInvalidProfileException("Field [foo]: Dates should be expressed in object format e.g. { \"date\": \"yyyy-MM-ddTHH:mm:ss.SSS[Z]\" }"); + expectInvalidProfileException("Field [foo]: Date string '2018-01-12' must be in ISO-8601 format: yyyy-MM-ddTHH:mm:ss.SSS[Z] between (inclusive) 0001-01-01T00:00:00.000Z and 9999-12-31T23:59:59.999Z"); } @Test From 9976fcb3ebfbd39628e97c1b7378d537f391c53f Mon Sep 17 00:00:00 2001 From: Charlton Dowding Date: Thu, 3 Oct 2019 16:45:11 +0100 Subject: [PATCH 6/6] Seperated TimeScale out of getValue method --- .../atomic/AtomicConstraintValueReader.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java index ded9fb44c..a267e9ec9 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/AtomicConstraintValueReader.java @@ -4,6 +4,7 @@ import com.scottlogic.deg.common.ValidationException; import com.scottlogic.deg.common.profile.Types; import com.scottlogic.deg.common.profile.constraintdetail.AtomicConstraintType; +import com.scottlogic.deg.common.profile.constraintdetail.Timescale; import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedSet; import com.scottlogic.deg.profile.dto.ConstraintDTO; @@ -15,6 +16,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import java.util.stream.Stream; public class AtomicConstraintValueReader { @@ -58,18 +60,24 @@ private DistributedSet getSet(Collection values, Types type) { } private Object getValue(Object value, Types type) { - if (type != null) { - switch (type) { - case NUMERIC: - return getBigDecimal(value); - case DATETIME: - if (!(value instanceof String) || value.equals("datetime") || value.equals("years") || value.equals("months") - || value.equals("days") || value.equals("hours") || value.equals("minutes") - || value.equals("seconds") || value.equals("millis")) return value; - return ConstraintReaderHelpers.parseDate((String) value); - } + if (type == null) { + return value; + } + switch (type) { + case NUMERIC: + return getBigDecimal(value); + case DATETIME: + if (!(value instanceof String) || value.equals("datetime") || isTimeScale((String)value)) { + return value; + } + return ConstraintReaderHelpers.parseDate((String) value); + default: + return value; } - return value; + } + + private static boolean isTimeScale(String value) { + return Stream.of(Timescale.values()).map(Timescale::toString).anyMatch(value::equals); } private Object getBigDecimal(Object value) {