diff --git a/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/CityObjectPropertiesAdapter.java b/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/CityObjectPropertiesAdapter.java index 1bf882537a020a4c0a1290a61028b1b12d1a2884..a67e63e6424e25fa60c33c35c0fe1f1998e5da8e 100644 --- a/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/CityObjectPropertiesAdapter.java +++ b/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/CityObjectPropertiesAdapter.java @@ -33,7 +33,7 @@ public class CityObjectPropertiesAdapter implements ObjectBuilder<CityObjectProp return; } switch (name.getLocalPart()) { - case "validationResult" -> object.setValidationResult(reader.getObjectUsingBuilder(ValidationResultPropertyAdapter.class)); + case "ValidationResult" -> object.setValidationResult(reader.getObjectUsingBuilder(ValidationResultPropertyAdapter.class)); default -> throw new IllegalStateException("Cannot handle name " + name + " when building CityObjectProperties element"); } } diff --git a/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/ErrorAdapter.java b/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/ErrorAdapter.java index b2e6786aba9b351f2ef1e2dd46f4eb136a223fe5..5fb6c4e7dcc786d04aa5f05e9dd83eb01cffdb24 100644 --- a/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/ErrorAdapter.java +++ b/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/ErrorAdapter.java @@ -1,9 +1,8 @@ package de.hft.stuttgart.quality.adapter.types; -import de.hft.stuttgart.quality.model.enums.ErrorId; -import de.hft.stuttgart.quality.model.types.Error; +import javax.xml.namespace.QName; -import de.hft.stuttgart.quality.QualityADEModule; +import org.xmlobjects.annotation.XMLElement; import org.xmlobjects.builder.ObjectBuildException; import org.xmlobjects.builder.ObjectBuilder; import org.xmlobjects.serializer.ObjectSerializeException; @@ -16,8 +15,11 @@ import org.xmlobjects.xml.Attributes; import org.xmlobjects.xml.Element; import org.xmlobjects.xml.Namespaces; -import javax.xml.namespace.QName; +import de.hft.stuttgart.quality.QualityADEModule; +import de.hft.stuttgart.quality.model.enums.ErrorId; +import de.hft.stuttgart.quality.model.types.Error; +@XMLElement(name = "Error", namespaceURI = QualityADEModule.NAMESPACE_URI) public class ErrorAdapter implements ObjectBuilder<Error>, ObjectSerializer<Error> { @Override @@ -37,6 +39,11 @@ public class ErrorAdapter implements ObjectBuilder<Error>, ObjectSerializer<Erro default -> throw new IllegalStateException("Cannot handle name " + name + " when building Error element"); } } + + @Override + public Element createElement(Error object, Namespaces namespaces) throws ObjectSerializeException { + return Element.of(QualityADEModule.NAMESPACE_URI, "Error"); + } @Override public void writeChildElements(Error object, Namespaces namespaces, XMLWriter writer) diff --git a/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/StatisticsAdapter.java b/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/StatisticsAdapter.java index c6ec15756da5089432bc9e60cf74f09530ca7cf9..4ee3eff4b349fd0a4dfa52277f9746041cf1f9ae 100644 --- a/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/StatisticsAdapter.java +++ b/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/adapter/types/StatisticsAdapter.java @@ -16,7 +16,9 @@ import org.xmlobjects.xml.Element; import org.xmlobjects.xml.Namespaces; import de.hft.stuttgart.quality.QualityADEModule; +import de.hft.stuttgart.quality.adapter.properties.ErrorPropertyAdapter; import de.hft.stuttgart.quality.adapter.properties.FeatureStatisticsPropertyAdapter; +import de.hft.stuttgart.quality.model.properties.ErrorProperty; import de.hft.stuttgart.quality.model.types.Statistics; @XMLElement(name = "Statistics", namespaceURI = QualityADEModule.NAMESPACE_URI) @@ -46,10 +48,11 @@ public class StatisticsAdapter implements ObjectBuilder<Statistics>, ObjectSeria .setNumErrorWaterObjects(reader.getObjectUsingBuilder(FeatureStatisticsPropertyAdapter.class)); case "numErrorTransportation" -> object .setNumErrorTransportation(reader.getObjectUsingBuilder(FeatureStatisticsPropertyAdapter.class)); + case "error" -> object.getErrors().add(reader.getObjectUsingBuilder(ErrorPropertyAdapter.class)); default -> throw new IllegalStateException("Cannot handle name " + name + " when building Statistics element"); } } - + @Override public Element createElement(Statistics object, Namespaces namespaces) throws ObjectSerializeException { return Element.of(QualityADEModule.NAMESPACE_URI, "Statistics"); @@ -82,5 +85,9 @@ public class StatisticsAdapter implements ObjectBuilder<Statistics>, ObjectSeria writer.writeElementUsingSerializer(Element.of(QualityADEModule.NAMESPACE_URI, "numErrorTransportation"), object.getNumErrorTransportation(), FeatureStatisticsPropertyAdapter.class, namespaces); } + for (ErrorProperty errorProp : object.getErrors()) { + writer.writeElementUsingSerializer(Element.of(QualityADEModule.NAMESPACE_URI, "error"), errorProp, + ErrorPropertyAdapter.class, namespaces); + } } } diff --git a/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/model/types/FeatureStatistics.java b/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/model/types/FeatureStatistics.java index 125a10cdc993742ff4ced75438b660c9fa17c2ee..e7944bb38bc92a50330c5e34ab21ba0fd59272bc 100644 --- a/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/model/types/FeatureStatistics.java +++ b/citygml4j-quality-ade/src/main/java/de/hft/stuttgart/quality/model/types/FeatureStatistics.java @@ -27,6 +27,15 @@ public class FeatureStatistics extends GMLObject implements ADEObject { private int numChecked; private int numErrors; + + public FeatureStatistics() { + // constructor for serialization + } + + public FeatureStatistics(int numChecked, int numErrors) { + this.numChecked = numChecked; + this.numErrors = numErrors; + } public int getNumChecked() { return numChecked; diff --git a/citygml4j-quality-ade/src/main/resources/META-INF/services/org.citygml4j.core.ade.ADE b/citygml4j-quality-ade/src/main/resources/META-INF/services/org.citygml4j.core.ade.ADE new file mode 100644 index 0000000000000000000000000000000000000000..7d74a7239692a199814fe7e69dde6cd771ba8761 --- /dev/null +++ b/citygml4j-quality-ade/src/main/resources/META-INF/services/org.citygml4j.core.ade.ADE @@ -0,0 +1 @@ +de.hft.stuttgart.quality.QualityADEContext \ No newline at end of file diff --git a/citygml4j-quality-ade/src/test/java/de/hft/stuttgart/quality/QualityAdeTests.java b/citygml4j-quality-ade/src/test/java/de/hft/stuttgart/quality/QualityAdeTests.java index 6a58f064cc0d007934f35d09776e89a386755c65..aaae63065771ebf1ab7ea576c11f3479a09d96a4 100644 --- a/citygml4j-quality-ade/src/test/java/de/hft/stuttgart/quality/QualityAdeTests.java +++ b/citygml4j-quality-ade/src/test/java/de/hft/stuttgart/quality/QualityAdeTests.java @@ -15,6 +15,7 @@ */ package de.hft.stuttgart.quality; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; @@ -22,10 +23,15 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; import javax.xml.XMLConstants; +import javax.xml.namespace.QName; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; @@ -37,11 +43,17 @@ import org.citygml4j.core.ade.ADERegistry; import org.citygml4j.core.model.CityGMLVersion; import org.citygml4j.core.model.building.Building; import org.citygml4j.core.model.core.AbstractCityObjectProperty; +import org.citygml4j.core.model.core.AbstractFeature; import org.citygml4j.core.model.core.AbstractFeatureProperty; import org.citygml4j.core.model.core.CityModel; +import org.citygml4j.core.util.CityGMLConstants; import org.citygml4j.xml.CityGMLContext; import org.citygml4j.xml.CityGMLContextException; import org.citygml4j.xml.module.citygml.CoreModule; +import org.citygml4j.xml.reader.ChunkOptions; +import org.citygml4j.xml.reader.CityGMLInputFactory; +import org.citygml4j.xml.reader.CityGMLReadException; +import org.citygml4j.xml.reader.CityGMLReader; import org.citygml4j.xml.schema.CityGMLSchemaHandler; import org.citygml4j.xml.writer.CityGMLOutputFactory; import org.citygml4j.xml.writer.CityGMLWriteException; @@ -57,6 +69,7 @@ import org.xmlobjects.gml.model.measures.Angle; import org.xmlobjects.gml.model.measures.Length; import org.xmlobjects.schema.SchemaHandlerException; +import de.hft.stuttgart.quality.model.enums.ErrorId; import de.hft.stuttgart.quality.model.enums.RequirementId; import de.hft.stuttgart.quality.model.enums.ResultType; import de.hft.stuttgart.quality.model.enums.RingSelfIntType; @@ -65,6 +78,7 @@ import de.hft.stuttgart.quality.model.properties.AbstractErrorProperty; import de.hft.stuttgart.quality.model.properties.CheckingProperty; import de.hft.stuttgart.quality.model.properties.EdgeListProperty; import de.hft.stuttgart.quality.model.properties.EdgeProperty; +import de.hft.stuttgart.quality.model.properties.ErrorProperty; import de.hft.stuttgart.quality.model.properties.FeatureStatisticsProperty; import de.hft.stuttgart.quality.model.properties.FilterProperty; import de.hft.stuttgart.quality.model.properties.GlobalParametersProperty; @@ -111,104 +125,139 @@ import de.hft.stuttgart.quality.model.types.ValidationPlan; import de.hft.stuttgart.quality.model.types.ValidationResult; class QualityAdeTests { - + + private static final String CITY_OBJECT_MEMBER = "cityObjectMember"; + private static List<QName> chunkProperties = new ArrayList<>(); + + static { + chunkProperties.add(new QName(CityGMLConstants.CITYGML_1_0_CORE_NAMESPACE, CITY_OBJECT_MEMBER)); + chunkProperties.add(new QName(CityGMLConstants.CITYGML_2_0_CORE_NAMESPACE, CITY_OBJECT_MEMBER)); + chunkProperties.add(new QName(CityGMLConstants.CITYGML_3_0_CORE_NAMESPACE, CITY_OBJECT_MEMBER)); + } + @BeforeAll static void setUsLocale() throws ADEException { Locale.setDefault(Locale.US); ADERegistry.getInstance().loadADE(new QualityADEContext()); } - - + @Test - void testAllPolygonsOrientedWrong() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testReadingModel() throws CityGMLContextException, CityGMLReadException { + CityGMLContext context = CityGMLContext.newInstance(); + + CityGMLInputFactory in = context.createCityGMLInputFactory() + .withChunking(ChunkOptions.chunkByProperties(chunkProperties).skipCityModel(false)); + + Path file = Paths.get("src/test/resources/SimpleSolid_Error_QualityADE.gml"); + + try (CityGMLReader reader = in.createCityGMLReader(file)) { + while (reader.hasNext()) { + AbstractFeature feature = reader.next(); + if (feature instanceof Building) { + List<CityObjectProperties> adeProperties = feature.getADEProperties(CityObjectProperties.class); + assertEquals(1, adeProperties.size()); + } + } + } + } + + @Test + void testAllPolygonsOrientedWrong() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + AllPolygonsOrientedWrongError err = new AllPolygonsOrientedWrongError(); err.setGeometryId("geomId"); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testConsecutivePointsSameError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testConsecutivePointsSameError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + ConsecutivePointsSameError err = new ConsecutivePointsSameError(); err.setLinearRingId("ringId"); err.setVertex1(new DirectPosition(1, 2, 3)); err.setVertex2(new DirectPosition(5, 6, 7)); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testHoleOutsideError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testHoleOutsideError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, + IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + HoleOutsideError err = new HoleOutsideError(); err.setLinearRingId("ringId"); err.setPolygonId("polyId"); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testInnerRingsNestedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testInnerRingsNestedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, + IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + InnerRingsNestedError err = new InnerRingsNestedError(); err.setLinearRingId1("ringId1"); err.setLinearRingId2("ringId2"); err.setPolygonId("polyId"); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testInteriorDisconnectedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testInteriorDisconnectedError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + InteriorDisconnectedError err = new InteriorDisconnectedError(); err.setPolygonId("polyId"); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testIntersectingRingsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testIntersectingRingsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, + IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + IntersectingRingsError err = new IntersectingRingsError(); err.setLinearRingId1("ringId1"); err.setLinearRingId2("ringId2"); err.setPolygonId("polyId"); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testMultipleComponentsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testMultipleComponentsError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + MultipleComponentsError err = new MultipleComponentsError(); err.setGeometryId("geomId"); PolygonIdList polygons = new PolygonIdList(); @@ -216,16 +265,17 @@ class QualityAdeTests { polygons.getPolygonIds().add("test2"); err.getComponents().add(new PolygonIdListProperty(polygons)); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testNonManifoldEdgeError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testNonManifoldEdgeError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, + IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + NonManifoldEdgeError err = new NonManifoldEdgeError(); err.setGeometryId("geomId"); EdgeList edges = new EdgeList(); @@ -234,75 +284,80 @@ class QualityAdeTests { edge.setTo(new DirectPosition(5, 6, 7)); edges.getEdges().add(new EdgeProperty(edge)); err.setEdges(new EdgeListProperty(edges)); - + res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testNonManifoldVertexError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testNonManifoldVertexError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, + IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + NonManifoldVertexError err = new NonManifoldVertexError(); err.setGeometryId("geomId"); err.setVertex(new DirectPosition(1, 2, 3)); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testOrientationRingsSameError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testOrientationRingsSameError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + OrientationRingsSameError err = new OrientationRingsSameError(); err.setLinearRing("ring1"); err.setPolygonId("polyId"); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testPlanarDistancePlaneError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testPlanarDistancePlaneError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + PlanarDistancePlaneError err = new PlanarDistancePlaneError(); err.setPolygonId("polyId"); err.setDistance(new Length(5d, "m")); err.setVertex(new DirectPosition(1, 2, 3)); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testPlanarNormalsDeviationError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testPlanarNormalsDeviationError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + PlanarNormalsDeviationError err = new PlanarNormalsDeviationError(); err.setPolygonId("polyId"); err.setDeviation(new Angle(5d, "deg")); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testPolygonWrongOrientationError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testPolygonWrongOrientationError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + PolygonWrongOrientationError err = new PolygonWrongOrientationError(); err.setGeometryId("geomId"); EdgeList edges = new EdgeList(); @@ -312,29 +367,31 @@ class QualityAdeTests { edges.getEdges().add(new EdgeProperty(edge)); err.setEdges(new EdgeListProperty(edges)); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testRingNotClosedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testRingNotClosedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, + IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + RingNotClosedError err = new RingNotClosedError(); err.setLinearRingId("ringId"); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testRingSelfIntersectionError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testRingSelfIntersectionError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + RingSelfIntersectionError err = new RingSelfIntersectionError(); err.setLinearRingId("ringId"); Edge edge = new Edge(); @@ -345,59 +402,63 @@ class QualityAdeTests { err.setType(RingSelfIntType.EDGE_INTERSECTS_EDGE); err.setVertex1(new DirectPosition(1, 2, 3)); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testRingTooFewPointsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testRingTooFewPointsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, + IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + RingTooFewPointsError err = new RingTooFewPointsError(); err.setLinearRingId("ringId"); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testSemanticAttributeMissingError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testSemanticAttributeMissingError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + SemanticAttributeMissingError err = new SemanticAttributeMissingError(); err.setAttributeName("attribute"); err.setChildId("child"); err.setGeneric(true); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testSemanticAttributeWrongValueError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testSemanticAttributeWrongValueError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + SemanticAttributeWrongValueError err = new SemanticAttributeWrongValueError(); err.setAttributeName("attribute"); err.setChildId("child"); err.setGeneric(true); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testSolidNotClosedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testSolidNotClosedError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, + IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + SolidNotClosedError err = new SolidNotClosedError(); err.setGeometryId("geomId"); EdgeList edges = new EdgeList(); @@ -407,42 +468,43 @@ class QualityAdeTests { edges.getEdges().add(new EdgeProperty(edge)); err.setEdges(new EdgeListProperty(edges)); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testSolidSelfIntersectionError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testSolidSelfIntersectionError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + SolidSelfIntersectionError err = new SolidSelfIntersectionError(); err.setGeometryId("geomId"); err.setPolygonId1("poly1"); err.setPolygonId2("poly2"); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - + @Test - void testSolidTooFewPolygonsError() throws ADEException, CityGMLContextException, CityGMLWriteException, SAXException, IOException, SchemaHandlerException { - CityModel model = new CityModel(); + void testSolidTooFewPolygonsError() throws ADEException, CityGMLContextException, CityGMLWriteException, + SAXException, IOException, SchemaHandlerException { + CityModel model = new CityModel(); ValidationResult res = fillCityModel(model); - + SolidTooFewPolygonsError err = new SolidTooFewPolygonsError(); err.setGeometryId("geomId"); res.getErrors().add(new AbstractErrorProperty(err)); - - byte[] buf = writeModel(model); - assertTrue(validate(new ByteArrayInputStream(buf))); + + byte[] buf = writeModel(model); + assertTrue(validate(new ByteArrayInputStream(buf))); } - - - - private boolean validate(InputStream stream) throws SAXException, IOException, CityGMLContextException, SchemaHandlerException { + + private boolean validate(InputStream stream) + throws SAXException, IOException, CityGMLContextException, SchemaHandlerException { CityGMLContext context = CityGMLContext.newInstance(); @@ -463,7 +525,7 @@ class QualityAdeTests { + exception.getMessage(); System.out.println(message); foundErrors[0] = true; - } + } @Override public void warning(SAXParseException exception) { @@ -476,26 +538,23 @@ class QualityAdeTests { } }); - validator.validate(new StreamSource(stream)); return !foundErrors[0]; } - private byte[] writeModel(CityModel model) throws ADEException, CityGMLContextException, CityGMLWriteException { CityGMLContext context = CityGMLContext.newInstance(); CityGMLVersion version = CityGMLVersion.v2_0; - CityGMLOutputFactory out = context.createCityGMLOutputFactory(version); - ByteArrayOutputStream outStream = new ByteArrayOutputStream(); - try (CityGMLWriter writer = out.createCityGMLWriter(outStream, StandardCharsets.UTF_8.name())) { - writer.withIndent(" ") - .withSchemaLocation(QualityADEModule.NAMESPACE_URI, getClass().getResource("/qualityAde.xsd").toString()) - .withDefaultPrefixes() - .withDefaultNamespace(CoreModule.of(version).getNamespaceURI()) - .write(model); - } - return outStream.toByteArray(); + CityGMLOutputFactory out = context.createCityGMLOutputFactory(version); + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + try (CityGMLWriter writer = out.createCityGMLWriter(outStream, StandardCharsets.UTF_8.name())) { + writer.withIndent(" ") + .withSchemaLocation(QualityADEModule.NAMESPACE_URI, + getClass().getResource("/qualityAde.xsd").toString()) + .withDefaultPrefixes().withDefaultNamespace(CoreModule.of(version).getNamespaceURI()).write(model); + } + return outStream.toByteArray(); } private ValidationResult fillCityModel(CityModel model) { @@ -505,7 +564,7 @@ class QualityAdeTests { v.setValidationSoftware("testSoftware"); v.setValidationDate(ZonedDateTime.now()); ValidationPlan plan = new ValidationPlan(); - + Statistics stats = new Statistics(); FeatureStatistics fStats = new FeatureStatistics(); fStats.setNumChecked(5); @@ -513,6 +572,11 @@ class QualityAdeTests { stats.setNumErrorBridgeObjects(new FeatureStatisticsProperty(fStats)); v.setStatistics(new StatisticsProperty(stats)); + de.hft.stuttgart.quality.model.types.Error err = new de.hft.stuttgart.quality.model.types.Error(); + err.setName(ErrorId.GE_P_HOLE_OUTSIDE); + err.setOccurrences(1); + stats.getErrors().add(new ErrorProperty(err)); + Requirement req = new Requirement(); req.setEnabled(true); req.setRequirementType(RequirementId.R_GE_P_HOLE_OUTSIDE); @@ -520,7 +584,7 @@ class QualityAdeTests { Checking checking = new Checking(); checking.setFeatureType(TopLevelFeatureType.BRIDGE); - + Filter filter = new Filter(); filter.getChecking().add(new CheckingProperty(checking)); plan.setFilter(new FilterProperty(filter)); @@ -534,12 +598,11 @@ class QualityAdeTests { plan.setGlobalParameters(new GlobalParametersProperty(globalParams)); v.setValidationPlan(new ValidationPlanProperty(plan)); - - + Building b = new Building(); b.setId("testId"); model.getCityObjectMembers().add(new AbstractCityObjectProperty(b)); - + CityObjectProperties props = new CityObjectProperties(); b.addADEProperty(props); ValidationResult res = new ValidationResult();