WmsCapabilities111ThemeWriter { public void writeTheme( final XMLStreamWriter writer, final Theme theme ) throws XMLStreamException { final LayerMetadata layerMetadata = new LayerMetadataMerger().merge( theme ); final DatasetMetadataFactory factory = new DatasetMetadataFactory(); final List<DatasetMetadata> dsMd1 = getDatasetMetadataFromProvider( theme ); final DatasetMetadata dsMd2 = factory.buildDatasetMetadata( layerMetadata, theme, mdUrlTemplate ); if ( dsMd1 != null && dsMd2 != null ) dsMd1.add( dsMd2 ); final DatasetMetadata datasetMetadata = new DatasetMetadataMerger().merge( dsMd1 ); final DoublePair scaleDenominators = new LayerMetadataMerger().mergeScaleDenominators( theme ); final Map<String, String> authorityNameToUrl = getExternalAuthorityNameToUrlMap( metadataProvider ); writeTheme( writer, layerMetadata, datasetMetadata, authorityNameToUrl, scaleDenominators, theme.getThemes() ); } WmsCapabilities111ThemeWriter( final OWSMetadataProvider metadataProvider,
                                          final Capabilities111XMLAdapter styleWriter, final String mdUrlTemplate ); void writeTheme( final XMLStreamWriter writer, final Theme theme );  }
@Test public void writeThemeMinimal() throws Exception { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final XMLStreamWriter writer = newInstance().createXMLStreamWriter( bos ); writer.writeStartElement( "Layer" ); XMLAdapter.writeElement( writer, "Title", "Container" ); final LayerMetadata layerMetadata = createLayerMetadataMinimal(); layerMetadata.setQueryable( false ); final DatasetMetadata datasetMetadata = createDatasetMetadataMinimal(); final Map<String, String> authorityNameToUrl = emptyMap(); themeWriter.writeTheme( writer, layerMetadata, datasetMetadata, authorityNameToUrl, null, null ); writer.writeEndElement(); writer.flush(); bos.close(); final InputStream is = WmsCapabilities111ThemeWriterTest.class.getResourceAsStream( "wms111_layer_minimal.xml" ); final byte[] expected = IOUtils.readBytesAndClose( is, -1 ); assertArrayEquals( expected, bos.toByteArray() ); }
@Test public void writeThemeFull() throws Exception { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final XMLStreamWriter writer = newInstance().createXMLStreamWriter( bos ); writer.writeStartElement( "Layer" ); XMLAdapter.writeElement( writer, "Title", "Container" ); final LayerMetadata layerMetadata = createLayerMetadata(); final DatasetMetadata datasetMetadata = createDatasetMetadataFull(); final DoublePair scaleDenominators = new DoublePair( 0.0, 999999.9 ); final Map<String, String> authorityNameToUrl = createAuthorityNameToUrlMap(); themeWriter.writeTheme( writer, layerMetadata, datasetMetadata, authorityNameToUrl, scaleDenominators, null ); writer.writeEndElement(); writer.flush(); bos.close(); final InputStream is = WmsCapabilities111ThemeWriterTest.class.getResourceAsStream( "wms111_layer_full.xml" ); final byte[] expected = IOUtils.readBytesAndClose( is, -1 ); assertArrayEquals( expected, bos.toByteArray() ); }
@Test public void testWriteThemeMultipleMetadataUrls() throws Exception { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final XMLStreamWriter writer = newInstance().createXMLStreamWriter( bos ); writer.writeStartElement( "Layer" ); XMLAdapter.writeElement( writer, "Title", "Container" ); final LayerMetadata layerMetadata = createLayerMetadata(); String mdurlTemplate = "http: OWSMetadataProvider provider = Mockito.mock( OWSMetadataProvider.class ); List<DatasetMetadata> mds = new ArrayList<DatasetMetadata>(); mds.add( createDatasetMetadata( "http: mds.add( createDatasetMetadata( "http: when( provider.getAllDatasetMetadata( Mockito.any( QName.class ) ) ).thenReturn( mds ); WmsCapabilities111ThemeWriter themeWriter = new WmsCapabilities111ThemeWriter( provider, null, mdurlTemplate ); Theme theme = new StandardTheme( layerMetadata, Collections.<Theme> emptyList(), Collections.<Layer> emptyList(), null ); themeWriter.writeTheme( writer, theme ); writer.writeEndElement(); writer.flush(); bos.close(); final InputStream is = WmsCapabilities130ThemeWriterTest.class.getResourceAsStream( "wms111_layer_multipleMetadataUrls.xml" ); final byte[] expected = IOUtils.readBytesAndClose( is, -1 ); assertArrayEquals( expected, bos.toByteArray() ); }