ConfigUtils { public static Pair<Map<String, Style>, Map<String, Style>> parseStyles( Workspace workspace, String layerName, List<StyleRefType> styles ) { Map<String, Style> styleMap = new LinkedHashMap<String, Style>(); Map<String, Style> legendStyleMap = new LinkedHashMap<String, Style>(); Style defaultStyle = null, defaultLegendStyle = null; for ( StyleRefType srt : styles ) { String id = srt.getStyleStoreId(); StyleStore store = workspace.getResource( StyleStoreProvider.class, id ); if ( srt.getStyle() == null || srt.getStyle().isEmpty() ) { if ( store.getAll( layerName ) != null ) { for ( Style s : store.getAll( layerName ) ) { if ( defaultStyle == null ) { defaultStyle = s; defaultLegendStyle = s; } styleMap.put( s.getName(), s ); legendStyleMap.put( s.getName(), s ); } } continue; } Pair<Style, Style> p = useSelectedStyles( workspace, store, srt, id, styleMap, legendStyleMap, defaultStyle, defaultLegendStyle ); defaultStyle = p.first; defaultLegendStyle = p.second; } checkDefaultStyle( defaultStyle, styleMap, defaultLegendStyle, legendStyleMap ); return new Pair<Map<String, Style>, Map<String, Style>>( styleMap, legendStyleMap ); } private  ConfigUtils(); static Pair<Map<String, Style>, Map<String, Style>> parseStyles( Workspace workspace, String layerName,
                                                                            List<StyleRefType> styles ); static List<ResourceIdentifier<StyleStore>> getStyleDeps( List<StyleRefType> styles ); static MapOptions parseLayerOptions( LayerOptionsType cfg ); static Map<String, Dimension<?>> parseDimensions( String layerName, List<DimensionType> dimensions );  }
@Test public void testParseStyles_EqualDefaultAndSimple() throws Exception { StyleStore store = mockStyleStoreWithThreeStyles_EqualDefaultAndSimple(); Workspace workspace = mockWorkspace( store ); List<StyleRefType> styles = singletonList( readStyleRef( "styleRefs_EqualDefaultAndSimple.xml" ) ); Pair<Map<String, Style>, Map<String, Style>> selectedStyles = parseStyles( workspace, "layer", styles ); Map<String, Style> styleMap = selectedStyles.getFirst(); Map<String, Style> legendStyleMap = selectedStyles.getSecond(); assertThat( styleMap.size(), is( 3 ) ); assertThat( legendStyleMap.size(), is( 3 ) ); Style defaultLegendStyle = legendStyleMap.get( "default" ); assertThat( defaultLegendStyle.getName(), is( "default" ) ); assertThat( defaultLegendStyle.getLegendURL(), is( new URL( "http: }
@Test public void testParseStyles_DifferentDefaultAndSimple() throws Exception { StyleStore store = mockStyleStoreWithThreeStyles_DifferentDefaultAndSimple(); Workspace workspace = mockWorkspace( store ); List<StyleRefType> styles = singletonList( readStyleRef( "styleRefs_DifferentDefaultAndSimple.xml" ) ); Pair<Map<String, Style>, Map<String, Style>> selectedStyles = parseStyles( workspace, "layer", styles ); Map<String, Style> styleMap = selectedStyles.getFirst(); Map<String, Style> legendStyleMap = selectedStyles.getSecond(); assertThat( styleMap.size(), is( 3 ) ); assertThat( legendStyleMap.size(), is( 3 ) ); Style defaultLegendStyle = legendStyleMap.get( "default" ); assertThat( defaultLegendStyle.getName(), is( "default" ) ); assertThat( defaultLegendStyle.getLegendURL(), is( new URL( "http: }
@Test public void testParseStyles_OnlyOneWithLegendStyle() throws Exception { StyleStore store = mockStyleStoreWithThreeStyles_DifferentDefaultAndSimple(); Workspace workspace = mockWorkspace( store ); List<StyleRefType> styles = singletonList( readStyleRef( "styleRefs_OnlyOneWithLegendStyle.xml" ) ); Pair<Map<String, Style>, Map<String, Style>> selectedStyles = parseStyles( workspace, "layer", styles ); Map<String, Style> styleMap = selectedStyles.getFirst(); Map<String, Style> legendStyleMap = selectedStyles.getSecond(); assertThat( styleMap.size(), is( 3 ) ); assertThat( legendStyleMap.size(), is( 2 ) ); Style defaultLegendStyle = legendStyleMap.get( "default" ); assertThat( defaultLegendStyle.getName(), is( "legendStyle" ) ); assertThat( defaultLegendStyle.getLegendURL(), nullValue() ); }
@Test public void testParseStyless_DefaultWithoutLegendStyle() throws Exception { StyleStore store = mockStyleStoreWithThreeStyles_DifferentDefaultAndSimple(); Workspace workspace = mockWorkspace( store ); List<StyleRefType> styles = singletonList( readStyleRef( "styleRefs_DefaultWithoutLegendStyle.xml" ) ); Pair<Map<String, Style>, Map<String, Style>> selectedStyles = parseStyles( workspace, "layer", styles ); Map<String, Style> styleMap = selectedStyles.getFirst(); Map<String, Style> legendStyleMap = selectedStyles.getSecond(); assertThat( styleMap.size(), is( 3 ) ); assertThat( legendStyleMap.size(), is( 3 ) ); Style defaultLegendStyle = legendStyleMap.get( "default" ); assertThat( defaultLegendStyle.getName(), is( "simpleStyle" ) ); assertThat( defaultLegendStyle.getLegendURL(), is( new URL( "http: }