Skip to content

Commit

Permalink
Add tests for Filter function
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Apr 4, 2024
1 parent 25433c5 commit 7a2402e
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/data/Filter/MandatoryConstraints.ili
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
INTERLIS 2.4;

MODEL TestSuite
AT "mailto:[email protected]" 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.
28 changes: 28 additions & 0 deletions src/test/data/Filter/MandatoryConstraintsText.ili
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
INTERLIS 2.4;

MODEL TestSuite
AT "mailto:[email protected]" 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.
45 changes: 45 additions & 0 deletions src/test/data/Filter/TestData.xtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<ili:transfer xmlns:ili="http://www.interlis.ch/xtf/2.4/INTERLIS" xmlns:geom="http://www.interlis.ch/geometry/1.0"
xmlns:TestSuite="http://www.interlis.ch/xtf/2.4/TestSuite">
<ili:headersection>
<ili:models>
<ili:model>GeoW_FunctionsExt</ili:model>
<ili:model>TestSuite</ili:model>
</ili:models>
<ili:sender>ili2gpkg-4.6.1-63db90def1260a503f0f2d4cb846686cd4851184</ili:sender>
</ili:headersection>
<ili:datasection>
<TestSuite:FunctionTestTopic ili:bid="TestSuite.FunctionTestTopic">
<TestSuite:BaseClass ili:tid="base">
<TestSuite:references>
<TestSuite:ReferencedStruct>
<TestSuite:textAttr>Some Value</TestSuite:textAttr>
<TestSuite:enumAttr>val2</TestSuite:enumAttr>
<TestSuite:numberAttr>2</TestSuite:numberAttr>
</TestSuite:ReferencedStruct>
<TestSuite:ReferencedStruct>
<TestSuite:textAttr>aaa</TestSuite:textAttr>
<TestSuite:enumAttr>val2</TestSuite:enumAttr>
<TestSuite:numberAttr>2</TestSuite:numberAttr>
</TestSuite:ReferencedStruct>
<TestSuite:ReferencedStruct>
<TestSuite:textAttr>aaa</TestSuite:textAttr>
<TestSuite:enumAttr>val2</TestSuite:enumAttr>
<TestSuite:numberAttr>2</TestSuite:numberAttr>
</TestSuite:ReferencedStruct>
<TestSuite:ExtendedStruct>
<TestSuite:textAttr>Some Value</TestSuite:textAttr>
<TestSuite:enumAttr>val3</TestSuite:enumAttr>
<TestSuite:numberAttr>1</TestSuite:numberAttr>
<TestSuite:newAttr>false</TestSuite:newAttr>
</TestSuite:ExtendedStruct>
<TestSuite:ReferencedStruct>
<TestSuite:textAttr>bbb</TestSuite:textAttr>
<TestSuite:enumAttr>val1</TestSuite:enumAttr>
<TestSuite:numberAttr>3</TestSuite:numberAttr>
</TestSuite:ReferencedStruct>
</TestSuite:references>
</TestSuite:BaseClass>
</TestSuite:FunctionTestTopic>
</ili:datasection>
</ili:transfer>
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit 7a2402e

Please sign in to comment.