01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.sld;
17:
18: import junit.framework.TestCase;
19: import java.awt.Color;
20: import org.geotools.styling.FeatureTypeStyle;
21: import org.geotools.styling.NamedLayer;
22: import org.geotools.styling.PolygonSymbolizer;
23: import org.geotools.styling.Rule;
24: import org.geotools.styling.SLD;
25: import org.geotools.styling.Style;
26: import org.geotools.styling.StyledLayerDescriptor;
27: import org.geotools.xml.Parser;
28:
29: public class SLDTest extends TestCase {
30: public void test() throws Exception {
31: Parser parser = new Parser(new SLDConfiguration());
32:
33: StyledLayerDescriptor sld = (StyledLayerDescriptor) parser
34: .parse(getClass()
35: .getResourceAsStream("example-sld.xml"));
36:
37: assertEquals(1, sld.getStyledLayers().length);
38:
39: NamedLayer layer = (NamedLayer) sld.getStyledLayers()[0];
40: assertEquals("OCEANSEA_1M:Foundation", layer.getName());
41: assertEquals(1, layer.getStyles().length);
42:
43: Style style = layer.getStyles()[0];
44: assertEquals("GEOSYM", style.getName());
45: assertTrue(style.isDefault());
46: assertEquals(1, style.getFeatureTypeStyles().length);
47:
48: FeatureTypeStyle ftStyle = (FeatureTypeStyle) style
49: .getFeatureTypeStyles()[0];
50: assertEquals(1, ftStyle.getRules().length);
51:
52: Rule rule = ftStyle.getRules()[0];
53: assertEquals("main", rule.getName());
54: assertEquals(1, rule.getSymbolizers().length);
55:
56: PolygonSymbolizer ps = (PolygonSymbolizer) rule
57: .getSymbolizers()[0];
58: assertEquals("GEOMETRY", ps.getGeometryPropertyName());
59:
60: Color color = SLD.color(ps.getFill().getColor());
61: assertEquals(Integer.parseInt("96", 16), color.getRed());
62: assertEquals(Integer.parseInt("C3", 16), color.getGreen());
63: assertEquals(Integer.parseInt("F5", 16), color.getBlue());
64: }
65: }
|