From b34b7885dd0e9dba8741ad4b9ecc2023d688fb03 Mon Sep 17 00:00:00 2001 From: Dominic Burger Date: Tue, 9 Jan 2024 14:49:43 +0100 Subject: [PATCH] Return empty set when grouping an empty set --- .../functions/GetInGroupsIoxPlugin.java | 4 ++++ .../data/GetInGroups/SetConstraintEmpty.ili | 17 +++++++++++++++++ src/test/data/GetInGroups/TestDataEmpty.xtf | 15 +++++++++++++++ .../functions/GetInGroupsIoxPluginTest.java | 9 +++++++++ 4 files changed, 45 insertions(+) create mode 100644 src/test/data/GetInGroups/SetConstraintEmpty.ili create mode 100644 src/test/data/GetInGroups/TestDataEmpty.xtf 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 687e798..7be4cfa 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPlugin.java @@ -30,6 +30,10 @@ public Value evaluateInternal(String validationKind, String usageScope, IomObjec return Value.createUndefined(); } + if (inputObjects.isEmpty()) { + return new Value(Collections.emptyList()); + } + Viewable contextClass = EvaluationHelper.getContextClass(td, contextObject, argObjects); if (contextClass == null) { throw new IllegalStateException("unknown class in " + usageScope); diff --git a/src/test/data/GetInGroups/SetConstraintEmpty.ili b/src/test/data/GetInGroups/SetConstraintEmpty.ili new file mode 100644 index 0000000..b3d6868 --- /dev/null +++ b/src/test/data/GetInGroups/SetConstraintEmpty.ili @@ -0,0 +1,17 @@ +INTERLIS 2.4; + +MODEL TestSuite + AT "mailto:info@geowerkstatt.ch" VERSION "2024-01-09" = + IMPORTS GeoW_FunctionsExt; + + TOPIC FunctionTestTopic = + + CLASS BaseClass = + textAttr: TEXT*16; + SET CONSTRAINT trueConstraintTextAttr: INTERLIS.elementCount(GeoW_FunctionsExt.GetInGroups(ALL, "textAttr")) == 0; + SET CONSTRAINT falseConstraintTextAttr: INTERLIS.elementCount(GeoW_FunctionsExt.GetInGroups(ALL, "textAttr")) == 2; + END BaseClass; + + END FunctionTestTopic; + +END TestSuite. diff --git a/src/test/data/GetInGroups/TestDataEmpty.xtf b/src/test/data/GetInGroups/TestDataEmpty.xtf new file mode 100644 index 0000000..422c127 --- /dev/null +++ b/src/test/data/GetInGroups/TestDataEmpty.xtf @@ -0,0 +1,15 @@ + + + + + GeoW_FunctionsExt + TestSuite + + ili2gpkg-4.6.1-63db90def1260a503f0f2d4cb846686cd4851184 + + + + + + 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 55ff24c..5ac50df 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/GetInGroupsIoxPluginTest.java @@ -9,6 +9,7 @@ class GetInGroupsIoxPluginTest { protected static final String TEST_DATA = "GetInGroups/TestData.xtf"; + protected static final String TEST_DATA_EMPTY = "GetInGroups/TestDataEmpty.xtf"; ValidationTestHelper vh = null; @BeforeEach @@ -28,4 +29,12 @@ void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException { AssertionHelper.assertSingleConstraintError(vh, 0, "falseConstraintEnumAttr"); AssertionHelper.assertSingleConstraintError(vh, 0, "falseConstraintNumberAttr"); } + + @Test + void emptySet() throws Ili2cFailure, IoxException { + vh.runValidation(new String[]{TEST_DATA_EMPTY}, new String[]{"GetInGroups/SetConstraintEmpty.ili"}); + Assert.equals(1, vh.getErrs().size()); + AssertionHelper.assertNoConstraintError(vh, "trueConstraintTextAttr"); + AssertionHelper.assertConstraintErrors(vh, 1, "falseConstraintTextAttr"); + } }