From 70b7ecf107794f7b15d29344f278edd115897f88 Mon Sep 17 00:00:00 2001 From: manuelaromero-guadaltel Date: Mon, 8 May 2023 10:15:25 +0200 Subject: [PATCH 1/2] Added validateLeftHandRightHandClockwiseOrientation() test Signed-off-by: manuelaromero-guadaltel --- .../validation/GmlGeometryValidatorTest.java | 151 ++++++++++++------ ...r_anticlockwise_interior_anticlockwise.gml | 13 ++ ...erior_anticlockwise_interior_clockwise.gml | 13 ++ ...erior_clockwise_interior_anticlockwise.gml | 13 ++ ..._exterior_clockwise_interior_clockwise.gml | 13 ++ ...r_anticlockwise_interior_anticlockwise.gml | 13 ++ ...erior_anticlockwise_interior_clockwise.gml | 13 ++ ...erior_clockwise_interior_anticlockwise.gml | 13 ++ ..._exterior_clockwise_interior_clockwise.gml | 13 ++ 9 files changed, 202 insertions(+), 53 deletions(-) create mode 100644 deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_anticlockwise_interior_anticlockwise.gml create mode 100644 deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_anticlockwise_interior_clockwise.gml create mode 100644 deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_clockwise_interior_anticlockwise.gml create mode 100644 deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_clockwise_interior_clockwise.gml create mode 100644 deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_anticlockwise_interior_anticlockwise.gml create mode 100644 deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_anticlockwise_interior_clockwise.gml create mode 100644 deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_clockwise_interior_anticlockwise.gml create mode 100644 deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_clockwise_interior_clockwise.gml diff --git a/deegree-core/deegree-core-base/src/test/java/org/deegree/geometry/gml/validation/GmlGeometryValidatorTest.java b/deegree-core/deegree-core-base/src/test/java/org/deegree/geometry/gml/validation/GmlGeometryValidatorTest.java index d2e69ea24a..7ca7ccfd76 100644 --- a/deegree-core/deegree-core-base/src/test/java/org/deegree/geometry/gml/validation/GmlGeometryValidatorTest.java +++ b/deegree-core/deegree-core-base/src/test/java/org/deegree/geometry/gml/validation/GmlGeometryValidatorTest.java @@ -64,77 +64,122 @@ /** * Tests that check the expected generation of validation events by the * {@link GmlGeometryValidationEvent}. - * + * * @author Markus Schneider */ public class GmlGeometryValidatorTest { - private static final String BASE_DIR = "../misc/geometry/"; + private static final String BASE_DIR = "../misc/geometry/"; - @Test - public void validateCurve() + @Test + public void validateCurve() throws XMLStreamException, FactoryConfigurationError, IOException, ClassCastException, UnknownCRSException { - TestEventHandler eventHandler = validate("Curve.gml"); - assertEquals(0, eventHandler.getEvents().size()); - } + TestEventHandler eventHandler = validate( "Curve.gml" ); + assertEquals( 0, eventHandler.getEvents().size() ); + } - @Test - public void validateCurveDiscontinuity() + @Test + public void validateCurveDiscontinuity() throws XMLStreamException, FactoryConfigurationError, IOException, ClassCastException, UnknownCRSException { - TestEventHandler eventHandler = validate("invalid/Curve_discontinuity.gml"); - assertEquals(1, eventHandler.getEvents().size()); - GmlGeometryValidationEvent event = eventHandler.getEvents().get(0); - Assert.assertEquals(CurveDiscontinuity.class, event.getEvent().getClass()); - } - - @Test - public void validateRingNotClosed() - throws XMLStreamException, FactoryConfigurationError, IOException, UnknownCRSException { - TestEventHandler eventHandler = validate("invalid/Ring_not_closed.gml"); - assertEquals(1, eventHandler.getEvents().size()); - GmlGeometryValidationEvent event = eventHandler.getEvents().get(0); - Assert.assertEquals(RingNotClosed.class, event.getEvent().getClass()); - } + TestEventHandler eventHandler = validate( "invalid/Curve_discontinuity.gml" ); + assertEquals( 1, eventHandler.getEvents().size() ); + GmlGeometryValidationEvent event = eventHandler.getEvents().get( 0 ); + Assert.assertEquals( CurveDiscontinuity.class, event.getEvent().getClass() ); + } + + @Test + public void validateRingNotClosed() + throws XMLStreamException, FactoryConfigurationError, IOException, UnknownCRSException { + TestEventHandler eventHandler = validate( "invalid/Ring_not_closed.gml" ); + assertEquals( 1, eventHandler.getEvents().size() ); + GmlGeometryValidationEvent event = eventHandler.getEvents().get( 0 ); + Assert.assertEquals( RingNotClosed.class, event.getEvent().getClass() ); + } + + @Test + public void validatePolygonExteriorClockwise() + throws XMLStreamException, FactoryConfigurationError, IOException, UnknownCRSException { + TestEventHandler eventHandler = validate( "invalid/Polygon_exterior_clockwise.gml" ); + assertEquals( 3, eventHandler.getEvents().size() ); + Assert.assertTrue( ( (ExteriorRingOrientation) ( eventHandler.getEvents().get( 0 ).getEvent() ) ).isClockwise() ); + Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler.getEvents().get( 1 ).getEvent() ) ).isClockwise() ); + Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler.getEvents().get( 2 ).getEvent() ) ).isClockwise() ); + } + + @Test + public void validateLeftHandRightHandClockwiseOrientation() + throws XMLStreamException, UnknownCRSException, FactoryConfigurationError, IOException { + TestEventHandler eventHandler = validate( "invalid/LeftHanded_exterior_clockwise_interior_clockwise.gml" ); + assertEquals( 2, eventHandler.getEvents().size() ); + Assert.assertTrue( ( (ExteriorRingOrientation) ( eventHandler.getEvents().get( 0 ).getEvent() ) ).isExterior() ); + Assert.assertFalse( ( (InteriorRingOrientation) ( eventHandler.getEvents().get( 1 ).getEvent() ) ).isInterior() ); + + TestEventHandler eventHandler2 = validate( "invalid/LeftHanded_exterior_clockwise_interior_anticlockwise.gml" ); + assertEquals( 2, eventHandler2.getEvents().size() ); + Assert.assertTrue( ( (ExteriorRingOrientation) ( eventHandler2.getEvents().get( 0 ).getEvent() ) ).isExterior() ); + Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler2.getEvents().get( 1 ).getEvent() ) ).isInterior() ); + + TestEventHandler eventHandler3 = validate( "invalid/LeftHanded_exterior_anticlockwise_interior_clockwise.gml" ); + assertEquals( 2, eventHandler3.getEvents().size() ); + Assert.assertFalse( ( (ExteriorRingOrientation) ( eventHandler3.getEvents().get( 0 ).getEvent() ) ).isExterior() ); + Assert.assertFalse( ( (InteriorRingOrientation) ( eventHandler3.getEvents().get( 1 ).getEvent() ) ).isInterior() ); + + TestEventHandler eventHandler4 = validate( "invalid/LeftHanded_exterior_anticlockwise_interior_anticlockwise.gml" ); + assertEquals( 2, eventHandler4.getEvents().size() ); + Assert.assertFalse( ( (ExteriorRingOrientation) ( eventHandler4.getEvents().get( 0 ).getEvent() ) ).isExterior() ); + Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler4.getEvents().get( 1 ).getEvent() ) ).isInterior() ); + + TestEventHandler eventHandler5 = validate( "invalid/RightHanded_exterior_clockwise_interior_clockwise.gml" ); + assertEquals( 2, eventHandler5.getEvents().size() ); + Assert.assertFalse( ( (ExteriorRingOrientation) ( eventHandler5.getEvents().get( 0 ).getEvent() ) ).isExterior() ); + Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler5.getEvents().get( 1 ).getEvent() ) ).isInterior() ); + + TestEventHandler eventHandler6 = validate( "invalid/RightHanded_exterior_clockwise_interior_anticlockwise.gml" ); + assertEquals( 2, eventHandler6.getEvents().size() ); + Assert.assertFalse( ( (ExteriorRingOrientation) ( eventHandler6.getEvents().get( 0 ).getEvent() ) ).isExterior() ); + Assert.assertFalse( ( (InteriorRingOrientation) ( eventHandler6.getEvents().get( 1 ).getEvent() ) ).isInterior() ); + + TestEventHandler eventHandler7 = validate( "invalid/RightHanded_exterior_anticlockwise_interior_clockwise.gml" ); + assertEquals( 2, eventHandler7.getEvents().size() ); + Assert.assertTrue( ( (ExteriorRingOrientation) ( eventHandler7.getEvents().get( 0 ).getEvent() ) ).isExterior() ); + Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler7.getEvents().get( 1 ).getEvent() ) ).isInterior() ); + + TestEventHandler eventHandler8 = validate( "invalid/RightHanded_exterior_anticlockwise_interior_anticlockwise.gml" ); + assertEquals( 2, eventHandler8.getEvents().size() ); + Assert.assertTrue( ( (ExteriorRingOrientation) ( eventHandler8.getEvents().get( 0 ).getEvent() ) ).isExterior() ); + Assert.assertFalse( ( (InteriorRingOrientation) ( eventHandler8.getEvents().get( 1 ).getEvent() ) ).isInterior() ); - @Test - public void validatePolygonExteriorClockwise() - throws XMLStreamException, FactoryConfigurationError, IOException, UnknownCRSException { - TestEventHandler eventHandler = validate("invalid/Polygon_exterior_clockwise.gml"); - assertEquals(3, eventHandler.getEvents().size()); - Assert.assertTrue(((ExteriorRingOrientation) (eventHandler.getEvents().get(0).getEvent())).isClockwise()); - Assert.assertTrue(((InteriorRingOrientation) (eventHandler.getEvents().get(1).getEvent())).isClockwise()); - Assert.assertTrue(((InteriorRingOrientation) (eventHandler.getEvents().get(2).getEvent())).isClockwise()); } - private TestEventHandler validate(String resourceName) - throws XMLStreamException, UnknownCRSException, FactoryConfigurationError, IOException { - TestEventHandler eventHandler = new TestEventHandler(); - URL resourceUrl = GML3GeometryReaderTest.class.getResource(BASE_DIR + resourceName); - GMLStreamReader gmlStream = GMLInputFactory.createGMLStreamReader(GML_31, resourceUrl); - GmlStreamGeometryValidator validator = new GmlStreamGeometryValidator(gmlStream, eventHandler); - validator.validateGeometries(); - return eventHandler; - } + private TestEventHandler validate( String resourceName ) + throws XMLStreamException, UnknownCRSException, FactoryConfigurationError, IOException { + TestEventHandler eventHandler = new TestEventHandler(); + URL resourceUrl = GML3GeometryReaderTest.class.getResource( BASE_DIR + resourceName ); + GMLStreamReader gmlStream = GMLInputFactory.createGMLStreamReader( GML_31, resourceUrl ); + GmlStreamGeometryValidator validator = new GmlStreamGeometryValidator( gmlStream, eventHandler ); + validator.validateGeometries(); + return eventHandler; + } } class TestEventHandler implements GmlGeometryValidationEventHandler { - private final List events = new ArrayList(); + private final List events = new ArrayList(); - @Override - public void parsingError(GmlElementIdentifier geometryElement, Exception e) { - // TODO Auto-generated method stub - } + @Override + public void parsingError( GmlElementIdentifier geometryElement, Exception e ) { + // TODO Auto-generated method stub + } - @Override - public boolean topologicalEvent(GmlGeometryValidationEvent event) { - events.add(event); - return false; - } + @Override + public boolean topologicalEvent( GmlGeometryValidationEvent event ) { + events.add( event ); + return false; + } - List getEvents() { - return events; - } + List getEvents() { + return events; + } } diff --git a/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_anticlockwise_interior_anticlockwise.gml b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_anticlockwise_interior_anticlockwise.gml new file mode 100644 index 0000000000..5107880a7c --- /dev/null +++ b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_anticlockwise_interior_anticlockwise.gml @@ -0,0 +1,13 @@ + + + + + 4570100 2886900 4570111 2886900 4570122 2886900 4570122 2886911 4570122 2886922 4570111 2886922 4570100 2886922 4570100 2886911 4570100 2886900 + + + + + 4570110 2886910 4570111 2886910 4570112 2886910 4570112 2886911 4570112 2886912 4570111 2886912 4570110 2886912 4570110 2886911 4570110 2886910 + + + diff --git a/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_anticlockwise_interior_clockwise.gml b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_anticlockwise_interior_clockwise.gml new file mode 100644 index 0000000000..ac3bf23760 --- /dev/null +++ b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_anticlockwise_interior_clockwise.gml @@ -0,0 +1,13 @@ + + + + + 4570100 2886900 4570111 2886900 4570122 2886900 4570122 2886911 4570122 2886922 4570111 2886922 4570100 2886922 4570100 2886911 4570100 2886900 + + + + + 4570110 2886910 4570110 2886911 4570110 2886912 4570111 2886912 4570112 2886912 4570112 2886911 4570112 2886910 4570111 2886910 4570110 2886910 + + + diff --git a/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_clockwise_interior_anticlockwise.gml b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_clockwise_interior_anticlockwise.gml new file mode 100644 index 0000000000..f274751123 --- /dev/null +++ b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_clockwise_interior_anticlockwise.gml @@ -0,0 +1,13 @@ + + + + + 4570100 2886900 4570100 2886911 4570100 2886922 4570111 2886922 4570122 2886922 4570122 2886911 4570122 2886900 4570111 2886900 4570100 2886900 + + + + + 4570110 2886910 4570111 2886910 4570112 2886910 4570112 2886911 4570112 2886912 4570111 2886912 4570110 2886912 4570110 2886911 4570110 2886910 + + + diff --git a/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_clockwise_interior_clockwise.gml b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_clockwise_interior_clockwise.gml new file mode 100644 index 0000000000..328e2070a1 --- /dev/null +++ b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/LeftHanded_exterior_clockwise_interior_clockwise.gml @@ -0,0 +1,13 @@ + + + + + 4570100 2886900 4570100 2886911 4570100 2886922 4570111 2886922 4570122 2886922 4570122 2886911 4570122 2886900 4570111 2886900 4570100 2886900 + + + + + 4570110 2886910 4570110 2886911 4570110 2886912 4570111 2886912 4570112 2886912 4570112 2886911 4570112 2886910 4570111 2886910 4570110 2886910 + + + diff --git a/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_anticlockwise_interior_anticlockwise.gml b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_anticlockwise_interior_anticlockwise.gml new file mode 100644 index 0000000000..e2298ed983 --- /dev/null +++ b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_anticlockwise_interior_anticlockwise.gml @@ -0,0 +1,13 @@ + + + + + 4570100 2886900 4570111 2886900 4570122 2886900 4570122 2886911 4570122 2886922 4570111 2886922 4570100 2886922 4570100 2886911 4570100 2886900 + + + + + 4570110 2886910 4570111 2886910 4570112 2886910 4570112 2886911 4570112 2886912 4570111 2886912 4570110 2886912 4570110 2886911 4570110 2886910 + + + diff --git a/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_anticlockwise_interior_clockwise.gml b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_anticlockwise_interior_clockwise.gml new file mode 100644 index 0000000000..76bfe07563 --- /dev/null +++ b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_anticlockwise_interior_clockwise.gml @@ -0,0 +1,13 @@ + + + + + 4570100 2886900 4570111 2886900 4570122 2886900 4570122 2886911 4570122 2886922 4570111 2886922 4570100 2886922 4570100 2886911 4570100 2886900 + + + + + 4570110 2886910 4570110 2886911 4570110 2886912 4570111 2886912 4570112 2886912 4570112 2886911 4570112 2886910 4570111 2886910 4570110 2886910 + + + diff --git a/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_clockwise_interior_anticlockwise.gml b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_clockwise_interior_anticlockwise.gml new file mode 100644 index 0000000000..31faacb126 --- /dev/null +++ b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_clockwise_interior_anticlockwise.gml @@ -0,0 +1,13 @@ + + + + + 4570100 2886900 4570100 2886911 4570100 2886922 4570111 2886922 4570122 2886922 4570122 2886911 4570122 2886900 4570111 2886900 4570100 2886900 + + + + + 4570110 2886910 4570111 2886910 4570112 2886910 4570112 2886911 4570112 2886912 4570111 2886912 4570110 2886912 4570110 2886911 4570110 2886910 + + + diff --git a/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_clockwise_interior_clockwise.gml b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_clockwise_interior_clockwise.gml new file mode 100644 index 0000000000..f54529fd09 --- /dev/null +++ b/deegree-core/deegree-core-base/src/test/resources/org/deegree/gml/misc/geometry/invalid/RightHanded_exterior_clockwise_interior_clockwise.gml @@ -0,0 +1,13 @@ + + + + + 4570100 2886900 4570100 2886911 4570100 2886922 4570111 2886922 4570122 2886922 4570122 2886911 4570122 2886900 4570111 2886900 4570100 2886900 + + + + + 4570110 2886910 4570110 2886911 4570110 2886912 4570111 2886912 4570112 2886912 4570112 2886911 4570112 2886910 4570111 2886910 4570110 2886910 + + + From bc3a3664d1f2477dda52cdb16376663e64c0165f Mon Sep 17 00:00:00 2001 From: Stephan Reichhelm Date: Wed, 9 Aug 2023 18:08:48 +0200 Subject: [PATCH 2/2] * fix formatting for current guidelines --- .../validation/GmlGeometryValidatorTest.java | 198 +++++++++--------- 1 file changed, 100 insertions(+), 98 deletions(-) diff --git a/deegree-core/deegree-core-base/src/test/java/org/deegree/geometry/gml/validation/GmlGeometryValidatorTest.java b/deegree-core/deegree-core-base/src/test/java/org/deegree/geometry/gml/validation/GmlGeometryValidatorTest.java index 7ca7ccfd76..01e27064f0 100644 --- a/deegree-core/deegree-core-base/src/test/java/org/deegree/geometry/gml/validation/GmlGeometryValidatorTest.java +++ b/deegree-core/deegree-core-base/src/test/java/org/deegree/geometry/gml/validation/GmlGeometryValidatorTest.java @@ -64,122 +64,124 @@ /** * Tests that check the expected generation of validation events by the * {@link GmlGeometryValidationEvent}. - * + * * @author Markus Schneider */ public class GmlGeometryValidatorTest { - private static final String BASE_DIR = "../misc/geometry/"; + private static final String BASE_DIR = "../misc/geometry/"; - @Test - public void validateCurve() + @Test + public void validateCurve() throws XMLStreamException, FactoryConfigurationError, IOException, ClassCastException, UnknownCRSException { - TestEventHandler eventHandler = validate( "Curve.gml" ); - assertEquals( 0, eventHandler.getEvents().size() ); - } + TestEventHandler eventHandler = validate("Curve.gml"); + assertEquals(0, eventHandler.getEvents().size()); + } - @Test - public void validateCurveDiscontinuity() + @Test + public void validateCurveDiscontinuity() throws XMLStreamException, FactoryConfigurationError, IOException, ClassCastException, UnknownCRSException { - TestEventHandler eventHandler = validate( "invalid/Curve_discontinuity.gml" ); - assertEquals( 1, eventHandler.getEvents().size() ); - GmlGeometryValidationEvent event = eventHandler.getEvents().get( 0 ); - Assert.assertEquals( CurveDiscontinuity.class, event.getEvent().getClass() ); - } - - @Test - public void validateRingNotClosed() - throws XMLStreamException, FactoryConfigurationError, IOException, UnknownCRSException { - TestEventHandler eventHandler = validate( "invalid/Ring_not_closed.gml" ); - assertEquals( 1, eventHandler.getEvents().size() ); - GmlGeometryValidationEvent event = eventHandler.getEvents().get( 0 ); - Assert.assertEquals( RingNotClosed.class, event.getEvent().getClass() ); - } - - @Test - public void validatePolygonExteriorClockwise() - throws XMLStreamException, FactoryConfigurationError, IOException, UnknownCRSException { - TestEventHandler eventHandler = validate( "invalid/Polygon_exterior_clockwise.gml" ); - assertEquals( 3, eventHandler.getEvents().size() ); - Assert.assertTrue( ( (ExteriorRingOrientation) ( eventHandler.getEvents().get( 0 ).getEvent() ) ).isClockwise() ); - Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler.getEvents().get( 1 ).getEvent() ) ).isClockwise() ); - Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler.getEvents().get( 2 ).getEvent() ) ).isClockwise() ); - } - - @Test - public void validateLeftHandRightHandClockwiseOrientation() - throws XMLStreamException, UnknownCRSException, FactoryConfigurationError, IOException { - TestEventHandler eventHandler = validate( "invalid/LeftHanded_exterior_clockwise_interior_clockwise.gml" ); - assertEquals( 2, eventHandler.getEvents().size() ); - Assert.assertTrue( ( (ExteriorRingOrientation) ( eventHandler.getEvents().get( 0 ).getEvent() ) ).isExterior() ); - Assert.assertFalse( ( (InteriorRingOrientation) ( eventHandler.getEvents().get( 1 ).getEvent() ) ).isInterior() ); - - TestEventHandler eventHandler2 = validate( "invalid/LeftHanded_exterior_clockwise_interior_anticlockwise.gml" ); - assertEquals( 2, eventHandler2.getEvents().size() ); - Assert.assertTrue( ( (ExteriorRingOrientation) ( eventHandler2.getEvents().get( 0 ).getEvent() ) ).isExterior() ); - Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler2.getEvents().get( 1 ).getEvent() ) ).isInterior() ); - - TestEventHandler eventHandler3 = validate( "invalid/LeftHanded_exterior_anticlockwise_interior_clockwise.gml" ); - assertEquals( 2, eventHandler3.getEvents().size() ); - Assert.assertFalse( ( (ExteriorRingOrientation) ( eventHandler3.getEvents().get( 0 ).getEvent() ) ).isExterior() ); - Assert.assertFalse( ( (InteriorRingOrientation) ( eventHandler3.getEvents().get( 1 ).getEvent() ) ).isInterior() ); - - TestEventHandler eventHandler4 = validate( "invalid/LeftHanded_exterior_anticlockwise_interior_anticlockwise.gml" ); - assertEquals( 2, eventHandler4.getEvents().size() ); - Assert.assertFalse( ( (ExteriorRingOrientation) ( eventHandler4.getEvents().get( 0 ).getEvent() ) ).isExterior() ); - Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler4.getEvents().get( 1 ).getEvent() ) ).isInterior() ); - - TestEventHandler eventHandler5 = validate( "invalid/RightHanded_exterior_clockwise_interior_clockwise.gml" ); - assertEquals( 2, eventHandler5.getEvents().size() ); - Assert.assertFalse( ( (ExteriorRingOrientation) ( eventHandler5.getEvents().get( 0 ).getEvent() ) ).isExterior() ); - Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler5.getEvents().get( 1 ).getEvent() ) ).isInterior() ); - - TestEventHandler eventHandler6 = validate( "invalid/RightHanded_exterior_clockwise_interior_anticlockwise.gml" ); - assertEquals( 2, eventHandler6.getEvents().size() ); - Assert.assertFalse( ( (ExteriorRingOrientation) ( eventHandler6.getEvents().get( 0 ).getEvent() ) ).isExterior() ); - Assert.assertFalse( ( (InteriorRingOrientation) ( eventHandler6.getEvents().get( 1 ).getEvent() ) ).isInterior() ); - - TestEventHandler eventHandler7 = validate( "invalid/RightHanded_exterior_anticlockwise_interior_clockwise.gml" ); - assertEquals( 2, eventHandler7.getEvents().size() ); - Assert.assertTrue( ( (ExteriorRingOrientation) ( eventHandler7.getEvents().get( 0 ).getEvent() ) ).isExterior() ); - Assert.assertTrue( ( (InteriorRingOrientation) ( eventHandler7.getEvents().get( 1 ).getEvent() ) ).isInterior() ); - - TestEventHandler eventHandler8 = validate( "invalid/RightHanded_exterior_anticlockwise_interior_anticlockwise.gml" ); - assertEquals( 2, eventHandler8.getEvents().size() ); - Assert.assertTrue( ( (ExteriorRingOrientation) ( eventHandler8.getEvents().get( 0 ).getEvent() ) ).isExterior() ); - Assert.assertFalse( ( (InteriorRingOrientation) ( eventHandler8.getEvents().get( 1 ).getEvent() ) ).isInterior() ); + TestEventHandler eventHandler = validate("invalid/Curve_discontinuity.gml"); + assertEquals(1, eventHandler.getEvents().size()); + GmlGeometryValidationEvent event = eventHandler.getEvents().get(0); + Assert.assertEquals(CurveDiscontinuity.class, event.getEvent().getClass()); + } + + @Test + public void validateRingNotClosed() + throws XMLStreamException, FactoryConfigurationError, IOException, UnknownCRSException { + TestEventHandler eventHandler = validate("invalid/Ring_not_closed.gml"); + assertEquals(1, eventHandler.getEvents().size()); + GmlGeometryValidationEvent event = eventHandler.getEvents().get(0); + Assert.assertEquals(RingNotClosed.class, event.getEvent().getClass()); + } + @Test + public void validatePolygonExteriorClockwise() + throws XMLStreamException, FactoryConfigurationError, IOException, UnknownCRSException { + TestEventHandler eventHandler = validate("invalid/Polygon_exterior_clockwise.gml"); + assertEquals(3, eventHandler.getEvents().size()); + Assert.assertTrue(((ExteriorRingOrientation) (eventHandler.getEvents().get(0).getEvent())).isClockwise()); + Assert.assertTrue(((InteriorRingOrientation) (eventHandler.getEvents().get(1).getEvent())).isClockwise()); + Assert.assertTrue(((InteriorRingOrientation) (eventHandler.getEvents().get(2).getEvent())).isClockwise()); } - private TestEventHandler validate( String resourceName ) - throws XMLStreamException, UnknownCRSException, FactoryConfigurationError, IOException { - TestEventHandler eventHandler = new TestEventHandler(); - URL resourceUrl = GML3GeometryReaderTest.class.getResource( BASE_DIR + resourceName ); - GMLStreamReader gmlStream = GMLInputFactory.createGMLStreamReader( GML_31, resourceUrl ); - GmlStreamGeometryValidator validator = new GmlStreamGeometryValidator( gmlStream, eventHandler ); - validator.validateGeometries(); - return eventHandler; - } + @Test + public void validateLeftHandRightHandClockwiseOrientation() + throws XMLStreamException, UnknownCRSException, FactoryConfigurationError, IOException { + TestEventHandler eventHandler = validate("invalid/LeftHanded_exterior_clockwise_interior_clockwise.gml"); + assertEquals(2, eventHandler.getEvents().size()); + Assert.assertTrue(((ExteriorRingOrientation) (eventHandler.getEvents().get(0).getEvent())).isExterior()); + Assert.assertFalse(((InteriorRingOrientation) (eventHandler.getEvents().get(1).getEvent())).isInterior()); + + TestEventHandler eventHandler2 = validate("invalid/LeftHanded_exterior_clockwise_interior_anticlockwise.gml"); + assertEquals(2, eventHandler2.getEvents().size()); + Assert.assertTrue(((ExteriorRingOrientation) (eventHandler2.getEvents().get(0).getEvent())).isExterior()); + Assert.assertTrue(((InteriorRingOrientation) (eventHandler2.getEvents().get(1).getEvent())).isInterior()); + + TestEventHandler eventHandler3 = validate("invalid/LeftHanded_exterior_anticlockwise_interior_clockwise.gml"); + assertEquals(2, eventHandler3.getEvents().size()); + Assert.assertFalse(((ExteriorRingOrientation) (eventHandler3.getEvents().get(0).getEvent())).isExterior()); + Assert.assertFalse(((InteriorRingOrientation) (eventHandler3.getEvents().get(1).getEvent())).isInterior()); + + TestEventHandler eventHandler4 = validate( + "invalid/LeftHanded_exterior_anticlockwise_interior_anticlockwise.gml"); + assertEquals(2, eventHandler4.getEvents().size()); + Assert.assertFalse(((ExteriorRingOrientation) (eventHandler4.getEvents().get(0).getEvent())).isExterior()); + Assert.assertTrue(((InteriorRingOrientation) (eventHandler4.getEvents().get(1).getEvent())).isInterior()); + + TestEventHandler eventHandler5 = validate("invalid/RightHanded_exterior_clockwise_interior_clockwise.gml"); + assertEquals(2, eventHandler5.getEvents().size()); + Assert.assertFalse(((ExteriorRingOrientation) (eventHandler5.getEvents().get(0).getEvent())).isExterior()); + Assert.assertTrue(((InteriorRingOrientation) (eventHandler5.getEvents().get(1).getEvent())).isInterior()); + + TestEventHandler eventHandler6 = validate("invalid/RightHanded_exterior_clockwise_interior_anticlockwise.gml"); + assertEquals(2, eventHandler6.getEvents().size()); + Assert.assertFalse(((ExteriorRingOrientation) (eventHandler6.getEvents().get(0).getEvent())).isExterior()); + Assert.assertFalse(((InteriorRingOrientation) (eventHandler6.getEvents().get(1).getEvent())).isInterior()); + + TestEventHandler eventHandler7 = validate("invalid/RightHanded_exterior_anticlockwise_interior_clockwise.gml"); + assertEquals(2, eventHandler7.getEvents().size()); + Assert.assertTrue(((ExteriorRingOrientation) (eventHandler7.getEvents().get(0).getEvent())).isExterior()); + Assert.assertTrue(((InteriorRingOrientation) (eventHandler7.getEvents().get(1).getEvent())).isInterior()); + + TestEventHandler eventHandler8 = validate( + "invalid/RightHanded_exterior_anticlockwise_interior_anticlockwise.gml"); + assertEquals(2, eventHandler8.getEvents().size()); + Assert.assertTrue(((ExteriorRingOrientation) (eventHandler8.getEvents().get(0).getEvent())).isExterior()); + Assert.assertFalse(((InteriorRingOrientation) (eventHandler8.getEvents().get(1).getEvent())).isInterior()); + + } + + private TestEventHandler validate(String resourceName) + throws XMLStreamException, UnknownCRSException, FactoryConfigurationError, IOException { + TestEventHandler eventHandler = new TestEventHandler(); + URL resourceUrl = GML3GeometryReaderTest.class.getResource(BASE_DIR + resourceName); + GMLStreamReader gmlStream = GMLInputFactory.createGMLStreamReader(GML_31, resourceUrl); + GmlStreamGeometryValidator validator = new GmlStreamGeometryValidator(gmlStream, eventHandler); + validator.validateGeometries(); + return eventHandler; + } } class TestEventHandler implements GmlGeometryValidationEventHandler { - private final List events = new ArrayList(); + private final List events = new ArrayList(); - @Override - public void parsingError( GmlElementIdentifier geometryElement, Exception e ) { - // TODO Auto-generated method stub - } + @Override + public void parsingError(GmlElementIdentifier geometryElement, Exception e) { + // TODO Auto-generated method stub + } - @Override - public boolean topologicalEvent( GmlGeometryValidationEvent event ) { - events.add( event ); - return false; - } + @Override + public boolean topologicalEvent(GmlGeometryValidationEvent event) { + events.add(event); + return false; + } - List getEvents() { - return events; - } + List getEvents() { + return events; + } }