diff --git a/deegree-core/deegree-core-base/pom.xml b/deegree-core/deegree-core-base/pom.xml index eb23537860..c417489f0a 100644 --- a/deegree-core/deegree-core-base/pom.xml +++ b/deegree-core/deegree-core-base/pom.xml @@ -36,10 +36,14 @@ org.mockito mockito-core - + + + org.xmlunit + xmlunit-core + - org.xmlmatchers - xml-matchers + org.xmlunit + xmlunit-matchers diff --git a/deegree-core/deegree-core-base/src/test/java/org/deegree/filter/xml/Filter200XMLEncoderParameterizedTest.java b/deegree-core/deegree-core-base/src/test/java/org/deegree/filter/xml/Filter200XMLEncoderParameterizedTest.java index 17b2e7f850..a053534d22 100644 --- a/deegree-core/deegree-core-base/src/test/java/org/deegree/filter/xml/Filter200XMLEncoderParameterizedTest.java +++ b/deegree-core/deegree-core-base/src/test/java/org/deegree/filter/xml/Filter200XMLEncoderParameterizedTest.java @@ -35,16 +35,14 @@ ----------------------------------------------------------------------------*/ package org.deegree.filter.xml; -import static org.apache.commons.io.IOUtils.toInputStream; -import static org.junit.Assert.assertThat; -import static org.xmlmatchers.XmlMatchers.isSimilarTo; -import static org.xmlmatchers.transform.XmlConverters.the; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; +import org.apache.commons.io.IOUtils; +import org.deegree.commons.xml.stax.IndentingXMLStreamWriter; +import org.deegree.filter.Filter; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.xmlunit.matchers.CompareMatcher; import javax.xml.stream.FactoryConfigurationError; import javax.xml.stream.XMLInputFactory; @@ -52,14 +50,15 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; -import org.apache.commons.io.IOUtils; -import org.deegree.commons.xml.stax.IndentingXMLStreamWriter; -import org.deegree.filter.Filter; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.commons.io.IOUtils.toInputStream; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author Lyn Goltz @@ -78,7 +77,7 @@ public Filter200XMLEncoderParameterizedTest( String testName, String filterUnder @Parameters public static List data() - throws IOException { + throws IOException { List filterTests = new ArrayList(); filterTests.add( new Object[] { "testfilter1.xml", asString( "v200/testfilter1.xml" ) } ); filterTests.add( new Object[] { "testfilter3.xml", asString( "v200/testfilter3.xml" ) } ); @@ -99,7 +98,7 @@ public static List data() @Test public void testExport() - throws Exception { + throws Exception { Filter filter = parseFilter( filterUnderTest ); ByteArrayOutputStream bos = new ByteArrayOutputStream(); @@ -108,18 +107,20 @@ public void testExport() Filter200XMLEncoder.export( filter, writer ); out.close(); - assertThat( "Failed test: " + testName, the( bos.toString() ), isSimilarTo( the( filterUnderTest ) ) ); + assertThat( "Failed test: " + testName, bos.toString(), + CompareMatcher.isSimilarTo( filterUnderTest ).ignoreWhitespace() ); } private static String asString( String filterResource ) - throws IOException { + throws IOException { InputStream resourceAsStream = Filter200XMLEncoderParameterizedTest.class.getResourceAsStream( filterResource ); - return IOUtils.toString( resourceAsStream ); + return IOUtils.toString( resourceAsStream, UTF_8 ); } private Filter parseFilter( String filterAsString ) - throws XMLStreamException, FactoryConfigurationError { - XMLStreamReader in = XMLInputFactory.newInstance().createXMLStreamReader( toInputStream( filterAsString ) ); + throws XMLStreamException, FactoryConfigurationError { + XMLStreamReader in = XMLInputFactory.newInstance().createXMLStreamReader( + toInputStream( filterAsString, UTF_8 ) ); in.nextTag(); return Filter200XMLDecoder.parse( in ); } diff --git a/deegree-core/deegree-core-base/src/test/java/org/deegree/gml/schema/GMLAppSchemaWriterTest.java b/deegree-core/deegree-core-base/src/test/java/org/deegree/gml/schema/GMLAppSchemaWriterTest.java index 24d6290be6..47cbce50aa 100644 --- a/deegree-core/deegree-core-base/src/test/java/org/deegree/gml/schema/GMLAppSchemaWriterTest.java +++ b/deegree-core/deegree-core-base/src/test/java/org/deegree/gml/schema/GMLAppSchemaWriterTest.java @@ -43,9 +43,8 @@ import org.deegree.gml.GMLVersion; import org.junit.Test; import org.slf4j.Logger; -import org.xmlmatchers.namespace.SimpleNamespaceContext; +import org.xmlunit.matchers.EvaluateXPathMatcher; -import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.QName; import javax.xml.stream.FactoryConfigurationError; import javax.xml.stream.XMLOutputFactory; @@ -56,23 +55,21 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.slf4j.LoggerFactory.getLogger; -import static org.xmlmatchers.XmlMatchers.hasXPath; -import static org.xmlmatchers.transform.XmlConverters.the; -import static org.xmlmatchers.xpath.XpathReturnType.returningANumber; /** * TODO add documentation here * * @author Markus Schneider * @author last edited by: $Author:$ - * * @version $Revision:$, $Date:$ */ public class GMLAppSchemaWriterTest { @@ -81,18 +78,21 @@ public class GMLAppSchemaWriterTest { @Test public void testPhilosopher() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, - this.getClass().getResource( "../misc/schema/Philosopher.xsd" ).toString() ); - List featureElementDecls = analyzer.getFeatureElementDeclarations( "http://www.deegree.org/app", - false ); + this.getClass().getResource( + "../misc/schema/Philosopher.xsd" ).toString() ); + List featureElementDecls = analyzer.getFeatureElementDeclarations( + "http://www.deegree.org/app", + false ); for ( XSElementDeclaration featureElementDecl : featureElementDecls ) { LOG.debug( "- Feature type: " + featureElementDecl.getName() ); } - List featureCollectionElementDecls = analyzer.getFeatureCollectionElementDeclarations( null, - false ); + List featureCollectionElementDecls = analyzer.getFeatureCollectionElementDeclarations( + null, + false ); for ( XSElementDeclaration featureCollectionElementDecl : featureCollectionElementDecls ) { LOG.debug( "- Feature collection type: " + featureCollectionElementDecl.getName() ); } @@ -108,8 +108,8 @@ public void testPhilosopher() @Test public void testPhilosopherAndWFS() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = this.getClass().getResource( "../misc/schema/Philosopher.xsd" ).toString(); String schemaURL2 = "http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"; @@ -120,8 +120,8 @@ public void testPhilosopherAndWFS() @Test public void testGML311AggregateElements() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); @@ -134,8 +134,8 @@ public void testGML311AggregateElements() @Test public void testGML311PrimitiveElements() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); @@ -148,8 +148,8 @@ public void testGML311PrimitiveElements() @Test public void testGML311ImplicitGeometryElements() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); @@ -162,8 +162,8 @@ public void testGML311ImplicitGeometryElements() @Test public void testGML311GeometryElements() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); @@ -176,8 +176,8 @@ public void testGML311GeometryElements() @Test public void testGML311CurveElements() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); @@ -191,8 +191,8 @@ public void testGML311CurveElements() @Test public void testGML311RingElements() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); @@ -204,8 +204,8 @@ public void testGML311RingElements() @Test public void testGML311SurfaceElements() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); @@ -222,8 +222,8 @@ public void testGML311SurfaceElements() @Test public void testGML311SolidElements() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); @@ -235,8 +235,8 @@ public void testGML311SolidElements() @Test public void testGML311CurveSegments() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); @@ -250,8 +250,8 @@ public void testGML311CurveSegments() @Test public void testGML311SurfacePatches() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); @@ -265,14 +265,14 @@ public void testGML311SurfacePatches() @Test public void testGML321CurveSegments() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.2.1/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); List elementDecls = analyzer.getSubstitutions( new QName( - "http://www.opengis.net/gml/3.2", - "AbstractCurveSegment" ), + "http://www.opengis.net/gml/3.2", + "AbstractCurveSegment" ), "http://www.opengis.net/gml/3.2", true, true ); for ( XSElementDeclaration elementDecl : elementDecls ) { @@ -282,14 +282,14 @@ public void testGML321CurveSegments() @Test public void testGML321SurfacePatches() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.2.1/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); List elementDecls = analyzer.getSubstitutions( new QName( - "http://www.opengis.net/gml/3.2", - "AbstractSurfacePatch" ), + "http://www.opengis.net/gml/3.2", + "AbstractSurfacePatch" ), "http://www.opengis.net/gml/3.2", true, true ); for ( XSElementDeclaration elementDecl : elementDecls ) { @@ -299,14 +299,14 @@ public void testGML321SurfacePatches() @Test public void testGML321GeometryElements() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException { String schemaURL = "http://schemas.opengis.net/gml/3.2.1/gml.xsd"; GMLSchemaInfoSet analyzer = new GMLSchemaInfoSet( null, schemaURL ); List elementDecls = analyzer.getSubstitutions( new QName( - "http://www.opengis.net/gml/3.2", - "AbstractGeometry" ), + "http://www.opengis.net/gml/3.2", + "AbstractGeometry" ), "http://www.opengis.net/gml/3.2", true, true ); for ( XSElementDeclaration elementDecl : elementDecls ) { @@ -328,8 +328,8 @@ private Set getConcreteSubstitutions( String localName, GMLSchemaInfoSet @Test public void testReexportCiteSF1() - throws ClassCastException, ClassNotFoundException, InstantiationException, - IllegalAccessException, XMLStreamException, FactoryConfigurationError, IOException { + throws ClassCastException, ClassNotFoundException, InstantiationException, + IllegalAccessException, XMLStreamException, FactoryConfigurationError, IOException { String schemaURL = this.getClass().getResource( "../cite/schema/cite-gmlsf1.xsd" ).toString(); GMLAppSchemaReader adapter = new GMLAppSchemaReader( GMLVersion.GML_31, null, schemaURL ); @@ -337,7 +337,8 @@ public void testReexportCiteSF1() XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty( XMLOutputFactory.IS_REPAIRING_NAMESPACES, true ); - OutputStream os = new FileOutputStream( System.getProperty( "java.io.tmpdir" ) + File.separatorChar + "out.xml" ); + OutputStream os = new FileOutputStream( + System.getProperty( "java.io.tmpdir" ) + File.separatorChar + "out.xml" ); XMLStreamWriter writer = new IndentingXMLStreamWriter( outputFactory.createXMLStreamWriter( os ) ); GMLAppSchemaWriter encoder = new GMLAppSchemaWriter( GMLVersion.GML_31, "http://cite.opengeospatial.org/gmlsf", null, schema.getNamespaceBindings() ); @@ -363,8 +364,10 @@ public void testExportSchemaWrappped() encoder.export( writer, gmlSchemaInfoSet, "http://cite.opengeospatial.org/gmlsf", uri -> uri ); writer.close(); - assertThat( the( os.toString() ), - hasXPath( "count(/xs:schema/xs:include)", nsContext(), returningANumber(), is( 2.0 ) ) ); + assertThat( os.toString(), + EvaluateXPathMatcher.hasXPath( "count(/xs:schema/xs:include)", is( "2" ) ).withNamespaceContext( + nsContext() ) ); + } @Test @@ -389,8 +392,8 @@ public void testExportSchema() System.out.println( os.toString() ); } - private NamespaceContext nsContext() { - return new SimpleNamespaceContext().withBinding( "xs", "http://www.w3.org/2001/XMLSchema" ); + private Map nsContext() { + return Collections.singletonMap( "xs", "http://www.w3.org/2001/XMLSchema" ); } } diff --git a/deegree-core/deegree-core-commons/pom.xml b/deegree-core/deegree-core-commons/pom.xml index ec57b47664..97dff1c8a5 100644 --- a/deegree-core/deegree-core-commons/pom.xml +++ b/deegree-core/deegree-core-commons/pom.xml @@ -110,5 +110,13 @@ junit junit + + org.xmlunit + xmlunit-core + + + org.xmlunit + xmlunit-matchers + \ No newline at end of file diff --git a/deegree-core/deegree-core-commons/src/test/java/org/deegree/commons/xml/stax/FilteringXMLStreamWriterTest.java b/deegree-core/deegree-core-commons/src/test/java/org/deegree/commons/xml/stax/FilteringXMLStreamWriterTest.java index 5b40fcf731..ebe54f0e81 100644 --- a/deegree-core/deegree-core-commons/src/test/java/org/deegree/commons/xml/stax/FilteringXMLStreamWriterTest.java +++ b/deegree-core/deegree-core-commons/src/test/java/org/deegree/commons/xml/stax/FilteringXMLStreamWriterTest.java @@ -35,30 +35,27 @@ ----------------------------------------------------------------------------*/ package org.deegree.commons.xml.stax; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - import org.apache.commons.io.IOUtils; import org.deegree.commons.xml.NamespaceBindings; import org.deegree.commons.xml.XMLAdapter; import org.deegree.commons.xml.XPath; -import org.junit.Assert; import org.junit.Test; +import org.xmlunit.matchers.CompareMatcher; + +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.hamcrest.MatcherAssert.assertThat; /** - * * @author Andreas Schmitz * @author last edited by: $Author: stranger $ - * * @version $Revision: $, $Date: $ */ public class FilteringXMLStreamWriterTest { @@ -70,6 +67,7 @@ public class FilteringXMLStreamWriterTest { private final static String alles = "http://www.deegree.org/alles"; private static final NamespaceBindings nsBindings = new NamespaceBindings(); + static { nsBindings.addNamespace( "app", app ); nsBindings.addNamespace( "nix", nix ); @@ -77,7 +75,7 @@ public class FilteringXMLStreamWriterTest { } private void writeDocument( XMLStreamWriter writer ) - throws XMLStreamException { + throws XMLStreamException { writer.writeStartDocument(); writer.setPrefix( "app", app ); writer.setPrefix( "nix", nix ); @@ -104,7 +102,7 @@ private void writeDocument( XMLStreamWriter writer ) } private XMLStreamWriter getWriter( List paths, OutputStream stream ) - throws Exception { + throws Exception { XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter( stream ); writer = new IndentingXMLStreamWriter( writer ); List xpaths = new ArrayList(); @@ -117,70 +115,73 @@ private XMLStreamWriter getWriter( List paths, OutputStream stream ) @Test public void testFilteringOneXPath() - throws Exception { - List list = new ArrayList(); + throws Exception { + List list = new ArrayList<>(); list.add( "/app:a/app:b/nix:c/app:b" ); ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLStreamWriter writer = getWriter( list, bos ); writeDocument( writer ); - byte[] actual = bos.toByteArray(); - byte[] expected = IOUtils.toByteArray( FilteringXMLStreamWriterTest.class.getResourceAsStream( "filteringxpathone.xml" ) ); - Assert.assertArrayEquals( expected, actual ); + String actual = bos.toString(); + String expected = IOUtils.toString( FilteringXMLStreamWriterTest.class.getResourceAsStream( + "filteringxpathone.xml" ), UTF_8 ); + assertThat( actual, CompareMatcher.isSimilarTo( expected ).ignoreWhitespace() ); } @Test public void testFilteringMultipleXPaths() - throws Exception { - List list = new ArrayList(); + throws Exception { + List list = new ArrayList<>(); list.add( "/app:a/app:b/nix:c/app:d" ); list.add( "/app:a/app:b/nix:c/app:b" ); ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLStreamWriter writer = getWriter( list, bos ); writeDocument( writer ); - byte[] actual = bos.toByteArray(); - byte[] expected = IOUtils.toByteArray( FilteringXMLStreamWriterTest.class.getResourceAsStream( "filteringxpathmultiple.xml" ) ); - Assert.assertArrayEquals( expected, actual ); + String actual = bos.toString(); + String expected = IOUtils.toString( FilteringXMLStreamWriterTest.class.getResourceAsStream( + "filteringxpathmultiple.xml" ), UTF_8 ); + assertThat( actual, CompareMatcher.isSimilarTo( expected ).ignoreWhitespace() ); } @Test public void testFilteringMultipleXPathsWithText() - throws Exception { - List list = new ArrayList(); + throws Exception { + List list = new ArrayList<>(); list.add( "/app:a/app:b/nix:c/alles:e" ); list.add( "/app:a/app:b/nix:c/app:b" ); list.add( "/app:a/app:b/nix:c/falsch:d" ); ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLStreamWriter writer = getWriter( list, bos ); writeDocument( writer ); - byte[] actual = bos.toByteArray(); - byte[] expected = IOUtils.toByteArray( FilteringXMLStreamWriterTest.class.getResourceAsStream( "filteringxpathmultiplewithtext.xml" ) ); - Assert.assertArrayEquals( expected, actual ); + String actual = bos.toString(); + String expected = IOUtils.toString( FilteringXMLStreamWriterTest.class.getResourceAsStream( + "filteringxpathmultiplewithtext.xml" ), UTF_8 ); + assertThat( actual, CompareMatcher.isSimilarTo( expected ).ignoreWhitespace() ); } @Test(expected = XMLStreamException.class) public void testFilteringOneXPathWithoutMatchingRootElement() - throws Exception { - List list = new ArrayList(); + throws Exception { + List list = new ArrayList<>(); list.add( "/ap:a/app:c" ); ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLStreamWriter writer = getWriter( list, bos ); writeDocument( writer ); - byte[] actual = bos.toByteArray(); - Assert.assertEquals( 0, actual.length ); } @Test public void testFilteringXPathSetPrefixBug() - throws Exception { - final XMLAdapter input = new XMLAdapter( FilteringXMLStreamWriterTest.class.getResourceAsStream( "filtering_xpath_set_prefix.xml" ) ); - final List list = new ArrayList(); + throws Exception { + final XMLAdapter input = new XMLAdapter( + FilteringXMLStreamWriterTest.class.getResourceAsStream( "filtering_xpath_set_prefix.xml" ) ); + final List list = new ArrayList<>(); list.add( "/app:a/nix:d" ); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final XMLStreamWriter writer = getWriter( list, bos ); input.getRootElement().serialize( writer ); writer.close(); - byte[] actual = bos.toByteArray(); - byte[] expected = IOUtils.toByteArray( FilteringXMLStreamWriterTest.class.getResourceAsStream( "filtering_xpath_set_prefix_expected.xml" ) ); - Assert.assertArrayEquals( expected, actual ); + String actual = bos.toString(); + String expected = IOUtils.toString( FilteringXMLStreamWriterTest.class.getResourceAsStream( + "filtering_xpath_set_prefix_expected.xml" ), UTF_8 ); + assertThat( actual, CompareMatcher.isSimilarTo( expected ).ignoreWhitespace() ); } } diff --git a/deegree-core/deegree-core-protocol/deegree-protocol-wfs/pom.xml b/deegree-core/deegree-core-protocol/deegree-protocol-wfs/pom.xml index bf0f426e35..be4cf38c5f 100644 --- a/deegree-core/deegree-core-protocol/deegree-protocol-wfs/pom.xml +++ b/deegree-core/deegree-core-protocol/deegree-protocol-wfs/pom.xml @@ -30,8 +30,12 @@ mockito-core - org.xmlmatchers - xml-matchers + org.xmlunit + xmlunit-core + + + org.xmlunit + xmlunit-matchers diff --git a/deegree-core/deegree-core-protocol/deegree-protocol-wfs/src/test/java/org/deegree/protocol/wfs/storedquery/xml/StoredQueryDefinition200EncoderTest.java b/deegree-core/deegree-core-protocol/deegree-protocol-wfs/src/test/java/org/deegree/protocol/wfs/storedquery/xml/StoredQueryDefinition200EncoderTest.java index e773159cd2..4091ece208 100644 --- a/deegree-core/deegree-core-protocol/deegree-protocol-wfs/src/test/java/org/deegree/protocol/wfs/storedquery/xml/StoredQueryDefinition200EncoderTest.java +++ b/deegree-core/deegree-core-protocol/deegree-protocol-wfs/src/test/java/org/deegree/protocol/wfs/storedquery/xml/StoredQueryDefinition200EncoderTest.java @@ -35,45 +35,33 @@ ----------------------------------------------------------------------------*/ package org.deegree.protocol.wfs.storedquery.xml; -import static org.deegree.protocol.wfs.WFSConstants.WFS_200_NS; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.xmlmatchers.XmlMatchers.hasXPath; -import static org.xmlmatchers.XmlMatchers.isSimilarTo; -import static org.xmlmatchers.transform.XmlConverters.xml; - -import java.io.IOException; -import java.io.InputStream; +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.deegree.protocol.wfs.storedquery.StoredQueryDefinition; +import org.junit.Test; +import org.xmlunit.matchers.CompareMatcher; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.Map; -import org.apache.commons.io.output.ByteArrayOutputStream; -import org.deegree.commons.xml.NamespaceBindings; -import org.deegree.protocol.wfs.storedquery.StoredQueryDefinition; -import org.deegree.protocol.wfs.storedquery.xml.StoredQueryDefinition200Encoder; -import org.deegree.protocol.wfs.storedquery.xml.StoredQueryDefinitionXMLAdapter; -import org.junit.BeforeClass; -import org.junit.Test; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.deegree.protocol.wfs.WFSConstants.WFS_200_NS; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.xmlunit.matchers.EvaluateXPathMatcher.hasXPath; /** * @author Lyn Goltz */ public class StoredQueryDefinition200EncoderTest { - private static final NamespaceBindings NS_CONTEXT = new NamespaceBindings(); - - @BeforeClass - public static void initNamespaceContext() - throws IOException { - NS_CONTEXT.addNamespace( "wfs", WFS_200_NS ); - } - @Test public void testExport() - throws Exception { + throws Exception { String storedQueryResource = "storedQuery.xml"; StoredQueryDefinition queryDefinition = parseStoredQueryDefinition( storedQueryResource ); @@ -82,18 +70,21 @@ public void testExport() StoredQueryDefinition200Encoder.export( queryDefinition, writer ); writer.close(); - assertThat( xml( stream.toString() ), - hasXPath( "/wfs:StoredQueryDefinition/wfs:QueryExpressionText/wfs:Query/@typeNames", - is( "cp:CadastralParcel" ), NS_CONTEXT ) ); - - assertThat( xml( stream.toString() ), - hasXPath( "/wfs:StoredQueryDefinition/wfs:Parameter/@name", is( "label" ), NS_CONTEXT ) ); - - assertThat( xml( stream.toString() ), isSimilarTo( the( storedQueryResource ) ) ); + String actual = stream.toString( UTF_8 ); + assertThat( actual, + hasXPath( + "/wfs:StoredQueryDefinition/wfs:QueryExpressionText/wfs:Query/@typeNames", + is( "cp:CadastralParcel" ) ).withNamespaceContext( nsContext() ) ); + assertThat( actual, + hasXPath( "/wfs:StoredQueryDefinition/wfs:Parameter/@name", is( "label" ) ).withNamespaceContext( + nsContext() ) ); + assertThat( actual, CompareMatcher.isSimilarTo( + IOUtils.toString( getClass().getResourceAsStream( storedQueryResource ), + UTF_8 ) ).ignoreWhitespace() ); } private StoredQueryDefinition parseStoredQueryDefinition( String resource ) - throws IOException { + throws IOException { InputStream storedQueryResource = StoredQueryDefinition200EncoderTest.class.getResourceAsStream( resource ); StoredQueryDefinitionXMLAdapter storedQueryXMLAdapter = new StoredQueryDefinitionXMLAdapter(); storedQueryXMLAdapter.load( storedQueryResource ); @@ -102,9 +93,8 @@ private StoredQueryDefinition parseStoredQueryDefinition( String resource ) return queryDefinition; } - private Source the( String resource ) { - InputStream inputStream = StoredQueryDefinition200EncoderTest.class.getResourceAsStream( resource ); - return new StreamSource( inputStream ); + private Map nsContext() { + return Collections.singletonMap( "wfs", WFS_200_NS ); } } \ No newline at end of file diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/pom.xml b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/pom.xml index ea58dfab72..664a3c5ec7 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/pom.xml +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/pom.xml @@ -56,8 +56,12 @@ mockito-core - org.xmlmatchers - xml-matchers + org.xmlunit + xmlunit-core + + + org.xmlunit + xmlunit-matchers org.antlr diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/org/deegree/feature/persistence/sql/config/SQLFeatureStoreConfigWriterIT.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/org/deegree/feature/persistence/sql/config/SQLFeatureStoreConfigWriterIT.java index 7457c0980e..ecfa068bcf 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/org/deegree/feature/persistence/sql/config/SQLFeatureStoreConfigWriterIT.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/org/deegree/feature/persistence/sql/config/SQLFeatureStoreConfigWriterIT.java @@ -1,6 +1,5 @@ package org.deegree.feature.persistence.sql.org.deegree.feature.persistence.sql.config; -import org.deegree.commons.xml.NamespaceBindings; import org.deegree.commons.xml.stax.IndentingXMLStreamWriter; import org.deegree.cs.coordinatesystems.ICRS; import org.deegree.cs.persistence.CRSManager; @@ -11,30 +10,24 @@ import org.deegree.feature.types.AppSchema; import org.deegree.gml.schema.GMLAppSchemaReader; import org.junit.Test; -import org.xml.sax.SAXException; -import org.xmlmatchers.validation.SchemaFactory; +import org.xmlunit.builder.Input; import javax.xml.stream.FactoryConfigurationError; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; -import static org.deegree.commons.xml.CommonNamespaces.getNamespaceContext; import static org.deegree.feature.types.property.GeometryPropertyType.CoordinateDimension.DIM_2; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.xmlmatchers.XmlMatchers.conformsTo; -import static org.xmlmatchers.XmlMatchers.hasXPath; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.xmlunit.matchers.EvaluateXPathMatcher.hasXPath; +import static org.xmlunit.matchers.ValidationMatcher.valid; /** * @author Lyn Goltz @@ -45,62 +38,36 @@ public class SQLFeatureStoreConfigWriterIT { private static final String UNDEFINED_SRID_POSTGRES = "0"; - private static final NamespaceBindings NAMESPACE_CONTEXT = getNamespaceContext(); - - static { - NAMESPACE_CONTEXT.addNamespace( "fsc", "http://www.deegree.org/datasource/feature/sql" ); - } - @Test public void testWriteConfig() - throws Exception { + throws Exception { URL appSchemaResource = new URL( "http://inspire.ec.europa.eu/schemas/ps/4.0/ProtectedSites.xsd" ); List schemaUrls = new ArrayList(); AppSchema appSchema = readApplicationSchema( appSchemaResource ); MappedAppSchema mappedSchema = mapApplicationSchema( appSchema ); - byte[] config = writeConfig( mappedSchema, schemaUrls ); - - assertThat( the( config ), hasXPath( "/fsc:SQLFeatureStore/@configVersion", - NAMESPACE_CONTEXT, is( "3.4.0" ) ) ); - assertThat( the( config ), conformsTo( sqlFeatureStore34Schema() ) ); - } - - private Source the( byte[] config ) { - StreamSource streamSource = new StreamSource(); - streamSource.setInputStream( new ByteArrayInputStream( config ) ); - return streamSource; - } - - private Schema sqlFeatureStore34Schema() - throws SAXException { + String config = writeConfig( mappedSchema, schemaUrls ); - URL schemaResource = SQLFeatureStoreConfigWriterIT.class.getResource( - "/META-INF/schemas/datasource/feature/sql/3.4.0/sql.xsd" ); - return SchemaFactory.w3cXmlSchemaFrom( schemaResource ); + assertThat( config, hasXPath( "/fsc:SQLFeatureStore/@configVersion", + is( "3.4.0" ) ).withNamespaceContext( nsContext() ) ); + assertThat( config, valid( Input.fromStream( getClass().getResourceAsStream( + "/META-INF/schemas/datasource/feature/sql/3.4.0/sql.xsd" ) ) ) ); } private static AppSchema readApplicationSchema( URL schemaUrl ) - throws ClassNotFoundException, InstantiationException, IllegalAccessException, - MalformedURLException { + throws ClassNotFoundException, InstantiationException, IllegalAccessException { GMLAppSchemaReader decoder = new GMLAppSchemaReader( null, null, schemaUrl.toString() ); return decoder.extractAppSchema(); } - private static byte[] writeConfig( MappedAppSchema mappedSchema, List schemaUrls ) - throws IOException, XMLStreamException, FactoryConfigurationError { + private static String writeConfig( MappedAppSchema mappedSchema, List schemaUrls ) + throws XMLStreamException, FactoryConfigurationError { SQLFeatureStoreConfigWriter configWriter = new SQLFeatureStoreConfigWriter( mappedSchema ); ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( bos ); xmlWriter = new IndentingXMLStreamWriter( xmlWriter ); configWriter.writeConfig( xmlWriter, "jdbcId", schemaUrls ); xmlWriter.close(); - return bos.toByteArray(); - } - - private static StreamSource asSource( byte[] bytes ) { - StreamSource streamSource = new StreamSource(); - streamSource.setInputStream( new ByteArrayInputStream( bytes ) ); - return streamSource; + return bos.toString(); } private static MappedAppSchema mapApplicationSchema( AppSchema appSchema ) { @@ -113,4 +80,8 @@ private static MappedAppSchema mapApplicationSchema( AppSchema appSchema ) { return mapper.getMappedSchema(); } + private Map nsContext() { + return Collections.singletonMap( "fsc", "http://www.deegree.org/datasource/feature/sql" ); + } + } \ No newline at end of file diff --git a/deegree-services/deegree-services-wfs/pom.xml b/deegree-services/deegree-services-wfs/pom.xml index 247d7e6e2b..3a358f7d93 100644 --- a/deegree-services/deegree-services-wfs/pom.xml +++ b/deegree-services/deegree-services-wfs/pom.xml @@ -58,8 +58,12 @@ mockito-core - org.xmlmatchers - xml-matchers + org.xmlunit + xmlunit-core + + + org.xmlunit + xmlunit-matchers diff --git a/deegree-services/deegree-services-wfs/src/test/java/org/deegree/services/wfs/query/StoredQueryHandlerTest.java b/deegree-services/deegree-services-wfs/src/test/java/org/deegree/services/wfs/query/StoredQueryHandlerTest.java index 64a4bbef0e..da248cdc02 100644 --- a/deegree-services/deegree-services-wfs/src/test/java/org/deegree/services/wfs/query/StoredQueryHandlerTest.java +++ b/deegree-services/deegree-services-wfs/src/test/java/org/deegree/services/wfs/query/StoredQueryHandlerTest.java @@ -35,19 +35,23 @@ ----------------------------------------------------------------------------*/ package org.deegree.services.wfs.query; -import static org.deegree.protocol.wfs.WFSConstants.VERSION_200; -import static org.deegree.protocol.wfs.WFSConstants.WFS_200_NS; -import static org.deegree.services.wfs.query.StoredQueryHandler.GET_FEATURE_BY_ID; -import static org.deegree.services.wfs.query.StoredQueryHandler.GET_FEATURE_BY_TYPE; -import static org.hamcrest.CoreMatchers.hasItems; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.xmlmatchers.XmlMatchers.hasXPath; -import static org.xmlmatchers.transform.XmlConverters.xml; +import org.apache.commons.io.IOUtils; +import org.deegree.commons.ows.exception.OWSException; +import org.deegree.feature.types.FeatureType; +import org.deegree.protocol.wfs.storedquery.CreateStoredQuery; +import org.deegree.protocol.wfs.storedquery.DropStoredQuery; +import org.deegree.protocol.wfs.storedquery.QueryExpressionText; +import org.deegree.protocol.wfs.storedquery.StoredQueryDefinition; +import org.deegree.services.controller.utils.HttpResponseBuffer; +import org.deegree.services.wfs.WebFeatureService; +import org.deegree.services.wfs.WfsFeatureStoreManager; +import org.junit.Before; +import org.junit.Test; +import org.xmlunit.matchers.HasXPathMatcher; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -61,43 +65,28 @@ import java.util.Collections; import java.util.List; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.commons.io.IOUtils; -import org.deegree.commons.ows.exception.OWSException; -import org.deegree.commons.xml.NamespaceBindings; -import org.deegree.feature.types.FeatureType; -import org.deegree.protocol.wfs.storedquery.CreateStoredQuery; -import org.deegree.protocol.wfs.storedquery.DropStoredQuery; -import org.deegree.protocol.wfs.storedquery.QueryExpressionText; -import org.deegree.protocol.wfs.storedquery.StoredQueryDefinition; -import org.deegree.services.controller.utils.HttpResponseBuffer; -import org.deegree.services.wfs.WebFeatureService; -import org.deegree.services.wfs.WfsFeatureStoreManager; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.deegree.protocol.wfs.WFSConstants.VERSION_200; +import static org.deegree.protocol.wfs.WFSConstants.WFS_200_NS; +import static org.deegree.services.wfs.query.StoredQueryHandler.GET_FEATURE_BY_ID; +import static org.deegree.services.wfs.query.StoredQueryHandler.GET_FEATURE_BY_TYPE; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.xmlunit.matchers.HasXPathMatcher.hasXPath; /** * @author Lyn Goltz */ public class StoredQueryHandlerTest { - private static final NamespaceBindings NS_CONTEXT = new NamespaceBindings(); - private static File managedStoredQueries; - @BeforeClass - public static void initNamespaceContext() - throws IOException { - NS_CONTEXT.addNamespace( "wfs", WFS_200_NS ); - } - @Before public void createManagedStoredQueriesDirectory() - throws IOException { + throws IOException { managedStoredQueries = Files.createTempDirectory( "managedStoredQueries" ).toFile(); managedStoredQueries.deleteOnExit(); } @@ -109,7 +98,8 @@ public void testCollectAndSortFeatureTypesToExport_AllFeatureTypes() { managedStoredQueries ); List configuredFeatureTypeNames = Collections.emptyList(); - List featureTypeNamesToExport = storedQueryHandler.collectAndSortFeatureTypesToExport( configuredFeatureTypeNames ); + List featureTypeNamesToExport = storedQueryHandler.collectAndSortFeatureTypesToExport( + configuredFeatureTypeNames ); assertThat( featureTypeNamesToExport.size(), is( featureTypes.size() ) ); for ( FeatureType featureType : featureTypes ) { @@ -124,7 +114,8 @@ public void testCollectAndSortFeatureTypesToExport_EmptyFeatureTypeList() { managedStoredQueries ); List configuredFeatureTypeNames = Collections.emptyList(); - List featureTypeNamesToExport = storedQueryHandler.collectAndSortFeatureTypesToExport( configuredFeatureTypeNames ); + List featureTypeNamesToExport = storedQueryHandler.collectAndSortFeatureTypesToExport( + configuredFeatureTypeNames ); assertThat( featureTypeNamesToExport.size(), is( 0 ) ); } @@ -136,7 +127,8 @@ public void testCollectAndSortFeatureTypesToExport_LimitedConfiguredFeatureTypes managedStoredQueries ); List configuredFeatureTypeNames = configuredFeatureTypeNames(); - List featureTypeNamesToExport = storedQueryHandler.collectAndSortFeatureTypesToExport( configuredFeatureTypeNames ); + List featureTypeNamesToExport = storedQueryHandler.collectAndSortFeatureTypesToExport( + configuredFeatureTypeNames ); assertThat( featureTypeNamesToExport.size(), is( 1 ) ); @@ -174,7 +166,7 @@ public void testInitManagedWithoutExistingManagedStoredQueryDirectoryThrowsExcep @Test public void testInitManagedStoredQueries() - throws Exception { + throws Exception { List featureTypes = featureTypes(); File managedStoredQueries = Files.createTempDirectory( "managedStoredQueries" ).toFile(); @@ -194,7 +186,7 @@ public void testInitManagedStoredQueries() @Test public void testInitErroneousManagedStoredQueries() - throws Exception { + throws Exception { List featureTypes = featureTypes(); File managedStoredQueries = Files.createTempDirectory( "managedStoredQueries" ).toFile(); @@ -209,7 +201,7 @@ public void testInitErroneousManagedStoredQueries() @Test public void testDoCreateStoredQuery() - throws Exception { + throws Exception { List featureTypes = featureTypes(); StoredQueryHandler storedQueryHandler = new StoredQueryHandler( mockWFS( featureTypes ), new ArrayList(), managedStoredQueries ); @@ -222,13 +214,14 @@ public void testDoCreateStoredQuery() xmlStreamWriter.close(); assertThat( storedQueryHandler.hasStoredQuery( id ), is( true ) ); - assertThat( xml( outStream.toString() ), - hasXPath( "/wfs:CreateStoredQueryResponse[@status='OK']", NS_CONTEXT ) ); + assertThat( outStream.toString(), + hasXPath( "/wfs:CreateStoredQueryResponse[@status='OK']" ).withNamespaceContext( + nsContext() ) ); } @Test(expected = OWSException.class) public void testDoCreateStoredQuery_NullManagedStoredQueryDirectory() - throws Exception { + throws Exception { List featureTypes = featureTypes(); StoredQueryHandler storedQueryHandler = new StoredQueryHandler( mockWFS( featureTypes ), new ArrayList(), null ); @@ -243,7 +236,7 @@ public void testDoCreateStoredQuery_NullManagedStoredQueryDirectory() @Test(expected = OWSException.class) public void testDoCreateStoredQuery_NotExistingManagedStoredQueryDirectory() - throws Exception { + throws Exception { List featureTypes = featureTypes(); StoredQueryHandler storedQueryHandler = new StoredQueryHandler( mockWFS( featureTypes ), new ArrayList(), new File( "this/directory/does/not/exist" ) ); @@ -258,7 +251,7 @@ public void testDoCreateStoredQuery_NotExistingManagedStoredQueryDirectory() @Test(expected = OWSException.class) public void testDoCreateStoredQuery_DuplicateId() - throws Exception { + throws Exception { List featureTypes = featureTypes(); StoredQueryHandler storedQueryHandler = new StoredQueryHandler( mockWFS( featureTypes ), new ArrayList(), managedStoredQueries ); @@ -277,7 +270,7 @@ public void testDoCreateStoredQuery_DuplicateId() @Test(expected = OWSException.class) public void testDoCreateStoredQuery_UnsupportedLanguage() - throws Exception { + throws Exception { List featureTypes = featureTypes(); StoredQueryHandler storedQueryHandler = new StoredQueryHandler( mockWFS( featureTypes ), new ArrayList(), managedStoredQueries ); @@ -292,7 +285,7 @@ public void testDoCreateStoredQuery_UnsupportedLanguage() @Test public void testDoDropStoredQuery() - throws Exception { + throws Exception { List featureTypes = featureTypes(); StoredQueryHandler storedQueryHandler = new StoredQueryHandler( mockWFS( featureTypes ), new ArrayList(), managedStoredQueries ); @@ -306,12 +299,14 @@ public void testDoDropStoredQuery() xmlStreamWriter.close(); assertThat( storedQueryHandler.hasStoredQuery( id ), is( false ) ); - assertThat( xml( outStream.toString() ), hasXPath( "/wfs:DropStoredQueryResponse[@status='OK']", NS_CONTEXT ) ); + assertThat( outStream.toString(), + HasXPathMatcher.hasXPath( "/wfs:DropStoredQueryResponse[@status='OK']" ).withNamespaceContext( + nsContext() ) ); } @Test public void testDoDropStoredQuery_Unremovable() - throws Exception { + throws Exception { List featureTypes = featureTypes(); StoredQueryHandler storedQueryHandler = new StoredQueryHandler( mockWFS( featureTypes ), new ArrayList(), managedStoredQueries ); @@ -329,7 +324,7 @@ public void testDoDropStoredQuery_Unremovable() @Test(expected = OWSException.class) public void testDoDropStoredQuery_Unremovable_Exception() - throws Exception { + throws Exception { List featureTypes = featureTypes(); StoredQueryHandler storedQueryHandler = new StoredQueryHandler( mockWFS( featureTypes ), new ArrayList(), managedStoredQueries ); @@ -344,7 +339,7 @@ public void testDoDropStoredQuery_Unremovable_Exception() } private void insertStoredQuery( StoredQueryHandler storedQueryHandler, String id ) - throws Exception { + throws Exception { CreateStoredQuery request = createStoredQuery( id ); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( outStream ); @@ -407,10 +402,13 @@ private WfsFeatureStoreManager mockStoreManager( Collection feature } private HttpResponseBuffer mockHttpResponseBuffer( XMLStreamWriter xmlStreamWriter ) - throws Exception { + throws Exception { HttpResponseBuffer mockedResponse = mock( HttpResponseBuffer.class ); when( mockedResponse.getXMLWriter( anyBoolean() ) ).thenReturn( xmlStreamWriter ); return mockedResponse; } + private java.util.Map nsContext() { + return Collections.singletonMap( "wfs", WFS_200_NS ); + } } \ No newline at end of file diff --git a/deegree-services/deegree-services-wms/pom.xml b/deegree-services/deegree-services-wms/pom.xml index 7b7e777230..9fbff96c4b 100644 --- a/deegree-services/deegree-services-wms/pom.xml +++ b/deegree-services/deegree-services-wms/pom.xml @@ -90,11 +90,15 @@ org.mockito mockito-core - + + + org.xmlunit + xmlunit-core + - org.xmlmatchers - xml-matchers - + org.xmlunit + xmlunit-matchers + diff --git a/deegree-services/deegree-services-wms/src/test/java/org/deegree/services/wms/controller/capabilities/Wms130SoapExtendedCapabilitesWriterTest.java b/deegree-services/deegree-services-wms/src/test/java/org/deegree/services/wms/controller/capabilities/Wms130SoapExtendedCapabilitesWriterTest.java index 5719870aa4..f67683f5c0 100644 --- a/deegree-services/deegree-services-wms/src/test/java/org/deegree/services/wms/controller/capabilities/Wms130SoapExtendedCapabilitesWriterTest.java +++ b/deegree-services/deegree-services-wms/src/test/java/org/deegree/services/wms/controller/capabilities/Wms130SoapExtendedCapabilitesWriterTest.java @@ -35,6 +35,20 @@ ----------------------------------------------------------------------------*/ package org.deegree.services.wms.controller.capabilities; +import org.deegree.services.encoding.SupportedEncodings; +import org.junit.Ignore; +import org.junit.Test; +import org.xmlunit.builder.Input; +import org.xmlunit.matchers.HasXPathMatcher; +import org.xmlunit.matchers.ValidationMatcher; + +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + import static org.deegree.commons.xml.CommonNamespaces.WMSNS; import static org.deegree.commons.xml.CommonNamespaces.WMS_PREFIX; import static org.deegree.commons.xml.CommonNamespaces.XLINK_PREFIX; @@ -46,29 +60,12 @@ import static org.deegree.services.wms.controller.capabilities.Wms130SoapExtendedCapabilitesWriter.SOAPWMS_PREFIX; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.xmlmatchers.XmlMatchers.hasXPath; -import static org.xmlmatchers.transform.XmlConverters.xml; - -import java.io.ByteArrayOutputStream; -import java.net.URL; - -import javax.xml.namespace.NamespaceContext; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamWriter; -import javax.xml.validation.Schema; - -import org.deegree.services.encoding.SupportedEncodings; -import org.junit.Ignore; -import org.junit.Test; -import org.xml.sax.SAXException; -import org.xmlmatchers.XmlMatchers; -import org.xmlmatchers.namespace.SimpleNamespaceContext; -import org.xmlmatchers.validation.SchemaFactory; +import static org.xmlunit.matchers.EvaluateXPathMatcher.hasXPath; /** * @author Lyn Goltz @@ -77,7 +74,7 @@ public class Wms130SoapExtendedCapabilitesWriterTest { @Test public void testWriteSoapWmsExtendedCapabilites_ContainsPostUrl() - throws Exception { + throws Exception { Wms130SoapExtendedCapabilitesWriter writer = new Wms130SoapExtendedCapabilitesWriter(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); @@ -87,14 +84,14 @@ public void testWriteSoapWmsExtendedCapabilites_ContainsPostUrl() writer.writeSoapWmsExtendedCapabilites( streamWriter, postUrl, supportedEncodings ); streamWriter.close(); - assertThat( xml( stream.toString() ), + assertThat( stream.toString(), hasXPath( "//soapwms:ExtendedCapabilities/soapwms:SOAP/wms:OnlineResource/@xlink:href", - nsBindings(), equalTo( postUrl ) ) ); + equalTo( postUrl ) ).withNamespaceContext( nsBindings() ) ); } @Test public void testWriteSoapWmsExtendedCapabilites_NotContainsGetMap() - throws Exception { + throws Exception { Wms130SoapExtendedCapabilitesWriter writer = new Wms130SoapExtendedCapabilitesWriter(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); @@ -104,21 +101,24 @@ public void testWriteSoapWmsExtendedCapabilites_NotContainsGetMap() writer.writeSoapWmsExtendedCapabilites( streamWriter, postUrl, supportedEncodings ); streamWriter.close(); - assertThat( xml( stream.toString() ), - hasXPath( "//soapwms:ExtendedCapabilities/soapwms:SOAP/soapwms:SupportedOperations/soapwms:Operation[@name = 'GetCapabilities']", - nsBindings() ) ); - assertThat( xml( stream.toString() ), - hasXPath( "//soapwms:ExtendedCapabilities/soapwms:SOAP/soapwms:SupportedOperations/soapwms:Operation[@name = 'GetFeatureInfo']", - nsBindings() ) ); - assertThat( xml( stream.toString() ), - not( hasXPath( "//soapwms:ExtendedCapabilities/soapwms:SOAP/soapwms:SupportedOperations/soapwms:Operation[@name = 'GetMap']", - nsBindings() ) ) ); + assertThat( stream.toString(), + HasXPathMatcher.hasXPath( + "//soapwms:ExtendedCapabilities/soapwms:SOAP/soapwms:SupportedOperations/soapwms:Operation[@name = 'GetCapabilities']" ).withNamespaceContext( + nsBindings() ) ); + assertThat( stream.toString(), + HasXPathMatcher.hasXPath( + "//soapwms:ExtendedCapabilities/soapwms:SOAP/soapwms:SupportedOperations/soapwms:Operation[@name = 'GetFeatureInfo']" ).withNamespaceContext( + nsBindings() ) ); + assertThat( stream.toString(), + not( HasXPathMatcher.hasXPath( + "//soapwms:ExtendedCapabilities/soapwms:SOAP/soapwms:SupportedOperations/soapwms:Operation[@name = 'GetMap']" ).withNamespaceContext( + nsBindings() ) ) ); } @Ignore("Requires access to referenced schema") @Test public void testWriteSoapWmsExtendedCapabilites_SchemaValid() - throws Exception { + throws Exception { Wms130SoapExtendedCapabilitesWriter writer = new Wms130SoapExtendedCapabilitesWriter(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); @@ -127,20 +127,19 @@ public void testWriteSoapWmsExtendedCapabilites_SchemaValid() writer.writeSoapWmsExtendedCapabilites( streamWriter, "http://post.url/soap", supportedEncodings ); streamWriter.close(); - assertThat( xml( stream.toString() ), XmlMatchers.conformsTo( schema() ) ); + assertThat( stream.toString(), ValidationMatcher.valid( schema() ) ); } - private Schema schema() - throws SAXException { - URL schemaResource = Wms130SoapExtendedCapabilitesWriterTest.class.getResource( "soapwms.xsd" ); - return SchemaFactory.w3cXmlSchemaFrom( schemaResource ); + private Input.Builder schema() { + InputStream schemaResource = Wms130SoapExtendedCapabilitesWriterTest.class.getResourceAsStream( "soapwms.xsd" ); + return Input.fromStream( schemaResource ); } - private NamespaceContext nsBindings() { - SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext(); - simpleNamespaceContext.withBinding( SOAPWMS_PREFIX, SOAPWMS_NS ); - simpleNamespaceContext.withBinding( WMS_PREFIX, WMSNS ); - simpleNamespaceContext.withBinding( XLINK_PREFIX, XLNNS ); + private Map nsBindings() { + Map simpleNamespaceContext = new HashMap(); + simpleNamespaceContext.put( SOAPWMS_PREFIX, SOAPWMS_NS ); + simpleNamespaceContext.put( WMS_PREFIX, WMSNS ); + simpleNamespaceContext.put( XLINK_PREFIX, XLNNS ); return simpleNamespaceContext; } diff --git a/pom.xml b/pom.xml index 681ec9ba59..55e7f79a61 100644 --- a/pom.xml +++ b/pom.xml @@ -408,10 +408,16 @@ 3.20.0-GA - org.xmlmatchers - xml-matchers - 1.0-RC1 - test + org.xmlunit + xmlunit-core + 2.9.0 + test + + + org.xmlunit + xmlunit-matchers + 2.9.0 + test