From 5bffcddef805973793ac64e34965631994e297dc Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Tue, 10 Dec 2024 16:00:56 +0100 Subject: [PATCH 1/6] Clear caches if validator instance changes --- .../extensions/functions/BaseInterlisFunction.java | 11 +++++++++++ .../extensions/functions/FilterIoxPlugin.java | 5 +++++ .../extensions/functions/FindObjectsIoxPlugin.java | 5 +++++ .../extensions/functions/GetInGroupsIoxPlugin.java | 5 +++++ .../functions/IsInsideExternalXtfIoxPlugin.java | 5 +++++ .../IsInsideExternalXtfResourceIoxPlugin.java | 5 +++++ .../extensions/functions/IsInsideIoxPlugin.java | 5 +++++ .../functions/PolylinesOverlapIoxPlugin.java | 5 +++++ .../extensions/functions/UnionIoxPlugin.java | 5 +++++ 9 files changed, 51 insertions(+) diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/BaseInterlisFunction.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/BaseInterlisFunction.java index 8f90f01..dae18d9 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/BaseInterlisFunction.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/BaseInterlisFunction.java @@ -11,6 +11,7 @@ import ch.interlis.iox_j.validator.Value; public abstract class BaseInterlisFunction implements InterlisFunction { + private static Validator lastValidator = null; protected LogEventFactory logger; protected TransferDescription td; @@ -26,6 +27,11 @@ public final void init(TransferDescription td, Settings settings, IoxValidationC this.settings = settings; this.validator = (Validator) settings.getTransientObject(IOX_VALIDATOR); this.objectPool = objectPool; + + if (lastValidator != this.validator) { + resetCaches(); + lastValidator = this.validator; + } } @Override @@ -43,4 +49,9 @@ public final Value evaluate(String validationKind, String usageScope, IomObject } protected abstract Value evaluateInternal(String validationKind, String usageScope, IomObject mainObj, Value[] actualArguments); + + /** + * A change was detected that requires the caches to be reset. + */ + protected void resetCaches() { } } diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPlugin.java index e9a0dbe..c1737a1 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPlugin.java @@ -19,6 +19,11 @@ public String getQualifiedIliName() { return "GeoW_FunctionsExt.Filter"; } + @Override + protected void resetCaches() { + EXPRESSION_CACHE.clear(); + } + @Override protected Value evaluateInternal(String validationKind, String usageScope, IomObject contextObject, Value[] arguments) { Value argObjects = arguments[0]; diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/FindObjectsIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/FindObjectsIoxPlugin.java index 30bed55..4cf9aae 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/FindObjectsIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/FindObjectsIoxPlugin.java @@ -24,6 +24,11 @@ public String getQualifiedIliName() { return "GeoW_FunctionsExt.FindObjects"; } + @Override + protected void resetCaches() { + OBJECTS_CACHE.clear(); + } + @Override protected Value evaluateInternal(String validationKind, String usageScope, IomObject contextObject, Value[] arguments) { Value argObjectClass = arguments[0]; diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPlugin.java index 7be4cfa..c21e96e 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPlugin.java @@ -16,6 +16,11 @@ public String getQualifiedIliName() { return "GeoW_FunctionsExt.GetInGroups"; } + @Override + protected void resetCaches() { + groups.clear(); + } + @Override public Value evaluateInternal(String validationKind, String usageScope, IomObject contextObject, Value[] arguments) { Value argObjects = arguments[0]; diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfIoxPlugin.java index 8ae2356..310c340 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfIoxPlugin.java @@ -34,6 +34,11 @@ public String getQualifiedIliName() { return QUALIFIED_ILI_NAME; } + @Override + protected void resetCaches() { + VALID_AREA_CACHE.clear(); + } + @Override protected Value evaluateInternal(String validationKind, String usageScope, IomObject mainObj, Value[] arguments) { Value argDatasetName = arguments[0]; // TEXT diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfResourceIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfResourceIoxPlugin.java index bfc8a09..0bbd319 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfResourceIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfResourceIoxPlugin.java @@ -22,6 +22,11 @@ public String getQualifiedIliName() { return QUALIFIED_ILI_NAME; } + @Override + protected void resetCaches() { + VALID_AREA_CACHE.clear(); + } + @Override protected Value evaluateInternal(String validationKind, String usageScope, IomObject mainObj, Value[] arguments) { Value argTransferFile = arguments[0]; // TEXT diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideIoxPlugin.java index b4030b3..b5ba682 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideIoxPlugin.java @@ -20,6 +20,11 @@ public String getQualifiedIliName() { return QUALIFIED_ILI_NAME; } + @Override + protected void resetCaches() { + VALID_AREA_CACHE.clear(); + } + @Override protected Value evaluateInternal(String validationKind, String usageScope, IomObject mainObj, Value[] arguments) { Value argReferenceObject = arguments[0]; // ANYSTRUCTURE diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPlugin.java index 84a0eb8..370cb52 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPlugin.java @@ -24,6 +24,11 @@ public String getQualifiedIliName() { return "GeoW_FunctionsExt.PolylinesOverlap"; } + @Override + protected void resetCaches() { + HAS_EQUAL_LINE_PART_CACHE.clear(); + } + @Override protected Value evaluateInternal(String validationKind, String usageScope, IomObject contextObject, Value[] arguments) { Value argObjects = arguments[0]; diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java index e3f955e..59a23c4 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java @@ -27,6 +27,11 @@ public String getQualifiedIliName() { return "GeoW_FunctionsExt.Union"; } + @Override + protected void resetCaches() { + UNION_SURFACE_CACHE.clear(); + } + @Override protected Value evaluateInternal(String validationKind, String usageScope, IomObject contextObject, Value[] actualArguments) { Value argObjects = actualArguments[0]; From 71b0148786be8c70839031f0e3ffe4d32dbf1fa7 Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Wed, 11 Dec 2024 11:20:59 +0100 Subject: [PATCH 2/6] Remove use of com.vividsolutions.jts.util.Assert We are testing with junit, vividsolutions.jts is obsolete --- .../extensions/functions/AssertionHelper.java | 8 ++++---- .../functions/FilterIoxPluginTest.java | 7 ++++--- .../functions/FindObjectsIoxPluginTest.java | 5 +++-- .../functions/GetAreaIoxPluginTest.java | 15 ++++++++------- .../functions/GetInGroupsIoxPluginTest.java | 7 ++++--- .../GetInnerringsCountIoxPluginTest.java | 5 +++-- .../functions/GetLengthIoxPluginTest.java | 15 ++++++++------- .../functions/InterlisExpressionParserTest.java | 16 +++++++++------- .../IsInsideExternalXtfIoxPluginTest.java | 7 ++++--- ...IsInsideExternalXtfResourceIoxPluginTest.java | 5 +++-- .../functions/IsInsideIoxPluginTest.java | 5 +++-- .../functions/PolylinesOverlapIoxPluginTest.java | 7 ++++--- .../extensions/functions/UnionIoxPluginTest.java | 9 +++++---- 13 files changed, 62 insertions(+), 49 deletions(-) diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/AssertionHelper.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/AssertionHelper.java index 2ade885..ec44068 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/AssertionHelper.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/AssertionHelper.java @@ -1,11 +1,11 @@ package ch.geowerkstatt.ilivalidator.extensions.functions; import ch.interlis.iox.IoxLogEvent; -import com.vividsolutions.jts.util.Assert; import java.util.List; import java.util.regex.Pattern; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; public final class AssertionHelper { @@ -22,7 +22,7 @@ public static void assertConstraintErrors(ValidationTestHelper vh, int expectedC } } - Assert.equals(expectedCount, errorsFound, + assertEquals(expectedCount, errorsFound, String.format("Expected %d but found %d errors with OID <%s> and Source <%s>.", expectedCount, errorsFound, oid, constraintName)); } @@ -38,7 +38,7 @@ public static void assertConstraintErrors(ValidationTestHelper vh, int expectedC } } - Assert.equals(expectedCount, errorsFound, + assertEquals(expectedCount, errorsFound, String.format("Expected %s errors with Source <%s> but found %d.", expectedCount, constraintName, errorsFound)); } @@ -50,7 +50,7 @@ public static void assertNoConstraintError(ValidationTestHelper vh, String const } } - Assert.equals(0, errorsFound, + assertEquals(0, errorsFound, String.format("Expected No errors with Source <%s> but found %d.", constraintName, errorsFound)); } diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPluginTest.java index 498015d..3e17fee 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPluginTest.java @@ -2,11 +2,12 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + class FilterIoxPluginTest { protected static final String TEST_DATA = "Filter/TestData.xtf"; private ValidationTestHelper vh; @@ -20,7 +21,7 @@ public void setUp() { @Test public void mandatoryConstraint() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"Filter/MandatoryConstraints.ili"}); - Assert.equals(2, vh.getErrs().size()); + assertEquals(2, vh.getErrs().size()); AssertionHelper.assertNoConstraintError(vh, "trueConstraintEnumAttr"); AssertionHelper.assertNoConstraintError(vh, "trueConstraintNumberAttr"); AssertionHelper.assertConstraintErrors(vh, 1, "base", "falseConstraintEnumAttr"); @@ -31,7 +32,7 @@ public void mandatoryConstraint() throws Ili2cFailure, IoxException { @Disabled("Escape sequences in strings (https://github.com/claeis/ili2c/issues/124)") public void filterTextAttr() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"Filter/MandatoryConstraintsText.ili"}); - Assert.equals(1, vh.getErrs().size()); + assertEquals(1, vh.getErrs().size()); AssertionHelper.assertNoConstraintError(vh, "trueConstraintTextAttr"); AssertionHelper.assertConstraintErrors(vh, 1, "base", "falseConstraintTextAttr"); } diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FindObjectsIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FindObjectsIoxPluginTest.java index 07035ca..72154d6 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FindObjectsIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FindObjectsIoxPluginTest.java @@ -2,10 +2,11 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + class FindObjectsIoxPluginTest { protected static final String TEST_DATA = "FindObjects/TestData.xtf"; private ValidationTestHelper vh = null; @@ -19,7 +20,7 @@ void setUp() { @Test void mandatoryConstraint() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"FindObjects/MandatoryConstraints.ili"}); - Assert.equals(3, vh.getErrs().size()); + assertEquals(3, vh.getErrs().size()); AssertionHelper.assertNoConstraintError(vh, "trueConstraintTextAttr"); AssertionHelper.assertNoConstraintError(vh, "trueConstraintEnumAttr"); AssertionHelper.assertNoConstraintError(vh, "trueConstraintNumberAttr"); diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetAreaIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetAreaIoxPluginTest.java index 369c2ac..11bfe33 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetAreaIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetAreaIoxPluginTest.java @@ -2,11 +2,12 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + class GetAreaIoxPluginTest { protected static final String TEST_DATA = "GetArea/TestData.xtf"; @@ -21,7 +22,7 @@ void setUp() { @Test void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"GetArea/MandatoryConstraintThis.ili"}); - Assert.equals(4, vh.getErrs().size()); + assertEquals(4, vh.getErrs().size()); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint1"); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint2"); AssertionHelper.assertSingleConstraintError(vh, 3, "Constraint3"); @@ -31,7 +32,7 @@ void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException { @Test void setConstraintOnAll() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"GetArea/SetConstraintAll.ili"}); - Assert.equals(3, vh.getErrs().size()); + assertEquals(3, vh.getErrs().size()); AssertionHelper.assertNoConstraintError(vh, "Constraint1"); AssertionHelper.assertNoConstraintError(vh, "Constraint2"); AssertionHelper.assertConstraintErrors(vh, 1, "Constraint3"); @@ -42,7 +43,7 @@ void setConstraintOnAll() throws Ili2cFailure, IoxException { @Test void setConstraintOnThis() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"GetArea/SetConstraintThis.ili"}); - Assert.equals(2, vh.getErrs().size()); + assertEquals(2, vh.getErrs().size()); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint2"); AssertionHelper.assertSingleConstraintError(vh, 3, "Constraint3"); } @@ -51,7 +52,7 @@ void setConstraintOnThis() throws Ili2cFailure, IoxException { @Disabled("XTF24Reader fails on reading Bag Of Struct") void setConstraintOnThisWithBagOfStruct() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{"GetArea/TestDataBagOf.xtf"}, new String[]{"GetArea/SetConstraintBagOf.ili"}); - Assert.equals(1, vh.getErrs().size()); + assertEquals(1, vh.getErrs().size()); AssertionHelper.assertNoConstraintError(vh, "Constraint1"); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint2"); AssertionHelper.assertNoConstraintError(vh, "Constraint3"); @@ -75,7 +76,7 @@ void setConstraintOnAssociationOne2Many() throws Ili2cFailure, IoxException { AssertionHelper.assertNoConstraintError(vh, "Constraint5"); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint6"); - Assert.equals(7, vh.getErrs().size()); + assertEquals(7, vh.getErrs().size()); } @Test @@ -100,6 +101,6 @@ void setConstraintOnAssociationMany2Many() throws Ili2cFailure, IoxException { AssertionHelper.assertNoConstraintError(vh, "Constraint6"); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint7"); AssertionHelper.assertNoConstraintError(vh, "Constraint8"); - Assert.equals(11, vh.getErrs().size()); + assertEquals(11, vh.getErrs().size()); } } diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPluginTest.java index 5ac50df..c13a10a 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPluginTest.java @@ -2,10 +2,11 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + class GetInGroupsIoxPluginTest { protected static final String TEST_DATA = "GetInGroups/TestData.xtf"; @@ -21,7 +22,7 @@ void setUp() { @Test void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"GetInGroups/SetConstraintAll.ili"}); - Assert.equals(3, vh.getErrs().size()); + assertEquals(3, vh.getErrs().size()); AssertionHelper.assertNoConstraintError(vh, "trueConstraintTextAttr"); AssertionHelper.assertNoConstraintError(vh, "trueConstraintEnumAttr"); AssertionHelper.assertNoConstraintError(vh, "trueConstraintNumberAttr"); @@ -33,7 +34,7 @@ void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException { @Test void emptySet() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA_EMPTY}, new String[]{"GetInGroups/SetConstraintEmpty.ili"}); - Assert.equals(1, vh.getErrs().size()); + assertEquals(1, vh.getErrs().size()); AssertionHelper.assertNoConstraintError(vh, "trueConstraintTextAttr"); AssertionHelper.assertConstraintErrors(vh, 1, "falseConstraintTextAttr"); } diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInnerringsCountIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInnerringsCountIoxPluginTest.java index 6e3a7f5..800bafb 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInnerringsCountIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInnerringsCountIoxPluginTest.java @@ -2,10 +2,11 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + class GetInnerringsCountIoxPluginTest { protected static final String TEST_DATA = "GetInnerRingsCount/TestData.xtf"; @@ -20,7 +21,7 @@ void setUp() { @Test void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"GetInnerRingsCount/MandatoryConstraintThis.ili"}); - Assert.equals(5, vh.getErrs().size()); + assertEquals(5, vh.getErrs().size()); AssertionHelper.assertConstraintErrors(vh, 1, "1", "AreaInnerRingCount"); AssertionHelper.assertConstraintErrors(vh, 1, "1", "SurfaceInnerRingCount"); diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetLengthIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetLengthIoxPluginTest.java index abe8f0a..71a35ca 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetLengthIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetLengthIoxPluginTest.java @@ -2,11 +2,12 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + class GetLengthIoxPluginTest { protected static final String TEST_DATA = "GetLength/TestData.xtf"; @@ -21,7 +22,7 @@ void setUp() { @Test void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"GetLength/MandatoryConstraintThis.ili"}); - Assert.equals(4, vh.getErrs().size()); + assertEquals(4, vh.getErrs().size()); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint1"); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint2"); AssertionHelper.assertSingleConstraintError(vh, 3, "Constraint3"); @@ -31,7 +32,7 @@ void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException { @Test void setConstraintOnAll() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"GetLength/SetConstraintAll.ili"}); - Assert.equals(3, vh.getErrs().size()); + assertEquals(3, vh.getErrs().size()); AssertionHelper.assertNoConstraintError(vh, "Constraint1"); AssertionHelper.assertNoConstraintError(vh, "Constraint2"); AssertionHelper.assertConstraintErrors(vh, 1, "Constraint3"); @@ -42,7 +43,7 @@ void setConstraintOnAll() throws Ili2cFailure, IoxException { @Test void setConstraintOnThis() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"GetLength/SetConstraintThis.ili"}); - Assert.equals(2, vh.getErrs().size()); + assertEquals(2, vh.getErrs().size()); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint2"); AssertionHelper.assertSingleConstraintError(vh, 3, "Constraint3"); } @@ -51,7 +52,7 @@ void setConstraintOnThis() throws Ili2cFailure, IoxException { @Disabled("XTF24Reader fails on reading Bag Of Struct") void setConstraintOnThisWithBagOfStruct() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{"GetLength/TestDataBagOf.xtf"}, new String[]{"GetLength/SetConstraintBagOf.ili"}); - Assert.equals(1, vh.getErrs().size()); + assertEquals(1, vh.getErrs().size()); AssertionHelper.assertNoConstraintError(vh, "Constraint1"); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint2"); AssertionHelper.assertNoConstraintError(vh, "Constraint3"); @@ -75,7 +76,7 @@ void setConstraintOnAssociationOne2Many() throws Ili2cFailure, IoxException { AssertionHelper.assertNoConstraintError(vh, "Constraint5"); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint6"); - Assert.equals(7, vh.getErrs().size()); + assertEquals(7, vh.getErrs().size()); } @Test @@ -100,6 +101,6 @@ void setConstraintOnAssociationMany2Many() throws Ili2cFailure, IoxException { AssertionHelper.assertNoConstraintError(vh, "Constraint6"); AssertionHelper.assertSingleConstraintError(vh, 0, "Constraint7"); AssertionHelper.assertNoConstraintError(vh, "Constraint8"); - Assert.equals(11, vh.getErrs().size()); + assertEquals(11, vh.getErrs().size()); } } diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/InterlisExpressionParserTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/InterlisExpressionParserTest.java index b608b72..73238f3 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/InterlisExpressionParserTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/InterlisExpressionParserTest.java @@ -14,12 +14,14 @@ import ch.interlis.iox_j.validator.ValidationConfig; import ch.interlis.iox_j.validator.Validator; import ch.interlis.iox_j.validator.Value; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.ArrayList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + class InterlisExpressionParserTest { private static final String ILI_FILE = "src/test/data/ExpressionParser/ExpressionParser.ili"; private static final String CLASS_NAME = "TestSuite.FunctionTestTopic.TestClass"; @@ -44,13 +46,13 @@ public void parseWhereExpressionTrueResult() { InterlisExpressionParser parser = InterlisExpressionParser.createParser(td, "WHERE THIS->enumAttr == #a;"); Evaluable evaluable = parser.parseWhereExpression(viewable); - Assert.equals(Expression.Equality.class, evaluable.getClass()); + assertEquals(Expression.Equality.class, evaluable.getClass()); IomObject iomObject = createIomObject("1", "a"); Value value = validator.evaluateExpression(null, "test", "test", iomObject, evaluable, null); - Assert.equals(0, logCollector.getErrs().size()); - Assert.isTrue(value.isTrue()); + assertEquals(0, logCollector.getErrs().size()); + assertTrue(value.isTrue()); } @Test @@ -58,13 +60,13 @@ public void parseWhereExpressionFalseResult() { InterlisExpressionParser parser = InterlisExpressionParser.createParser(td, "WHERE enumAttr != #c;"); Evaluable evaluable = parser.parseWhereExpression(viewable); - Assert.equals(Expression.Inequality.class, evaluable.getClass()); + assertEquals(Expression.Inequality.class, evaluable.getClass()); IomObject iomObject = createIomObject("2", "c"); Value value = validator.evaluateExpression(null, "test", "test", iomObject, evaluable, null); - Assert.equals(0, logCollector.getErrs().size()); - Assert.equals(false, value.isTrue()); + assertEquals(0, logCollector.getErrs().size()); + assertEquals(false, value.isTrue()); } private static IomObject createIomObject(String oid, String enumAttrValue) { diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfIoxPluginTest.java index 9502f2d..c9908ab 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfIoxPluginTest.java @@ -2,13 +2,14 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.File; import java.lang.reflect.Field; +import static org.junit.jupiter.api.Assertions.assertEquals; + class IsInsideExternalXtfIoxPluginTest { private static final String TEST_DATA = "IsInsideExternalXtf/TestData.xtf"; ValidationTestHelper vh; @@ -29,7 +30,7 @@ void setUp() throws NoSuchFieldException, IllegalAccessException { void isInsideExternalXtf() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"IsInsideExternalXtf/MandatoryConstraintThis.ili"}); - Assert.equals(6, vh.getErrs().size()); + assertEquals(6, vh.getErrs().size()); AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.MalformedDatasetName: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalXtf. Expected qualified attribute name but got ."); AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentDatasetName: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalXtf. Could not find Transferfile containing model ."); AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentTransferIds: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalXtf. Could not find objects with TID <100000000, 9999> in transfer file"); @@ -37,7 +38,7 @@ void isInsideExternalXtf() throws Ili2cFailure, IoxException { AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "Mandatory Constraint TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentDatasetName is not true."); AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "Mandatory Constraint TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentTransferIds is not true."); - Assert.equals(1, vh.getWarn().size()); + assertEquals(1, vh.getWarn().size()); // Interlis 2.4 XTF files do not work. AssertionHelper.assertLogEventsContainMessage(vh.getWarn(), "GeoW_FunctionsExt.IsInsideExternalXtf: Error while reading xtf file \\S*TestData.xtf. Expected TRANSFER, but transfer found."); } diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfResourceIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfResourceIoxPluginTest.java index a20498c..a1fb6c9 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfResourceIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideExternalXtfResourceIoxPluginTest.java @@ -2,10 +2,11 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public final class IsInsideExternalXtfResourceIoxPluginTest { private static final String TEST_DATA = "IsInsideExternalXtfResource/TestData.xtf"; private ValidationTestHelper vh; @@ -20,7 +21,7 @@ void setUp() { void isInsideExternalXtfResource() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"IsInsideExternalXtfResource/MandatoryConstraintThis.ili"}); - Assert.equals(6, vh.getErrs().size()); + assertEquals(6, vh.getErrs().size()); AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.MalformedDatasetName: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalXtfResource. Expected qualified attribute name but got ."); AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentTransferFile: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalXtfResource. Could not find Transferfile in resources."); AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.NonExistentTransferIds: Unable to evaluate GeoW_FunctionsExt.IsInsideExternalXtfResource. Could not find objects with TID <100000000, 9999> in transfer file"); diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideIoxPluginTest.java index d7dd1b9..75fbdbd 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/IsInsideIoxPluginTest.java @@ -2,10 +2,11 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public final class IsInsideIoxPluginTest { private static final String TEST_DATA = "IsInside/TestData.xtf"; private ValidationTestHelper vh; @@ -20,7 +21,7 @@ void setUp() { void isInside() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"IsInside/MandatoryConstraintThis.ili"}); - Assert.equals(2, vh.getErrs().size()); + assertEquals(2, vh.getErrs().size()); AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "TestSuite.FunctionTestTopic.InvalidConstraints.IsInsideMissingArea: Unable to evaluate GeoW_FunctionsExt.IsInside. Missing reference geometry."); AssertionHelper.assertLogEventsContainMessage(vh.getErrs(), "Mandatory Constraint TestSuite.FunctionTestTopic.InvalidConstraints.IsInsideMissingArea is not true."); } diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java index f6ee501..920c1fc 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java @@ -2,10 +2,11 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public final class PolylinesOverlapIoxPluginTest { private static final String TEST_DATA = "PolylinesOverlap/TestData.xtf"; private static final String TEST_DATA_SAME_LINE = "PolylinesOverlap/TestDataSameLine.xtf"; @@ -20,7 +21,7 @@ void setUp() { @Test void polylinesOverlap() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"PolylinesOverlap/PolylinesOverlap.ili"}); - Assert.equals(4, vh.getErrs().size()); + assertEquals(4, vh.getErrs().size()); AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintAllNoOverlaps"); AssertionHelper.assertNoConstraintError(vh, "setConstraintT1"); // Some lines in T1 overlap AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintT2"); @@ -32,7 +33,7 @@ void polylinesOverlap() throws Ili2cFailure, IoxException { @Test void sameLineOverlaps() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA_SAME_LINE}, new String[]{"PolylinesOverlap/PolylinesOverlap.ili"}); - Assert.equals(4, vh.getErrs().size()); + assertEquals(4, vh.getErrs().size()); AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintAllNoOverlaps"); AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintT1"); AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintT2"); diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPluginTest.java index ef155e6..5847351 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPluginTest.java @@ -2,10 +2,11 @@ import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; -import com.vividsolutions.jts.util.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + public final class UnionIoxPluginTest { private static final String TEST_DATA = "Union/TestData.xtf"; private static final String TEST_DATA_MERGED_INNER_RINGS = "Union/TestDataMergedInnerRings.xtf"; @@ -21,7 +22,7 @@ void setUp() { @Test void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA}, new String[]{"Union/MandatoryConstraintThis.ili"}); - Assert.equals(3, vh.getErrs().size()); + assertEquals(3, vh.getErrs().size()); AssertionHelper.assertConstraintErrors(vh, 2, "falseConstraint"); AssertionHelper.assertConstraintErrors(vh, 0, "0", "oneInnerRingConstraint"); AssertionHelper.assertConstraintErrors(vh, 1, "1", "oneInnerRingConstraint"); @@ -30,7 +31,7 @@ void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException { @Test void mandatoryConstraintMergedInnerRings() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA_MERGED_INNER_RINGS}, new String[]{"Union/MandatoryConstraintMergedInnerRings.ili"}); - Assert.equals(0, vh.getErrs().size()); + assertEquals(0, vh.getErrs().size()); AssertionHelper.assertNoConstraintError(vh, "innerRings"); AssertionHelper.assertNoConstraintError(vh, "innerRingsUnion"); } @@ -38,6 +39,6 @@ void mandatoryConstraintMergedInnerRings() throws Ili2cFailure, IoxException { @Test void test() throws Exception { vh.runValidation(new String[]{"Union/UnionTest.xtf"}, new String[]{"Union/UnionTest.ili"}); - Assert.equals(0, vh.getErrs().size()); + assertEquals(0, vh.getErrs().size()); } } From 21c72f89218bd1c3fe028729b7979fb86e1e7cfe Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Wed, 11 Dec 2024 11:47:25 +0100 Subject: [PATCH 3/6] Return empty collection if no objects --- .../extensions/functions/EvaluationHelper.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/EvaluationHelper.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/EvaluationHelper.java index ee73ffc..142b14d 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/EvaluationHelper.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/EvaluationHelper.java @@ -11,10 +11,7 @@ import ch.interlis.iox_j.validator.Validator; import ch.interlis.iox_j.validator.Value; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.Set; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -48,6 +45,8 @@ public static PathEl[] getAttributePathEl(Validator validator, Viewable /** * Get the {@link Viewable} (e.g. the class definition) from the {@link TransferDescription}. * If the {@code iomObject} is {@code null}, the {@code argObjects} is used to retrieve the {@link Viewable}. + * + * @return the {@link Viewable} instance or {@code null} if no {@link Viewable} could be found. */ public static Viewable getContextClass(TransferDescription td, IomObject iomObject, Value argObjects) { if (iomObject != null) { @@ -122,12 +121,17 @@ public static Collection evaluateAttributes(Validator validator, Valu /** * Get the collection of {@link IomObject} inside {@code object} by following the provided {@code path} text. - * If the {@code path} is UNDEFINED, the direct collection of {@code object} is returned. + * If the {@code path} is {@link Value#isUndefined()}, the direct collection of {@code object} is returned. + * If {@code object} is empty, an empty collection is returned. */ public static Collection evaluateObjectPath(TransferDescription td, Validator validator, Value object, Value path, IomObject contextObject, String usageScope) { if (path.isUndefined()) { return object.getComplexObjects(); } else { + if (object.getComplexObjects().isEmpty()) { + return Collections.emptyList(); + } + Viewable contextClass = EvaluationHelper.getContextClass(td, contextObject, object); if (contextClass == null) { throw new IllegalStateException("unknown class in " + usageScope); From 428bbc5a69a5b30b92468b515a5c78ce905ddd22 Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Wed, 11 Dec 2024 11:48:41 +0100 Subject: [PATCH 4/6] Add PolylinesOverlap test --- .../functions/PolylinesOverlapIoxPlugin.java | 9 ++++ .../data/PolylinesOverlap/TestDataOnlyT2.xtf | 45 +++++++++++++++++++ .../PolylinesOverlapIoxPluginTest.java | 20 +++++++++ 3 files changed, 74 insertions(+) create mode 100644 src/test/data/PolylinesOverlap/TestDataOnlyT2.xtf diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPlugin.java index 370cb52..094b597 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPlugin.java @@ -55,6 +55,7 @@ protected Value evaluateInternal(String validationKind, String usageScope, IomOb HasEqualLinePartKey key = new HasEqualLinePartKey(objectIds, argPath.isUndefined() ? null : argPath.getValue()); boolean hasOverlap = HAS_EQUAL_LINE_PART_CACHE.computeIfAbsent(key, k -> { + logger.addEvent(logger.logDetailInfoMsg("Calculating {0} for key {1}", getQualifiedIliName(), k.toString())); List lines = convertToJTSLines(polylineObjects); return hasEqualLinePart(lines); }); @@ -132,5 +133,13 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(objectIds, attributeName); } + + @Override + public String toString() { + return "HasEqualLinePartKey{" + + "objectIds=[" + String.join(", ", objectIds) + + "], attributeName='" + attributeName + '\'' + + '}'; + } } } diff --git a/src/test/data/PolylinesOverlap/TestDataOnlyT2.xtf b/src/test/data/PolylinesOverlap/TestDataOnlyT2.xtf new file mode 100644 index 0000000..5bac4e7 --- /dev/null +++ b/src/test/data/PolylinesOverlap/TestDataOnlyT2.xtf @@ -0,0 +1,45 @@ + + + + + TestSuite + + ili2gpkg-5.0.0-20f2bb62307ba6329a125fc6f10965ad9a4e6300 + + + + + + + + 2645543.027 + 1249774.761 + + + 2645564.119 + 1249788.217 + + + + t2 + + + + + + 2645543.027 + 1249774.761 + + + 2645564.119 + 1249788.217 + + + + t2 + + + + diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java index 920c1fc..e5dd9ce 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java @@ -1,7 +1,9 @@ package ch.geowerkstatt.ilivalidator.extensions.functions; +import ch.ehi.basics.logging.EhiLogger; import ch.interlis.ili2c.Ili2cFailure; import ch.interlis.iox.IoxException; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,8 +12,14 @@ public final class PolylinesOverlapIoxPluginTest { private static final String TEST_DATA = "PolylinesOverlap/TestData.xtf"; private static final String TEST_DATA_SAME_LINE = "PolylinesOverlap/TestDataSameLine.xtf"; + private static final String TEST_DATA_ONLY_T2 = "PolylinesOverlap/TestDataOnlyT2.xtf"; private ValidationTestHelper vh = null; + @BeforeAll + static void init() { + EhiLogger.getInstance().setTraceFilter(false); + } + @BeforeEach void setUp() { vh = new ValidationTestHelper(); @@ -41,4 +49,16 @@ void sameLineOverlaps() throws Ili2cFailure, IoxException { AssertionHelper.assertNoConstraintError(vh, "setConstraintT1or2"); // One line in T1 is a segment of T2 AssertionHelper.assertNoConstraintError(vh, "setConstraintT2or3"); // The lines in T2 and T3 are equal } + + @Test + void setConstraintEverythingFilteredOut() throws Ili2cFailure, IoxException { + vh.runValidation(new String[]{TEST_DATA_ONLY_T2}, new String[]{"PolylinesOverlap/PolylinesOverlap.ili"}); + assertEquals(3, vh.getErrs().size()); + AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintAllNoOverlaps"); + AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintT1"); + AssertionHelper.assertNoConstraintError(vh, "setConstraintT2"); + AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintT3"); + AssertionHelper.assertNoConstraintError(vh, "setConstraintT1or2"); // One line in T1 is a segment of T2 + AssertionHelper.assertNoConstraintError(vh, "setConstraintT2or3"); // The lines in T2 and T3 are equal + } } From e2d92f49bd6de745c1249874500bae904be88590 Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Wed, 11 Dec 2024 11:49:50 +0100 Subject: [PATCH 5/6] Add GetInGroups test --- .../SetConstraintWhereCondition.ili | 18 +++++++++++++++ src/test/data/GetInGroups/TestDataOnlyT2.xtf | 23 +++++++++++++++++++ .../functions/GetInGroupsIoxPluginTest.java | 9 ++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/test/data/GetInGroups/SetConstraintWhereCondition.ili create mode 100644 src/test/data/GetInGroups/TestDataOnlyT2.xtf diff --git a/src/test/data/GetInGroups/SetConstraintWhereCondition.ili b/src/test/data/GetInGroups/SetConstraintWhereCondition.ili new file mode 100644 index 0000000..16d380e --- /dev/null +++ b/src/test/data/GetInGroups/SetConstraintWhereCondition.ili @@ -0,0 +1,18 @@ +INTERLIS 2.4; + +MODEL TestSuite + AT "mailto:info@geowerkstatt.ch" VERSION "2024-01-09" = + IMPORTS GeoW_FunctionsExt; + + TOPIC FunctionTestTopic = + + CLASS BaseClass = + textAttr: TEXT*16; + type: (t1, t2); + SET CONSTRAINT onlyT1: WHERE type == #t1: INTERLIS.elementCount(GeoW_FunctionsExt.GetInGroups(ALL, "textAttr")) == 2; + SET CONSTRAINT onlyT2: WHERE type == #t2: INTERLIS.elementCount(GeoW_FunctionsExt.GetInGroups(ALL, "textAttr")) == 2; + END BaseClass; + + END FunctionTestTopic; + +END TestSuite. diff --git a/src/test/data/GetInGroups/TestDataOnlyT2.xtf b/src/test/data/GetInGroups/TestDataOnlyT2.xtf new file mode 100644 index 0000000..b8be6eb --- /dev/null +++ b/src/test/data/GetInGroups/TestDataOnlyT2.xtf @@ -0,0 +1,23 @@ + + + + + GeoW_FunctionsExt + TestSuite + + ili2gpkg-4.6.1-63db90def1260a503f0f2d4cb846686cd4851184 + + + + + aaa + t2 + + + aaa + t2 + + + + diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPluginTest.java index c13a10a..b044781 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPluginTest.java @@ -11,6 +11,7 @@ class GetInGroupsIoxPluginTest { protected static final String TEST_DATA = "GetInGroups/TestData.xtf"; protected static final String TEST_DATA_EMPTY = "GetInGroups/TestDataEmpty.xtf"; + protected static final String TEST_DATA_ONLY_T2 = "GetInGroups/TestDataOnlyT2.xtf"; ValidationTestHelper vh = null; @BeforeEach @@ -38,4 +39,12 @@ void emptySet() throws Ili2cFailure, IoxException { AssertionHelper.assertNoConstraintError(vh, "trueConstraintTextAttr"); AssertionHelper.assertConstraintErrors(vh, 1, "falseConstraintTextAttr"); } + + @Test + void emptyAfterWhereCondition() throws Ili2cFailure, IoxException { + vh.runValidation(new String[]{TEST_DATA_ONLY_T2}, new String[]{"GetInGroups/SetConstraintWhereCondition.ili"}); + assertEquals(1, vh.getErrs().size()); + AssertionHelper.assertConstraintErrors(vh, 1, "onlyT1"); + AssertionHelper.assertNoConstraintError(vh, "onlyT2"); + } } From 7b39436bfcbb439f6dcc33a49e12f2770eb29165 Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Wed, 11 Dec 2024 14:56:01 +0100 Subject: [PATCH 6/6] Fix comments in test --- .../functions/PolylinesOverlapIoxPluginTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java index e5dd9ce..359ed25 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/PolylinesOverlapIoxPluginTest.java @@ -55,10 +55,10 @@ void setConstraintEverythingFilteredOut() throws Ili2cFailure, IoxException { vh.runValidation(new String[]{TEST_DATA_ONLY_T2}, new String[]{"PolylinesOverlap/PolylinesOverlap.ili"}); assertEquals(3, vh.getErrs().size()); AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintAllNoOverlaps"); - AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintT1"); + AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintT1"); // Error because no T1 objects AssertionHelper.assertNoConstraintError(vh, "setConstraintT2"); - AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintT3"); - AssertionHelper.assertNoConstraintError(vh, "setConstraintT1or2"); // One line in T1 is a segment of T2 - AssertionHelper.assertNoConstraintError(vh, "setConstraintT2or3"); // The lines in T2 and T3 are equal + AssertionHelper.assertConstraintErrors(vh, 1, "setConstraintT3"); // Error because no T3 objects + AssertionHelper.assertNoConstraintError(vh, "setConstraintT1or2"); // T2 has overlapping lines + AssertionHelper.assertNoConstraintError(vh, "setConstraintT2or3"); // T2 has overlapping lines } }