Commit f95ca9ff authored by Matthias Betz's avatar Matthias Betz
Browse files

fixed error adapter

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