This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1435 from finos/1340-fix-relations-with-null-beha…
…viour fix(#1340): Fix null behaviour with relational constraints
- Loading branch information
Showing
7 changed files
with
261 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...rc/test/java/com/scottlogic/deg/generator/fieldspecs/relations/AfterDateRelationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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.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.constraintdetail.Granularity; | ||
import com.scottlogic.deg.generator.fieldspecs.FieldSpec; | ||
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.scottlogic.deg.common.util.Defaults.ISO_MAX_DATE; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
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); | ||
|
||
@Test | ||
public void testReduceToFieldSpec_withNotNull_reducesToSpec() { | ||
FieldSpecRelations afterDateRelations = new AfterDateRelation(a, b, true); | ||
OffsetDateTime value = OffsetDateTime.of(2000, | ||
1, | ||
1, | ||
0, | ||
0, | ||
0, | ||
0, | ||
ZoneOffset.UTC); | ||
DataBagValue generatedValue = new DataBagValue(value); | ||
|
||
FieldSpec result = afterDateRelations.reduceValueToFieldSpec(generatedValue); | ||
|
||
FieldSpec expected = FieldSpec.fromRestriction(new LinearRestrictions<>(value, ISO_MAX_DATE, new DateTimeGranularity(ChronoUnit.MILLIS))); | ||
assertEquals(expected, result); | ||
} | ||
|
||
@Test | ||
public void testReduceToFieldSpec_withNotNullExclusive_reducesToSpec() { | ||
FieldSpecRelations afterDateRelations = new AfterDateRelation(a, b, false); | ||
OffsetDateTime value = OffsetDateTime.of(2000, | ||
1, | ||
1, | ||
0, | ||
0, | ||
0, | ||
0, | ||
ZoneOffset.UTC); | ||
DataBagValue generatedValue = new DataBagValue(value); | ||
|
||
FieldSpec result = afterDateRelations.reduceValueToFieldSpec(generatedValue); | ||
|
||
Granularity<OffsetDateTime> granularity = new DateTimeGranularity(ChronoUnit.MILLIS); | ||
FieldSpec expected = FieldSpec.fromRestriction(new LinearRestrictions<>(granularity.getNext(value), ISO_MAX_DATE, new DateTimeGranularity(ChronoUnit.MILLIS))); | ||
assertEquals(expected, result); | ||
} | ||
|
||
@Test | ||
public void testReduceToFieldSpec_withNull_reducesToSpec() { | ||
FieldSpecRelations afterDateRelations = new AfterDateRelation(a, b, true); | ||
OffsetDateTime value = null; | ||
DataBagValue generatedValue = new DataBagValue(value); | ||
|
||
FieldSpec result = afterDateRelations.reduceValueToFieldSpec(generatedValue); | ||
|
||
FieldSpec expected = FieldSpec.empty(); | ||
assertEquals(expected, result); | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
...c/test/java/com/scottlogic/deg/generator/fieldspecs/relations/BeforeDateRelationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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.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.constraintdetail.Granularity; | ||
import com.scottlogic.deg.generator.fieldspecs.FieldSpec; | ||
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.scottlogic.deg.common.util.Defaults.ISO_MIN_DATE; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
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); | ||
|
||
@Test | ||
public void testReduceToFieldSpec_withNotNull_reducesToSpec() { | ||
FieldSpecRelations beforeDateRelations = new BeforeDateRelation(a, b, true); | ||
OffsetDateTime value = OffsetDateTime.of(2000, | ||
1, | ||
1, | ||
0, | ||
0, | ||
0, | ||
0, | ||
ZoneOffset.UTC); | ||
DataBagValue generatedValue = new DataBagValue(value); | ||
|
||
FieldSpec result = beforeDateRelations.reduceValueToFieldSpec(generatedValue); | ||
|
||
FieldSpec expected = FieldSpec.fromRestriction(new LinearRestrictions<>(ISO_MIN_DATE, value, new DateTimeGranularity(ChronoUnit.MILLIS))); | ||
assertEquals(expected, result); | ||
} | ||
|
||
@Test | ||
public void testReduceToFieldSpec_withNotNullExclusive_reducesToSpec() { | ||
FieldSpecRelations beforeDateRelations = new BeforeDateRelation(a, b, false); | ||
OffsetDateTime value = OffsetDateTime.of(2000, | ||
1, | ||
1, | ||
0, | ||
0, | ||
0, | ||
0, | ||
ZoneOffset.UTC); | ||
DataBagValue generatedValue = new DataBagValue(value); | ||
|
||
FieldSpec result = beforeDateRelations.reduceValueToFieldSpec(generatedValue); | ||
|
||
Granularity<OffsetDateTime> granularity = new DateTimeGranularity(ChronoUnit.MILLIS); | ||
FieldSpec expected = FieldSpec.fromRestriction(new LinearRestrictions<>(ISO_MIN_DATE, granularity.getPrevious(value), new DateTimeGranularity(ChronoUnit.MILLIS))); | ||
assertEquals(expected, result); | ||
} | ||
|
||
@Test | ||
public void testReduceToFieldSpec_withNull_reducesToSpec() { | ||
FieldSpecRelations beforeDateRelations = new BeforeDateRelation(a, b, true); | ||
OffsetDateTime value = null; | ||
DataBagValue generatedValue = new DataBagValue(value); | ||
|
||
FieldSpec result = beforeDateRelations.reduceValueToFieldSpec(generatedValue); | ||
|
||
FieldSpec expected = FieldSpec.empty(); | ||
assertEquals(expected, result); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
.../test/java/com/scottlogic/deg/generator/fieldspecs/relations/EqualToDateRelationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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.generator.fieldspecs.FieldSpec; | ||
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 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 FieldSpecRelations equalToDateRelations = new EqualToDateRelation(a, b); | ||
|
||
@Test | ||
public void testReduceToFieldSpec_withNotNull_reducesToSpec() { | ||
OffsetDateTime value = OffsetDateTime.of(2000, | ||
1, | ||
1, | ||
0, | ||
0, | ||
0, | ||
0, | ||
ZoneOffset.UTC); | ||
DataBagValue generatedValue = new DataBagValue(value); | ||
|
||
FieldSpec result = equalToDateRelations.reduceValueToFieldSpec(generatedValue); | ||
|
||
FieldSpec expected = FieldSpec.fromRestriction(new LinearRestrictions<>(value, value, new DateTimeGranularity(ChronoUnit.MILLIS))); | ||
assertEquals(expected, result); | ||
} | ||
|
||
@Test | ||
public void testReduceToFieldSpec_withNull_reducesToSpec() { | ||
OffsetDateTime value = null; | ||
DataBagValue generatedValue = new DataBagValue(value); | ||
|
||
FieldSpec result = equalToDateRelations.reduceValueToFieldSpec(generatedValue); | ||
|
||
FieldSpec expected = FieldSpec.empty(); | ||
assertEquals(expected, result); | ||
} | ||
|
||
} |