From 8a831f113533e2e4e80a3582396d52f806a362d6 Mon Sep 17 00:00:00 2001 From: Simon Templer Date: Wed, 7 Feb 2024 10:56:42 +0100 Subject: [PATCH] WIP first test case for inner join --- .../META-INF/MANIFEST.MF | 2 + .../hale/common/test/TestUtil.java | 22 +++- .../ConceptualSchemaTransformerTest.java | 10 ++ .../cst/test/TransformationExamples.groovy | 20 +++- .../testdata/inner_join/mapping.halex | 33 ++++++ .../inner_join/mapping.halex.alignment.xml | 107 ++++++++++++++++++ .../inner_join/mapping.halex.styles.sld | 3 + .../inner_join/source-instances.groovy | 55 +++++++++ .../testdata/inner_join/source-schema.groovy | 15 +++ .../inner_join/target-instances.groovy | 15 +++ .../testdata/inner_join/target-schema.groovy | 7 ++ 11 files changed, 283 insertions(+), 6 deletions(-) create mode 100644 cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex create mode 100644 cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex.alignment.xml create mode 100644 cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex.styles.sld create mode 100644 cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/source-instances.groovy create mode 100644 cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/source-schema.groovy create mode 100644 cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/target-instances.groovy create mode 100644 cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/target-schema.groovy diff --git a/common/plugins/eu.esdihumboldt.hale.common.test/META-INF/MANIFEST.MF b/common/plugins/eu.esdihumboldt.hale.common.test/META-INF/MANIFEST.MF index d74cb29ac6..95e488a71c 100644 --- a/common/plugins/eu.esdihumboldt.hale.common.test/META-INF/MANIFEST.MF +++ b/common/plugins/eu.esdihumboldt.hale.common.test/META-INF/MANIFEST.MF @@ -15,8 +15,10 @@ Import-Package: de.fhg.igd.osgi.util, eu.esdihumboldt.hale.common.core.io.report.impl, eu.esdihumboldt.hale.common.core.io.supplier, eu.esdihumboldt.hale.common.core.report, + eu.esdihumboldt.hale.common.instance.io, eu.esdihumboldt.hale.common.instance.io.impl, eu.esdihumboldt.hale.common.instance.model, + eu.esdihumboldt.hale.common.schema.io, eu.esdihumboldt.hale.common.schema.io.impl, eu.esdihumboldt.hale.common.schema.model, eu.esdihumboldt.hale.common.schema.model.impl, diff --git a/common/plugins/eu.esdihumboldt.hale.common.test/src/eu/esdihumboldt/hale/common/test/TestUtil.java b/common/plugins/eu.esdihumboldt.hale.common.test/src/eu/esdihumboldt/hale/common/test/TestUtil.java index 780d48059b..8f994104a6 100644 --- a/common/plugins/eu.esdihumboldt.hale.common.test/src/eu/esdihumboldt/hale/common/test/TestUtil.java +++ b/common/plugins/eu.esdihumboldt.hale.common.test/src/eu/esdihumboldt/hale/common/test/TestUtil.java @@ -37,6 +37,7 @@ import eu.esdihumboldt.hale.common.align.io.impl.CastorAlignmentIO; import eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentIO; import eu.esdihumboldt.hale.common.align.model.Alignment; +import eu.esdihumboldt.hale.common.core.io.HaleIO; import eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException; import eu.esdihumboldt.hale.common.core.io.PathUpdate; import eu.esdihumboldt.hale.common.core.io.report.IOReport; @@ -44,7 +45,9 @@ import eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter; import eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier; import eu.esdihumboldt.hale.common.core.io.supplier.Locatable; +import eu.esdihumboldt.hale.common.instance.io.InstanceReader; import eu.esdihumboldt.hale.common.instance.model.InstanceCollection; +import eu.esdihumboldt.hale.common.schema.io.SchemaReader; import eu.esdihumboldt.hale.common.schema.model.Schema; import eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeIndex; import eu.esdihumboldt.hale.io.gml.reader.internal.XmlInstanceReader; @@ -59,7 +62,7 @@ public class TestUtil { /** - * Loads the specified XML Schema. + * Loads the specified schema. * * @param location the URI specifying the location of the schema * @return the loaded schema @@ -71,7 +74,11 @@ public static Schema loadSchema(URI location) throws IOProviderConfigurationException, IOException { DefaultInputSupplier input = new DefaultInputSupplier(location); - XmlSchemaReader reader = new XmlSchemaReader(); + SchemaReader reader = HaleIO.findIOProvider(SchemaReader.class, input, location.getPath()); + if (reader == null) { + // assume XML schema as default + reader = new XmlSchemaReader(); + } reader.setSharedTypes(new DefaultTypeIndex()); reader.setSource(input); @@ -120,10 +127,10 @@ public URI getLocation() { } /** - * Loads an instance collection from the specified XML file with the given + * Loads an instance collection from the specified file with the given * source types. * - * @param location the URI specifying the location of the xml instance file + * @param location the URI specifying the location of the instance file * @param types the type index * @return the loaded instance collection * @throws IOException if loading the instance failed @@ -134,7 +141,12 @@ public static InstanceCollection loadInstances(URI location, Schema types) throws IOProviderConfigurationException, IOException { DefaultInputSupplier input = new DefaultInputSupplier(location); - XmlInstanceReader instanceReader = new XmlInstanceReader(); + InstanceReader instanceReader = HaleIO.findIOProvider(InstanceReader.class, input, + location.getPath()); + if (instanceReader == null) { + // assume XML as default + instanceReader = new XmlInstanceReader(); + } instanceReader.setSource(input); instanceReader.setSourceSchema(types); IOReport report = instanceReader.execute(null); diff --git a/cst/plugins/eu.esdihumboldt.cst.test/src/eu/esdihumboldt/cst/internal/ConceptualSchemaTransformerTest.java b/cst/plugins/eu.esdihumboldt.cst.test/src/eu/esdihumboldt/cst/internal/ConceptualSchemaTransformerTest.java index 47cac32543..8d6f54f80b 100644 --- a/cst/plugins/eu.esdihumboldt.cst.test/src/eu/esdihumboldt/cst/internal/ConceptualSchemaTransformerTest.java +++ b/cst/plugins/eu.esdihumboldt.cst.test/src/eu/esdihumboldt/cst/internal/ConceptualSchemaTransformerTest.java @@ -344,6 +344,16 @@ public void testPropertyJoinIntFloat() throws Exception { TransformationExamples.getExample(TransformationExamples.PROPERTY_JOIN_INT_FLOAT)); } + /** + * Test a Join that has the innerJoin flag enabled. + * + * @throws Exception if an error occurs executing the test + */ + @Test + public void testInnerJoin() throws Exception { + testTransform(TransformationExamples.getExample(TransformationExamples.INNER_JOIN)); + } + @Override protected List transformData(TransformationExample example) throws Exception { ConceptualSchemaTransformer transformer = new ConceptualSchemaTransformer(); diff --git a/cst/plugins/eu.esdihumboldt.cst.test/src/eu/esdihumboldt/cst/test/TransformationExamples.groovy b/cst/plugins/eu.esdihumboldt.cst.test/src/eu/esdihumboldt/cst/test/TransformationExamples.groovy index 592feac05b..bb4aa145cd 100644 --- a/cst/plugins/eu.esdihumboldt.cst.test/src/eu/esdihumboldt/cst/test/TransformationExamples.groovy +++ b/cst/plugins/eu.esdihumboldt.cst.test/src/eu/esdihumboldt/cst/test/TransformationExamples.groovy @@ -112,6 +112,8 @@ abstract class TransformationExamples { public static final String XSL_XPATH_1 = 'xpath1' + public static final String INNER_JOIN = 'inner_join' + /** * Internal example map. */ @@ -225,7 +227,10 @@ abstract class TransformationExamples { (CM_NESTED_6): defaultExample(CM_NESTED_6), // XSL only examples - (XSL_XPATH_1): defaultExample(XSL_XPATH_1) + (XSL_XPATH_1): defaultExample(XSL_XPATH_1), + + // builder based examples + (INNER_JOIN): builderExample(INNER_JOIN) ]; static def defaultExample(String folder) { @@ -240,6 +245,19 @@ abstract class TransformationExamples { ] } + static def builderExample(String folder) { + [ + sourceSchema: "/testdata/${folder}/source-schema.groovy", + targetSchema: "/testdata/${folder}/target-schema.groovy", + alignment: "/testdata/${folder}/mapping.halex.alignment.xml", + sourceData: "/testdata/${folder}/source-instances.groovy", + transformedData: "/testdata/${folder}/target-instances.groovy", + // not relevant: + containerNamespace: null, + containerName: null + ] + } + /** * Get the transformation example with the given identifier. * diff --git a/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex new file mode 100644 index 0000000000..74e7dfbc99 --- /dev/null +++ b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex @@ -0,0 +1,33 @@ + + + mapping + hale + 2024-02-07T10:28:58.718+01:00 + 2024-02-07T10:39:07.594+01:00 + + UTF-8 + false + eu.esdihumboldt.hale.io.project.hale25.xml + file:/home/simon/repos/hale/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex + + + UTF-8 + ec2ec25e-5940-4b91-8ccd-9ea9455a3dbc + source-schema.groovy + eu.esdihumboldt.hale.io.schemabuilder + + + UTF-8 + 646e49d6-a2f9-462c-8bfb-e6a2a47abef1 + target-schema.groovy + eu.esdihumboldt.hale.io.schemabuilder + + + UTF-8 + 95bd5843-dfc0-43be-a901-03e7b843d44a + source-instances.groovy + eu.esdihumboldt.hale.io.instancebuilder + + + + diff --git a/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex.alignment.xml b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex.alignment.xml new file mode 100644 index 0000000000..7aacf8dffe --- /dev/null +++ b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex.alignment.xml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex.styles.sld b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex.styles.sld new file mode 100644 index 0000000000..ad34f540f6 --- /dev/null +++ b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/mapping.halex.styles.sld @@ -0,0 +1,3 @@ + + Default Styler + diff --git a/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/source-instances.groovy b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/source-instances.groovy new file mode 100644 index 0000000000..6ec91bc764 --- /dev/null +++ b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/source-instances.groovy @@ -0,0 +1,55 @@ +createCollection { + + /* + * Sets of instances that are joined + */ + + A { + a('a1') + } + B { + a('a1') + b('b1') + } + C { + b('b1') + c('c1') + } + + A { + a('a3') + } + B { + a('a3') + b('b1') + } + + /* + * Sets of instances that are not joined because of missing links + */ + + A { + a('a2') + } + B { + a('a2') + b('b2') + } + C { + b('c2') + c('c2') + } + + A { + a('a4') + } + B { + a('a4') + b('b4') + } + + A { + a('a5') + } + +} \ No newline at end of file diff --git a/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/source-schema.groovy b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/source-schema.groovy new file mode 100644 index 0000000000..f36e161f99 --- /dev/null +++ b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/source-schema.groovy @@ -0,0 +1,15 @@ +schema('source') { + A { + a() + } + + B { + a() + b(cardinality: '?') + } + + C { + b() + c(cardinality: '?') + } +} \ No newline at end of file diff --git a/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/target-instances.groovy b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/target-instances.groovy new file mode 100644 index 0000000000..bcffd2ac78 --- /dev/null +++ b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/target-instances.groovy @@ -0,0 +1,15 @@ +createCollection { + + T { + a('a1') + b('b1') + c('c1') + } + + T { + a('a3') + b('b1') + c('c1') + } + +} \ No newline at end of file diff --git a/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/target-schema.groovy b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/target-schema.groovy new file mode 100644 index 0000000000..d1e90f9ce2 --- /dev/null +++ b/cst/plugins/eu.esdihumboldt.cst.test/testdata/inner_join/target-schema.groovy @@ -0,0 +1,7 @@ +schema('target') { + T { + a() + b() + c() + } +}