StoredQueryDefinition200Encoder { public static void export( StoredQueryDefinition storedQueryDefinition, XMLStreamWriter writer ) throws XMLStreamException { writer.setPrefix( WFS_200_PREFIX, WFS_200_NS ); writer.writeStartElement( WFS_200_NS, "StoredQueryDefinition" ); writer.writeNamespace( WFS_200_PREFIX, WFS_200_NS ); writer.writeNamespace( XSI_PREFIX, XSINS ); String schemaLocation = WFS_200_NS + " " + WFS_200_SCHEMA_URL; writer.writeAttribute( XSINS, "schemaLocation", schemaLocation ); writer.writeAttribute( "id", storedQueryDefinition.getId() ); writeTitles( storedQueryDefinition.getTitles(), writer ); writeAbstracts( storedQueryDefinition.getAbstracts(), writer ); exportMetadata( storedQueryDefinition.getMetadata(), writer ); exportParameter( storedQueryDefinition, writer ); exportQueryExpression( storedQueryDefinition, writer ); writer.writeEndElement(); }  static void export( StoredQueryDefinition storedQueryDefinition, XMLStreamWriter writer );  }
@Test public void testExport() throws Exception { String storedQueryResource = "storedQuery.xml"; StoredQueryDefinition queryDefinition = parseStoredQueryDefinition( storedQueryResource ); ByteArrayOutputStream stream = new ByteArrayOutputStream(); XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter( stream ); 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 ) ) ); }