diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/Field.java b/common/src/main/java/com/scottlogic/deg/common/profile/Field.java index e280b22e6..9d3ee0afe 100644 --- a/common/src/main/java/com/scottlogic/deg/common/profile/Field.java +++ b/common/src/main/java/com/scottlogic/deg/common/profile/Field.java @@ -20,12 +20,12 @@ public class Field { public final String name; - private final Types type; + private final FieldType type; private final boolean unique; private final String formatting; private final boolean internal; - public Field(String name, Types type, boolean unique, String formatting, boolean internal) { + public Field(String name, FieldType type, boolean unique, String formatting, boolean internal) { this.name = name; this.type = type; this.unique = unique; @@ -66,7 +66,7 @@ public String getFormatting() { return formatting; } - public Types getType() { + public FieldType getType() { return type; } diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/FieldType.java b/common/src/main/java/com/scottlogic/deg/common/profile/FieldType.java new file mode 100644 index 000000000..6608ef76c --- /dev/null +++ b/common/src/main/java/com/scottlogic/deg/common/profile/FieldType.java @@ -0,0 +1,8 @@ +package com.scottlogic.deg.common.profile; + +public enum FieldType +{ + NUMERIC, + STRING, + DATETIME +} diff --git a/common/src/main/java/com/scottlogic/deg/common/profile/Types.java b/common/src/main/java/com/scottlogic/deg/common/profile/Types.java deleted file mode 100644 index f4d57317e..000000000 --- a/common/src/main/java/com/scottlogic/deg/common/profile/Types.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.scottlogic.deg.common.profile; - -import java.time.OffsetDateTime; -import java.util.function.Function; - -public enum Types { - NUMERIC(o -> o instanceof Number), - STRING(o -> o instanceof String), - DATETIME(o -> o instanceof OffsetDateTime); - - private final Function isInstanceOf; - - Types(final Function isInstanceOf) { - this.isInstanceOf = isInstanceOf; - } - - public boolean isInstanceOf(Object o) { - return isInstanceOf.apply(o); - } -} diff --git a/common/src/test/java/com/scottlogic/deg/common/profile/FieldBuilder.java b/common/src/test/java/com/scottlogic/deg/common/profile/FieldBuilder.java index 751886049..800671ef4 100644 --- a/common/src/test/java/com/scottlogic/deg/common/profile/FieldBuilder.java +++ b/common/src/test/java/com/scottlogic/deg/common/profile/FieldBuilder.java @@ -18,15 +18,15 @@ public class FieldBuilder { public static Field createField(String name) { - return createField(name, Types.STRING); + return createField(name, FieldType.STRING); } public static Field createInternalField(String name) { - return createInternalField(name, Types.STRING); + return createInternalField(name, FieldType.STRING); } - public static Field createField(String name, Types type) { + public static Field createField(String name, FieldType type) { return new Field(name, type, false, null, false); } - public static Field createInternalField(String name, Types type) { + public static Field createInternalField(String name, FieldType type) { return new Field(name, type, false, null, true); } } diff --git a/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/FieldSpec.java b/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/FieldSpec.java index 672926ce7..bdbde988b 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/FieldSpec.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/FieldSpec.java @@ -16,7 +16,7 @@ package com.scottlogic.deg.generator.fieldspecs; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.restrictions.*; @@ -41,7 +41,7 @@ public static FieldSpec fromList(DistributedList whitelist) { public static FieldSpec fromRestriction(TypedRestrictions restrictions) { return new FieldSpec(null, restrictions, true, Collections.emptySet()); } - public static FieldSpec fromType(Types type) { + public static FieldSpec fromType(FieldType type) { switch (type) { case NUMERIC: return new FieldSpec(null, createDefaultNumericRestrictions(), true, Collections.emptySet()); diff --git a/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperation.java b/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperation.java index 5a155b53d..28214173c 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperation.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperation.java @@ -16,7 +16,6 @@ package com.scottlogic.deg.generator.fieldspecs; -import com.scottlogic.deg.common.profile.Types; import com.scottlogic.deg.generator.restrictions.*; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsMerger; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/generation/FieldValueSourceEvaluator.java b/generator/src/main/java/com/scottlogic/deg/generator/generation/FieldValueSourceEvaluator.java index cb5970a6d..496cbaa08 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/generation/FieldValueSourceEvaluator.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/generation/FieldValueSourceEvaluator.java @@ -16,7 +16,7 @@ package com.scottlogic.deg.generator.generation; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.generation.fieldvaluesources.*; import com.scottlogic.deg.generator.generation.fieldvaluesources.datetime.DateTimeFieldValueSource; @@ -24,21 +24,18 @@ import com.scottlogic.deg.generator.generation.string.generators.StringGenerator; import com.scottlogic.deg.generator.restrictions.*; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions; -import com.scottlogic.deg.common.profile.constraintdetail.NumericGranularity; import java.math.BigDecimal; import java.time.OffsetDateTime; import java.util.*; -import static com.scottlogic.deg.common.util.Defaults.*; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createDateTimeRestrictions; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; -import static com.scottlogic.deg.generator.utils.Defaults.*; public class FieldValueSourceEvaluator { private static final FieldValueSource NULL_ONLY_SOURCE = new NullOnlySource(); - public FieldValueSource getFieldValueSources(Types type, FieldSpec fieldSpec){ + public FieldValueSource getFieldValueSources(FieldType type, FieldSpec fieldSpec){ Optional source = getSource(type, fieldSpec); @@ -54,7 +51,7 @@ public FieldValueSource getFieldValueSources(Types type, FieldSpec fieldSpec){ return new NullAppendingValueSource(source.get()); } - private Optional getSource(Types type, FieldSpec fieldSpec) { + private Optional getSource(FieldType type, FieldSpec fieldSpec) { if (fieldSpec.getWhitelist() != null){ if (fieldSpec.getWhitelist().isEmpty()){ return Optional.empty(); @@ -66,7 +63,7 @@ private Optional getSource(Types type, FieldSpec fieldSpec) { return Optional.of(getRestrictionSource(type, fieldSpec)); } - private FieldValueSource getRestrictionSource(Types type, FieldSpec fieldSpec) { + private FieldValueSource getRestrictionSource(FieldType type, FieldSpec fieldSpec) { switch (type) { case DATETIME: return getDateTimeSource(fieldSpec); diff --git a/generator/src/main/java/com/scottlogic/deg/generator/restrictions/StringRestrictions.java b/generator/src/main/java/com/scottlogic/deg/generator/restrictions/StringRestrictions.java index 195c6e9b8..9e85cc16c 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/restrictions/StringRestrictions.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/restrictions/StringRestrictions.java @@ -16,7 +16,6 @@ package com.scottlogic.deg.generator.restrictions; -import com.scottlogic.deg.common.profile.Types; import com.scottlogic.deg.generator.generation.string.generators.StringGenerator; import java.util.Optional; diff --git a/generator/src/main/java/com/scottlogic/deg/generator/restrictions/linear/LinearRestrictionsFactory.java b/generator/src/main/java/com/scottlogic/deg/generator/restrictions/linear/LinearRestrictionsFactory.java index e2a00ad37..a90ac0f0c 100644 --- a/generator/src/main/java/com/scottlogic/deg/generator/restrictions/linear/LinearRestrictionsFactory.java +++ b/generator/src/main/java/com/scottlogic/deg/generator/restrictions/linear/LinearRestrictionsFactory.java @@ -1,6 +1,5 @@ package com.scottlogic.deg.generator.restrictions.linear; -import com.scottlogic.deg.common.profile.Types; import com.scottlogic.deg.common.profile.constraintdetail.Granularity; import java.math.BigDecimal; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeOptimiserTest.java b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeOptimiserTest.java index 544ec8a81..020e5805e 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeOptimiserTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/decisiontree/DecisionTreeOptimiserTest.java @@ -18,15 +18,14 @@ import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.common.profile.ProfileFields; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import java.util.Collections; +import static com.scottlogic.deg.common.profile.FieldBuilder.createField; import static com.scottlogic.deg.generator.builders.TestConstraintNodeBuilder.constraintNode; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; -import static com.scottlogic.deg.common.profile.FieldBuilder.createField; class DecisionTreeOptimiserTest { @@ -94,79 +93,4 @@ public void optimise_oneCommonIf(){ assertThat(actual, sameBeanAs(original)); } - - @Disabled ("what???") - @Test - public void optimise_oneCommonIfTwoFields() { - ConstraintNode original = constraintNode() - .where(A).isInSet("a1", "a2") - .where(B).isInSet("b1", "b2") - .where(C).isInSet("c1", "c2") - .where(D).isInSet("d1", "d2") - .where(E).isInSet("e1", "e2") - .where(F).isInSet("f1", "f2") - .withDecision( - constraintNode() - .where(A).isInSet("a1") - .where(B).isInSet("b1") - .where(C).isInSet("c1") - .where(E).isInSet("e1"), - constraintNode() - .where(A).isNotInSet("a1"), - constraintNode() - .where(B).isNotInSet("b1"), - constraintNode() - .where(C).isNotInSet("c1")) - .withDecision( - constraintNode() - .where(A).isInSet("a1") - .where(B).isInSet("b1") - .where(D).isInSet("d1") - .where(F).isInSet("f1"), - constraintNode() - .where(A).isNotInSet("a1"), - constraintNode() - .where(B).isNotInSet("b1"), - constraintNode() - .where(D).isNotInSet("d1")) - .build(); - - ConstraintNode actual = optimiser.optimiseTree(new DecisionTree(original, new ProfileFields(Collections.EMPTY_LIST))) - .getRootNode(); - - - ConstraintNode expected = constraintNode() - .where(A).isInSet("a1", "a2") - .where(B).isInSet("b1", "b2") - .where(C).isInSet("c1", "c2") - .where(D).isInSet("d1", "d2") - .where(E).isInSet("e1", "e2") - .where(F).isInSet("f1", "f2") - .withDecision( - constraintNode() - .where(A).isInSet("a1") - .withDecision( - constraintNode() - .where(B).isInSet("b1") - .withDecision( - constraintNode() - .where(C).isInSet("c1") - .where(E).isInSet("e1"), - constraintNode() - .where(C).isNotInSet("c1") - ) - .withDecision( - constraintNode() - .where(D).isInSet("d1") - .where(F).isInSet("f1"), - constraintNode() - .where(D).isNotInSet("d1")), - constraintNode() - .where(B).isNotInSet("b1")), - constraintNode() - .where(A).isNotInSet("a1") - ).build(); - - assertThat(actual, sameBeanAs(expected)); - } } \ No newline at end of file diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/FieldSpecTests.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/FieldSpecTests.java index 6761c28db..2bdc4f63f 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/FieldSpecTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/FieldSpecTests.java @@ -16,7 +16,7 @@ package com.scottlogic.deg.generator.fieldspecs; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.generation.string.generators.StringGenerator; import com.scottlogic.deg.generator.restrictions.*; @@ -30,7 +30,7 @@ import java.util.Arrays; import java.util.Optional; -import static com.scottlogic.deg.common.profile.Types.*; +import static com.scottlogic.deg.common.profile.FieldType.*; import static com.scottlogic.deg.generator.restrictions.StringRestrictionsFactory.forMaxLength; import static com.scottlogic.deg.generator.utils.Defaults.*; import static org.hamcrest.core.IsEqual.equalTo; @@ -42,7 +42,7 @@ class FieldSpecTests { @Test void equals_objTypeIsNotFieldSpec_returnsFalse() { - FieldSpec fieldSpec = FieldSpec.fromType(Types.STRING); + FieldSpec fieldSpec = FieldSpec.fromType(FieldType.STRING); boolean result = fieldSpec.equals("Test"); @@ -56,7 +56,7 @@ void equals_objTypeIsNotFieldSpec_returnsFalse() { void equals_fieldSpecHasSetRestrictionsAndOtherObjectSetRestrictionsNull_returnsFalse() { FieldSpec fieldSpec = FieldSpec.fromList(DistributedList.singleton("whitelist")); - boolean result = fieldSpec.equals(FieldSpec.fromType(Types.STRING)); + boolean result = fieldSpec.equals(FieldSpec.fromType(FieldType.STRING)); assertFalse( "Expected that when the field spec has set restrictions and the other object set restrictions are null a false value should be returned but was true", @@ -66,7 +66,7 @@ void equals_fieldSpecHasSetRestrictionsAndOtherObjectSetRestrictionsNull_returns @Test void equals_fieldSpecSetRestrictionsNullAndOtherObjectHasSetRestrictions_returnsFalse() { - FieldSpec fieldSpec = FieldSpec.fromType(Types.STRING); + FieldSpec fieldSpec = FieldSpec.fromType(FieldType.STRING); boolean result = fieldSpec.equals( FieldSpec.fromList(DistributedList.singleton("whitelist"))); @@ -112,7 +112,7 @@ void equals_fieldSpecNumericRestrictionsNotNullAndOtherObjectNumericRestrictions @Test public void shouldCreateNewInstanceWithNullRestrictions() { - FieldSpec original = FieldSpec.fromType(Types.STRING); + FieldSpec original = FieldSpec.fromType(FieldType.STRING); FieldSpec augmentedFieldSpec = original.withNotNull(); Assert.assertNotSame(original, augmentedFieldSpec); @@ -120,8 +120,8 @@ public void shouldCreateNewInstanceWithNullRestrictions() { @Test public void emptyFieldSpecsShouldBeEqualAndHaveSameHashCode() { - FieldSpec first = FieldSpec.fromType(Types.STRING); - FieldSpec second = FieldSpec.fromType(Types.STRING); + FieldSpec first = FieldSpec.fromType(FieldType.STRING); + FieldSpec second = FieldSpec.fromType(FieldType.STRING); Assert.assertThat(first, equalTo(second)); Assert.assertThat(first.hashCode(), equalTo(second.hashCode())); @@ -167,8 +167,8 @@ public void fieldSpecsWithUnequalRestrictionsShouldBeUnequal() { @Test public void fieldSpecsWithEqualTypeRestrictionsShouldBeEqual() { - FieldSpec a = FieldSpec.fromType(Types.STRING); - FieldSpec b = FieldSpec.fromType(Types.STRING); + FieldSpec a = FieldSpec.fromType(FieldType.STRING); + FieldSpec b = FieldSpec.fromType(FieldType.STRING); Assert.assertThat(a, equalTo(b)); Assert.assertThat(a.hashCode(), equalTo(b.hashCode())); @@ -176,8 +176,8 @@ public void fieldSpecsWithEqualTypeRestrictionsShouldBeEqual() { @Test public void fieldSpecsWithEqualNullRestrictionsShouldBeEqual() { - FieldSpec a = FieldSpec.fromType(Types.STRING).withNotNull(); - FieldSpec b = FieldSpec.fromType(Types.STRING).withNotNull(); + FieldSpec a = FieldSpec.fromType(FieldType.STRING).withNotNull(); + FieldSpec b = FieldSpec.fromType(FieldType.STRING).withNotNull(); Assert.assertThat(a, equalTo(b)); Assert.assertThat(a.hashCode(), equalTo(b.hashCode())); @@ -185,7 +185,7 @@ public void fieldSpecsWithEqualNullRestrictionsShouldBeEqual() { @Test public void fieldSpecsWithUnequalNullRestrictionsShouldBeUnequal() { - FieldSpec a = FieldSpec.fromType(Types.STRING).withNotNull(); + FieldSpec a = FieldSpec.fromType(FieldType.STRING).withNotNull(); FieldSpec b = FieldSpec.nullOnly(); Assert.assertThat(a, not(equalTo(b))); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperationTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperationTest.java index db7725225..94bba2c2e 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperationTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RestrictionsMergeOperationTest.java @@ -16,7 +16,6 @@ package com.scottlogic.deg.generator.fieldspecs; -import com.scottlogic.deg.common.profile.Types; import com.scottlogic.deg.generator.restrictions.StringRestrictions; import com.scottlogic.deg.generator.restrictions.StringRestrictionsFactory; import com.scottlogic.deg.generator.restrictions.StringRestrictionsMerger; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMergerTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMergerTest.java index 514e4ebcd..c236e5a9c 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMergerTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/RowSpecMergerTest.java @@ -3,7 +3,7 @@ import com.google.common.collect.ImmutableMap; import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.common.profile.ProfileFields; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -17,7 +17,7 @@ class RowSpecMergerTest { RowSpecMerger rowSpecMerger = new RowSpecMerger(new FieldSpecMerger()); FieldSpec isNull = FieldSpec.nullOnly(); - FieldSpec notNull = FieldSpec.fromType(Types.STRING).withNotNull(); + FieldSpec notNull = FieldSpec.fromType(FieldType.STRING).withNotNull(); Field A = createField("A"); Field B = createField("B"); ProfileFields fields = new ProfileFields(Arrays.asList(A, B)); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/AfterDateRelationTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/AfterDateRelationTest.java index f61691c52..b51399139 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/AfterDateRelationTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/AfterDateRelationTest.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.generator.fieldspecs.relations; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.common.profile.constraintdetail.DateTimeGranularity; import com.scottlogic.deg.common.profile.constraintdetail.Granularity; import com.scottlogic.deg.common.util.defaults.DateTimeDefaults; @@ -35,8 +35,8 @@ public class AfterDateRelationTest { - private final Field a = new Field("a", Types.DATETIME, false, "", false); - private final Field b = new Field("b", Types.DATETIME, false, "", false); + private final Field a = new Field("a", FieldType.DATETIME, false, "", false); + private final Field b = new Field("b", FieldType.DATETIME, false, "", false); @Test public void testReduceToFieldSpec_withNotNull_reducesToSpec() { @@ -85,7 +85,7 @@ public void testReduceToFieldSpec_withNull_reducesToSpec() { FieldSpec result = afterDateRelations.reduceValueToFieldSpec(generatedValue); - FieldSpec expected = FieldSpec.fromType(Types.DATETIME); + FieldSpec expected = FieldSpec.fromType(FieldType.DATETIME); assertEquals(expected, result); } diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/BeforeDateRelationTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/BeforeDateRelationTest.java index 455e2dfcd..982a0cd7d 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/BeforeDateRelationTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/BeforeDateRelationTest.java @@ -17,7 +17,7 @@ package com.scottlogic.deg.generator.fieldspecs.relations; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.common.profile.constraintdetail.DateTimeGranularity; import com.scottlogic.deg.common.profile.constraintdetail.Granularity; import com.scottlogic.deg.common.util.defaults.DateTimeDefaults; @@ -35,8 +35,8 @@ public class BeforeDateRelationTest { - private final Field a = new Field("a", Types.DATETIME, false, "", false); - private final Field b = new Field("b", Types.DATETIME, false, "", false); + private final Field a = new Field("a", FieldType.DATETIME, false, "", false); + private final Field b = new Field("b", FieldType.DATETIME, false, "", false); @Test public void testReduceToFieldSpec_withNotNull_reducesToSpec() { @@ -85,7 +85,7 @@ public void testReduceToFieldSpec_withNull_reducesToSpec() { FieldSpec result = beforeDateRelations.reduceValueToFieldSpec(generatedValue); - FieldSpec expected = FieldSpec.fromType(Types.DATETIME); + FieldSpec expected = FieldSpec.fromType(FieldType.DATETIME); assertEquals(expected, result); } diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/EqualToDateRelationTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/EqualToDateRelationTest.java index 57129cb84..f45a6f842 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/EqualToDateRelationTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/EqualToDateRelationTest.java @@ -1,26 +1,22 @@ package com.scottlogic.deg.generator.fieldspecs.relations; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.Types; -import com.scottlogic.deg.common.profile.constraintdetail.DateTimeGranularity; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.generation.databags.DataBagValue; -import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions; import org.junit.jupiter.api.Test; import java.time.OffsetDateTime; import java.time.ZoneOffset; -import java.time.temporal.ChronoUnit; + import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; -import static org.junit.jupiter.api.Assertions.*; - class EqualToDateRelationTest { - private final Field a = new Field("a", Types.DATETIME, false ,"", false); - private final Field b = new Field("b", Types.DATETIME, false, "", false); + private final Field a = new Field("a", FieldType.DATETIME, false ,"", false); + private final Field b = new Field("b", FieldType.DATETIME, false, "", false); private final FieldSpecRelations equalToDateRelations = new EqualToRelation(a, b); @Test diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/FieldSpecRelationsTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/FieldSpecRelationsTest.java index 2885ca91a..43cb42289 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/FieldSpecRelationsTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/FieldSpecRelationsTest.java @@ -1,7 +1,7 @@ package com.scottlogic.deg.generator.fieldspecs.relations; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.common.profile.constraintdetail.DateTimeGranularity; import com.scottlogic.deg.common.util.defaults.DateTimeDefaults; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; @@ -21,8 +21,8 @@ import static java.time.temporal.ChronoUnit.YEARS; class FieldSpecRelationsTest { - private Field main = createField("main", Types.DATETIME); - private Field other = createField("other", Types.DATETIME); + private Field main = createField("main", FieldType.DATETIME); + private Field other = createField("other", FieldType.DATETIME); @Test public void equalTo_exactValue_returnsSame(){ diff --git a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/InMapIndexRelationTest.java b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/InMapIndexRelationTest.java index 9dd56a057..1dfc26aac 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/InMapIndexRelationTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/fieldspecs/relations/InMapIndexRelationTest.java @@ -1,7 +1,7 @@ package com.scottlogic.deg.generator.fieldspecs.relations; import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.generator.fieldspecs.FieldSpec; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.restrictions.StringRestrictionsFactory; @@ -31,7 +31,7 @@ static void before() { @Test void reduceToRelatedFieldSpec_whenAllValid_returnCompleteWhiteList() { - FieldSpec parameter = FieldSpec.fromType(Types.STRING); + FieldSpec parameter = FieldSpec.fromType(FieldType.STRING); FieldSpec expected = FieldSpec.fromList(DistributedList.uniform(Arrays.asList(0, 1))).withNotNull(); FieldSpec actual = testInstance.reduceToRelatedFieldSpec(parameter); diff --git a/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecValueGeneratorTests.java b/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecValueGeneratorTests.java index 7ed97c7d4..8d2481a21 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecValueGeneratorTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldSpecValueGeneratorTests.java @@ -34,8 +34,8 @@ import java.util.stream.Stream; import static com.scottlogic.deg.common.profile.FieldBuilder.createField; -import static com.scottlogic.deg.common.profile.Types.NUMERIC; -import static com.scottlogic.deg.common.profile.Types.STRING; +import static com.scottlogic.deg.common.profile.FieldType.NUMERIC; +import static com.scottlogic.deg.common.profile.FieldType.STRING; import static com.scottlogic.deg.generator.config.detail.DataGenerationType.*; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldValueSourceEvaluatorTests.java b/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldValueSourceEvaluatorTests.java index 0b35f461d..57dc4e18f 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldValueSourceEvaluatorTests.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/generation/FieldValueSourceEvaluatorTests.java @@ -33,7 +33,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import static com.scottlogic.deg.common.profile.Types.*; +import static com.scottlogic.deg.common.profile.FieldType.*; import static com.scottlogic.deg.generator.restrictions.linear.LinearRestrictionsFactory.createNumericRestrictions; import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MAX_LIMIT; import static com.scottlogic.deg.generator.utils.Defaults.NUMERIC_MIN_LIMIT; diff --git a/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java b/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java index 5de627d72..226e5e15f 100644 --- a/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java +++ b/generator/src/test/java/com/scottlogic/deg/generator/reducer/ConstraintReducerTest.java @@ -26,7 +26,6 @@ import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.fieldspecs.whitelist.WeightedElement; import com.scottlogic.deg.generator.profile.constraints.atomic.*; -import com.scottlogic.deg.generator.restrictions.StringRestrictionsFactory; import com.scottlogic.deg.generator.restrictions.linear.LinearRestrictions; import com.scottlogic.deg.generator.utils.SetUtils; import org.hamcrest.core.Is; @@ -42,7 +41,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static com.scottlogic.deg.common.profile.Types.*; +import static com.scottlogic.deg.common.profile.FieldType.*; import static com.scottlogic.deg.common.util.Defaults.*; import static org.hamcrest.Matchers.*; import static com.scottlogic.deg.common.profile.FieldBuilder.createField; diff --git a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java index e9aa93d7b..95c5d8c64 100644 --- a/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java +++ b/orchestrator/src/test/java/com/scottlogic/deg/orchestrator/cucumber/testframework/utils/CucumberTestState.java @@ -18,8 +18,6 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.scottlogic.deg.common.profile.Field; -import com.scottlogic.deg.common.profile.Types; import com.scottlogic.deg.generator.config.detail.CombinationStrategyType; import com.scottlogic.deg.generator.config.detail.DataGenerationType; import com.scottlogic.deg.common.profile.constraintdetail.AtomicConstraintType; 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 dbb01b7b9..2baafd961 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 @@ -2,7 +2,7 @@ import com.google.inject.Inject; import com.scottlogic.deg.common.ValidationException; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.common.profile.constraintdetail.AtomicConstraintType; import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; @@ -10,11 +10,9 @@ import com.scottlogic.deg.profile.reader.InvalidProfileException; import java.math.BigDecimal; -import java.time.OffsetDateTime; import java.time.temporal.ChronoUnit; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -28,7 +26,7 @@ public AtomicConstraintValueReader(FromFileReader fromFileReader) { } - public Object getValue(ConstraintDTO dto, Types type){ + public Object getValue(ConstraintDTO dto, FieldType type){ try { return tryGetValue(dto, type); } catch (IllegalArgumentException | ValidationException e){ @@ -36,7 +34,7 @@ public Object getValue(ConstraintDTO dto, Types type){ } } - private Object tryGetValue(ConstraintDTO dto, Types type){ + private Object tryGetValue(ConstraintDTO dto, FieldType type){ if (dto.values != null){ return getSet(dto.values, type); } @@ -52,14 +50,14 @@ private Object tryGetValue(ConstraintDTO dto, Types type){ return getValue(dto.value, type); } - private DistributedList getList(Collection values, Types type) { + private DistributedList getList(Collection values, FieldType type) { List collect = values.stream() .map(val -> getValue(val, type)) .collect(Collectors.toList()); return DistributedList.uniform(collect); } - private DistributedList getSet(Collection values, Types type) { + private DistributedList getSet(Collection values, FieldType type) { List collect = values.stream() .map(val -> getValue(val, type)) .distinct() @@ -67,7 +65,7 @@ private DistributedList getSet(Collection values, Types type) { return DistributedList.uniform(collect); } - private Object getValue(Object value, Types type) { + private Object getValue(Object value, FieldType type) { if (type == null) { return value; } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/ConstraintReaderHelpers.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/ConstraintReaderHelpers.java index 846b45d43..f0db010b1 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/ConstraintReaderHelpers.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/ConstraintReaderHelpers.java @@ -16,8 +16,7 @@ package com.scottlogic.deg.profile.reader.atomic; -import com.scottlogic.deg.common.ValidationException; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.common.profile.constraintdetail.DateTimeGranularity; import com.scottlogic.deg.profile.reader.InvalidProfileException; @@ -63,7 +62,7 @@ public static OffsetDateTime parseDate(String value) { } } - public static Types getFieldType(String type) { + public static FieldType getFieldType(String type) { if (type == null) { return null; } @@ -71,7 +70,7 @@ public static Types getFieldType(String type) { switch (type) { case "decimal": case "integer": - return Types.NUMERIC; + return FieldType.NUMERIC; case "string": case "ISIN": @@ -81,10 +80,10 @@ public static Types getFieldType(String type) { case "firstname": case "lastname": case "fullname": - return Types.STRING; + return FieldType.STRING; case "datetime": - return Types.DATETIME; + return FieldType.DATETIME; } throw new InvalidProfileException("Profile is invalid: no type known for " + type); diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/ConstraintValueValidator.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/ConstraintValueValidator.java index 629b3ec0b..3149a5598 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/ConstraintValueValidator.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/ConstraintValueValidator.java @@ -3,7 +3,7 @@ import com.scottlogic.deg.common.ValidationException; import com.scottlogic.deg.common.profile.Field; import com.scottlogic.deg.common.profile.constraintdetail.NumericGranularityFactory; -import com.scottlogic.deg.common.profile.Types; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.common.util.Defaults; import com.scottlogic.deg.common.util.NumberUtils; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; @@ -16,7 +16,7 @@ import static com.scottlogic.deg.common.profile.constraintdetail.AtomicConstraintType.IS_GRANULAR_TO; import static com.scottlogic.deg.common.profile.constraintdetail.AtomicConstraintType.IS_NULL; -import static com.scottlogic.deg.common.profile.Types.*; +import static com.scottlogic.deg.common.profile.FieldType.*; import static com.scottlogic.deg.profile.reader.atomic.ConstraintReaderHelpers.getDateTimeGranularity; public class ConstraintValueValidator { @@ -82,7 +82,7 @@ private static void validateConstraintValue(Field field, AtomicConstraintType ty } } - private static void validateTypeIs(Field field, AtomicConstraintType type, Types s) { + private static void validateTypeIs(Field field, AtomicConstraintType type, FieldType s) { if (field.getType() == null){ throw new ValidationException("is not typed; add its type to the field definition"); } diff --git a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/RelationsFactory.java b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/RelationsFactory.java index 13e3e78df..552058fe8 100644 --- a/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/RelationsFactory.java +++ b/profile/src/main/java/com/scottlogic/deg/profile/reader/atomic/RelationsFactory.java @@ -2,8 +2,8 @@ import com.scottlogic.deg.common.ValidationException; import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.common.profile.ProfileFields; -import com.scottlogic.deg.common.profile.Types; import com.scottlogic.deg.common.profile.constraintdetail.AtomicConstraintType; import com.scottlogic.deg.common.profile.constraintdetail.Granularity; import com.scottlogic.deg.common.profile.constraintdetail.NumericGranularityFactory; @@ -54,7 +54,7 @@ public static FieldSpecRelations create(ConstraintDTO dto, ProfileFields fields) throw new ValidationException(dto.is + "cannot be used with OtherValue)"); } - private static Granularity getOffsetUnit(Types type, String offsetUnit) { + private static Granularity getOffsetUnit(FieldType type, String offsetUnit) { if (offsetUnit == null) { return null; } 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 65a04f5d3..e7dee5de5 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 @@ -17,8 +17,8 @@ package com.scottlogic.deg.profile.reader; import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.common.profile.ProfileFields; -import com.scottlogic.deg.common.profile.Types; import com.scottlogic.deg.common.profile.constraintdetail.AtomicConstraintType; import com.scottlogic.deg.generator.profile.constraints.Constraint; import com.scottlogic.deg.common.util.Defaults; @@ -40,7 +40,7 @@ import java.util.stream.Stream; import static com.scottlogic.deg.common.profile.FieldBuilder.createField; -import static com.scottlogic.deg.common.profile.Types.*; +import static com.scottlogic.deg.common.profile.FieldType.*; import static com.scottlogic.deg.common.profile.constraintdetail.AtomicConstraintType.*; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.core.IsEqual.equalTo; @@ -190,12 +190,12 @@ private static Stream stringLengthValidOperandProvider() { @DisplayName("Should return correct constraint type") @ParameterizedTest(name = "{0} should return {1}") @MethodSource("testProvider") - public void testAtomicConstraintReader(AtomicConstraintType type, ConstraintDTO dto, Class constraintType, Types types) { + public void testAtomicConstraintReader(AtomicConstraintType type, ConstraintDTO dto, Class constraintType, FieldType fieldType) { try { - Object value = new AtomicConstraintValueReader(null).getValue(dto, types); + Object value = new AtomicConstraintValueReader(null).getValue(dto, fieldType); - ConstraintValueValidator.validate(createField(dto.field, types), type, value); + ConstraintValueValidator.validate(createField(dto.field, fieldType), type, value); Constraint constraint = AtomicConstraintFactory.create(type, createField(dto.field), value); 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 61c25d90b..b9aeeae1e 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 @@ -18,11 +18,11 @@ import com.scottlogic.deg.common.profile.Field; +import com.scottlogic.deg.common.profile.FieldType; import com.scottlogic.deg.generator.fieldspecs.whitelist.DistributedList; import com.scottlogic.deg.generator.profile.Profile; import com.scottlogic.deg.generator.profile.Rule; import com.scottlogic.deg.generator.profile.constraints.Constraint; -import com.scottlogic.deg.common.profile.Types; import com.scottlogic.deg.generator.profile.constraints.grammatical.AndConstraint; import com.scottlogic.deg.generator.profile.constraints.grammatical.ConditionalConstraint; import com.scottlogic.deg.generator.profile.constraints.grammatical.OrConstraint; @@ -188,7 +188,7 @@ public void shouldGiveDefaultNameToUnnamedRules() throws IOException { expectFields( field -> { Assert.assertThat(field.name, equalTo("foo")); - Assert.assertEquals(field.getType(), Types.STRING); + Assert.assertEquals(field.getType(), FieldType.STRING); }); } @@ -265,7 +265,7 @@ public void shouldDeserialiseIsOfTypeConstraint() throws IOException { expectFields( field -> { Assert.assertThat(field.name, equalTo("foo")); - Assert.assertEquals(field.getType(), Types.STRING); + Assert.assertEquals(field.getType(), FieldType.STRING); }); } @@ -1053,10 +1053,10 @@ public void type_setsFieldTypeProperty_whenSetInFieldDefinition() throws IOExcep expectFields( field -> { - Assert.assertThat(field.getType(), equalTo(Types.NUMERIC)); + Assert.assertThat(field.getType(), equalTo(FieldType.NUMERIC)); }, field -> { - Assert.assertThat(field.getType(), equalTo(Types.STRING)); + Assert.assertThat(field.getType(), equalTo(FieldType.STRING)); } ); expectRules(); @@ -1151,7 +1151,7 @@ void parser_createsInternalField_whenProfileHasANestedInMapConstraint() throws I field -> { Assert.assertEquals("foobar.csv", field.name); Assert.assertTrue(field.isInternal()); - Assert.assertEquals(Types.NUMERIC, field.getType()); + Assert.assertEquals(FieldType.NUMERIC, field.getType()); } ); }