diff --git a/src/test/data/Filter/MandatoryConstraints.ili b/src/test/data/Filter/MandatoryConstraints.ili new file mode 100644 index 0000000..546e917 --- /dev/null +++ b/src/test/data/Filter/MandatoryConstraints.ili @@ -0,0 +1,30 @@ +INTERLIS 2.4; + +MODEL TestSuite + AT "mailto:info@geowerkstatt.ch" VERSION "2024-04-04" = + IMPORTS GeoW_FunctionsExt; + + TOPIC FunctionTestTopic = + + STRUCTURE ReferencedStruct = + textAttr: TEXT*16; + enumAttr: (val1,val2,val3); + numberAttr: 0..10; + END ReferencedStruct; + + STRUCTURE ExtendedStruct EXTENDS ReferencedStruct = + newAttr: BOOLEAN; + END ExtendedStruct; + + CLASS BaseClass = + references: BAG {1..*} OF ReferencedStruct; + + MANDATORY CONSTRAINT trueConstraintEnumAttr: INTERLIS.elementCount(GeoW_FunctionsExt.Filter(THIS->references, "WHERE enumAttr == #val2;")) == 3; + MANDATORY CONSTRAINT trueConstraintNumberAttr: INTERLIS.elementCount(GeoW_FunctionsExt.Filter(references, "WHERE numberAttr >= 3 AND enumAttr != #val3;")) == 1; + MANDATORY CONSTRAINT falseConstraintEnumAttr: INTERLIS.elementCount(GeoW_FunctionsExt.Filter(references, "WHERE enumAttr == #val2;")) == 0; + MANDATORY CONSTRAINT falseConstraintNumberAttr: INTERLIS.elementCount(GeoW_FunctionsExt.Filter(THIS->references, "WHERE numberAttr == 3 AND enumAttr == #val3;")) > 0; + END BaseClass; + + END FunctionTestTopic; + +END TestSuite. diff --git a/src/test/data/Filter/MandatoryConstraintsText.ili b/src/test/data/Filter/MandatoryConstraintsText.ili new file mode 100644 index 0000000..e0e57cb --- /dev/null +++ b/src/test/data/Filter/MandatoryConstraintsText.ili @@ -0,0 +1,28 @@ +INTERLIS 2.4; + +MODEL TestSuite + AT "mailto:info@geowerkstatt.ch" VERSION "2024-04-04" = + IMPORTS GeoW_FunctionsExt; + + TOPIC FunctionTestTopic = + + STRUCTURE ReferencedStruct = + textAttr: TEXT*16; + enumAttr: (val1,val2,val3); + numberAttr: 0..10; + END ReferencedStruct; + + STRUCTURE ExtendedStruct EXTENDS ReferencedStruct = + newAttr: BOOLEAN; + END ExtendedStruct; + + CLASS BaseClass = + references: BAG {1..*} OF ReferencedStruct; + + MANDATORY CONSTRAINT trueConstraintTextAttr: INTERLIS.elementCount(GeoW_FunctionsExt.Filter(THIS->references, "WHERE textAttr == \"Some Value\";")) == 2; + MANDATORY CONSTRAINT falseConstraintTextAttr: INTERLIS.elementCount(GeoW_FunctionsExt.Filter(references, "WHERE textAttr == \"Value that does not exist\";")) > 0; + END BaseClass; + + END FunctionTestTopic; + +END TestSuite. diff --git a/src/test/data/Filter/TestData.xtf b/src/test/data/Filter/TestData.xtf new file mode 100644 index 0000000..db84c90 --- /dev/null +++ b/src/test/data/Filter/TestData.xtf @@ -0,0 +1,45 @@ + + + + + GeoW_FunctionsExt + TestSuite + + ili2gpkg-4.6.1-63db90def1260a503f0f2d4cb846686cd4851184 + + + + + + + Some Value + val2 + 2 + + + aaa + val2 + 2 + + + aaa + val2 + 2 + + + Some Value + val3 + 1 + false + + + bbb + val1 + 3 + + + + + + diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPluginTest.java new file mode 100644 index 0000000..498015d --- /dev/null +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/FilterIoxPluginTest.java @@ -0,0 +1,38 @@ +package ch.geowerkstatt.ilivalidator.extensions.functions; + +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; + +class FilterIoxPluginTest { + protected static final String TEST_DATA = "Filter/TestData.xtf"; + private ValidationTestHelper vh; + + @BeforeEach + public void setUp() { + vh = new ValidationTestHelper(); + vh.addFunction(new FilterIoxPlugin()); + } + + @Test + public void mandatoryConstraint() throws Ili2cFailure, IoxException { + vh.runValidation(new String[]{TEST_DATA}, new String[]{"Filter/MandatoryConstraints.ili"}); + Assert.equals(2, vh.getErrs().size()); + AssertionHelper.assertNoConstraintError(vh, "trueConstraintEnumAttr"); + AssertionHelper.assertNoConstraintError(vh, "trueConstraintNumberAttr"); + AssertionHelper.assertConstraintErrors(vh, 1, "base", "falseConstraintEnumAttr"); + AssertionHelper.assertConstraintErrors(vh, 1, "base", "falseConstraintNumberAttr"); + } + + @Test + @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()); + AssertionHelper.assertNoConstraintError(vh, "trueConstraintTextAttr"); + AssertionHelper.assertConstraintErrors(vh, 1, "base", "falseConstraintTextAttr"); + } +}