001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.styling;
017:
018: import junit.framework.Test;
019: import junit.framework.TestCase;
020: import junit.framework.TestSuite;
021:
022: import org.geotools.factory.CommonFactoryFinder;
023: import org.geotools.feature.Feature;
024: import org.opengis.filter.FilterFactory;
025: import org.opengis.filter.expression.Expression;
026:
027: import java.lang.reflect.InvocationTargetException;
028: import java.lang.reflect.Method;
029: import java.util.logging.Logger;
030:
031: /**
032: * DOCUMENT ME!
033: *
034: * @author iant
035: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/test/java/org/geotools/styling/StyleFactoryImplTest.java $
036: */
037: public class StyleFactoryImplTest extends TestCase {
038: static StyleFactory styleFactory;
039: static FilterFactory filterFactory = CommonFactoryFinder
040: .getFilterFactory(null);
041: static Feature feature;
042: protected static final Logger LOGGER = org.geotools.util.logging.Logging
043: .getLogger("org.geotools.styling");
044:
045: public StyleFactoryImplTest(java.lang.String testName) {
046: super (testName);
047:
048: feature = null;
049: }
050:
051: public static void main(java.lang.String[] args) {
052: junit.textui.TestRunner.run(suite());
053: }
054:
055: public static Test suite() {
056: TestSuite suite = new TestSuite(StyleFactoryImplTest.class);
057:
058: return suite;
059: }
060:
061: /**
062: * Test of createStyle method, of class
063: * org.geotools.styling.StyleFactoryImpl.
064: */
065: public void testCreateStyle() {
066: LOGGER.finer("testCreateStyle");
067:
068: styleFactory = CommonFactoryFinder.getStyleFactory(null);
069:
070: assertNotNull("Failed to build styleFactory", styleFactory);
071: }
072:
073: /**
074: * Test of createPointSymbolizer method, of class
075: * org.geotools.styling.StyleFactoryImpl.
076: */
077: public void testCreatePointSymbolizer() {
078: LOGGER.finer("testCreatePointSymbolizer");
079:
080: PointSymbolizer ps = styleFactory.createPointSymbolizer();
081:
082: assertNotNull("Failed to create PointSymbolizer", ps);
083: }
084:
085: /**
086: * Test of createPolygonSymbolizer method, of class
087: * org.geotools.styling.StyleFactoryImpl.
088: */
089: public void testCreatePolygonSymbolizer() {
090: LOGGER.finer("testCreatePolygonSymbolizer");
091:
092: PolygonSymbolizer ps = styleFactory.createPolygonSymbolizer();
093:
094: assertNotNull("Failed to create PolygonSymbolizer", ps);
095: }
096:
097: /**
098: * Test of createLineSymbolizer method, of class
099: * org.geotools.styling.StyleFactoryImpl.
100: */
101: public void testCreateLineSymbolizer() {
102: LOGGER.finer("testCreateLineSymbolizer");
103:
104: LineSymbolizer ls = styleFactory.createLineSymbolizer();
105:
106: assertNotNull("Failed to create PolygonSymbolizer", ls);
107: }
108:
109: /**
110: * Test of createTextSymbolizer method, of class
111: * org.geotools.styling.StyleFactoryImpl.
112: */
113: public void testCreateTextSymbolizer() {
114: LOGGER.finer("testCreateTextSymbolizer");
115:
116: TextSymbolizer ts = styleFactory.createTextSymbolizer();
117:
118: assertNotNull("Failed to create TextSymbolizer", ts);
119: }
120:
121: /**
122: * Test of createFeatureTypeStyle method, of class
123: * org.geotools.styling.StyleFactoryImpl.
124: */
125: public void testCreateFeatureTypeStyle() {
126: LOGGER.finer("testCreateFeatureTypeStyle");
127:
128: FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
129:
130: assertNotNull("failed to create featureTypeStyle", fts);
131: }
132:
133: /**
134: * Test of createRule method, of class
135: * org.geotools.styling.StyleFactoryImpl.
136: */
137: public void testCreateRule() {
138: LOGGER.finer("testCreateRule");
139:
140: Rule r = styleFactory.createRule();
141:
142: assertNotNull("failed to create Rule", r);
143: }
144:
145: /**
146: * Test of createStroke method, of class
147: * org.geotools.styling.StyleFactoryImpl.
148: */
149: public void testCreateStroke() {
150: LOGGER.finer("testCreateStroke");
151:
152: Stroke s = styleFactory.createStroke(filterFactory
153: .literal("#000000"), filterFactory.literal(2.0));
154:
155: assertNotNull("Failed to build stroke ", s);
156:
157: s = styleFactory.createStroke(filterFactory.literal("#000000"),
158: filterFactory.literal(2.0), filterFactory.literal(0.5));
159:
160: assertNotNull("Failed to build stroke ", s);
161:
162: s = styleFactory.createStroke(filterFactory.literal("#000000"),
163: filterFactory.literal(2.0), filterFactory.literal(0.5),
164: filterFactory.literal("bevel"), filterFactory
165: .literal("square"), new float[] { 1.1f, 2.1f,
166: 6f, 2.1f, 1.1f, 5f }, filterFactory.literal(3),
167: null, null);
168:
169: assertNotNull("Failed to build stroke ", s);
170:
171: assertEquals("Wrong color ", "#000000", s.getColor().evaluate(
172: feature).toString());
173: assertEquals("Wrong width ", "2.0", s.getWidth().evaluate(
174: feature).toString());
175: assertEquals("Wrong opacity ", "0.5", s.getOpacity().evaluate(
176: feature).toString());
177: assertEquals("Wrong linejoin ", "bevel", s.getLineJoin()
178: .evaluate(feature).toString());
179: assertEquals("Wrong linejoin ", "square", s.getLineCap()
180: .evaluate(feature).toString());
181: assertEquals("Broken dash array", 2.1f, s.getDashArray()[1],
182: 0.001f);
183: assertEquals("Wrong dash offset ", "3", s.getDashOffset()
184: .evaluate(feature).toString());
185: }
186:
187: /**
188: * Test of createFill method, of class
189: * org.geotools.styling.StyleFactoryImpl.
190: */
191: public void testCreateFill() {
192: LOGGER.finer("testCreateFill");
193:
194: Fill f = styleFactory.createFill(filterFactory
195: .literal("#808080"));
196:
197: assertNotNull("Failed to build fill", f);
198:
199: f = styleFactory.createFill(filterFactory.literal("#808080"),
200: filterFactory.literal(1.0));
201: assertNotNull("Failed to build fill", f);
202:
203: f = styleFactory.createFill(null);
204: assertEquals(f.getColor(), Fill.DEFAULT.getColor());
205: assertSame(f.getColor(), Fill.DEFAULT.getColor());
206:
207: assertEquals(f.getBackgroundColor(), Fill.DEFAULT
208: .getBackgroundColor());
209: assertSame(f.getBackgroundColor(), Fill.DEFAULT
210: .getBackgroundColor());
211: }
212:
213: /**
214: * Test of createMark method, of class
215: * org.geotools.styling.StyleFactoryImpl.
216: */
217: public void testCreateMark() {
218: LOGGER.finer("testCreateMark");
219:
220: Mark m = styleFactory.createMark();
221:
222: assertNotNull("Failed to build mark ", m);
223: }
224:
225: /**
226: * Test of getSquareMark method, of class
227: * org.geotools.styling.StyleFactoryImpl.
228: */
229: public void testGetNamedMarks() {
230: LOGGER.finer("testGetNamedMarks");
231:
232: Mark m;
233: String[] names = { "Square", "Circle", "Triangle", "Star", "X",
234: "Cross" };
235:
236: for (int i = 0; i < names.length; i++) {
237: try {
238: Class target = styleFactory.getClass();
239:
240: // LOGGER.finer("About to load get"+names[i]+"Mark");
241: Method method = target.getMethod("get" + names[i]
242: + "Mark", (Class[]) null);
243:
244: // LOGGER.finer("got method back " + method.toString());
245: m = (Mark) method.invoke(styleFactory, (Object[]) null);
246: assertNotNull("Failed to get " + names[i] + " mark ", m);
247:
248: Expression exp = filterFactory.literal(names[i]);
249: assertEquals("Wrong sort of mark returned ", exp, m
250: .getWellKnownName());
251: assertEquals("Wrong size of mark returned ", "6", m
252: .getSize().evaluate(feature).toString());
253: } catch (InvocationTargetException ite) {
254: ite.getTargetException().printStackTrace();
255: fail("InvocationTargetException "
256: + ite.getTargetException());
257: } catch (Exception e) {
258: e.printStackTrace();
259: fail("Exception " + e.toString());
260: }
261: }
262: }
263:
264: /**
265: * Test of createGraphic method, of class
266: * org.geotools.styling.StyleFactoryImpl.
267: */
268: public void testCreateGraphic() {
269: LOGGER.finer("testCreateGraphic");
270:
271: ExternalGraphic[] externalGraphics = new ExternalGraphic[] { styleFactory
272: .createExternalGraphic(
273: "http://www.ccg.leeds.ac.uk/ian/geotools/icons/rail.gif",
274: "image/gif") };
275: Mark[] marks = new Mark[] { styleFactory.getCircleMark() };
276: Mark[] symbols = new Mark[0];
277: Expression opacity = filterFactory.literal(0.5);
278: Expression size = filterFactory.literal(10);
279: Expression rotation = filterFactory.literal(145.0);
280: Graphic g = styleFactory.createGraphic(externalGraphics, marks,
281: symbols, opacity, size, rotation);
282:
283: assertNotNull("failed to build graphic ", g);
284: }
285:
286: /**
287: * Test of createFont method, of class
288: * org.geotools.styling.StyleFactoryImpl.
289: */
290: public void testCreateFont() {
291: LOGGER.finer("testCreateFont");
292:
293: Expression fontFamily = filterFactory.literal("Times");
294: Expression fontStyle = filterFactory.literal("Italic");
295: Expression fontWeight = filterFactory.literal("Bold");
296: Expression fontSize = filterFactory.literal("12");
297: Font f = styleFactory.createFont(fontFamily, fontStyle,
298: fontWeight, fontSize);
299:
300: assertNotNull("Failed to build font", f);
301:
302: assertEquals("Wrong font type ", "Times", f.getFontFamily()
303: .evaluate(feature).toString());
304: assertEquals("Wrong font Style ", "Italic", f.getFontStyle()
305: .evaluate(feature).toString());
306: assertEquals("Wrong font weight ", "Bold", f.getFontWeight()
307: .evaluate(feature).toString());
308: assertEquals("Wrong font size ", "12", f.getFontSize()
309: .evaluate(feature).toString());
310: }
311:
312: /**
313: * Test of createLinePlacement method, of class
314: * org.geotools.styling.StyleFactoryImpl.
315: */
316: public void testCreateLinePlacement() {
317: LOGGER.finer("testCreateLinePlacement");
318:
319: LinePlacement lp = styleFactory
320: .createLinePlacement(filterFactory.literal(10));
321:
322: assertNotNull("failed to create LinePlacement", lp);
323: }
324:
325: /**
326: * Test of createPointPlacement method, of class
327: * org.geotools.styling.StyleFactoryImpl.
328: */
329: public void testCreatePointPlacement() {
330: LOGGER.finer("testCreatePointPlacement");
331:
332: AnchorPoint anchorPoint = styleFactory.createAnchorPoint(
333: filterFactory.literal(1.0), filterFactory.literal(0.5));
334: Displacement displacement = styleFactory
335: .createDisplacement(filterFactory.literal(10.0),
336: filterFactory.literal(5.0));
337: Expression rotation = filterFactory.literal(90.0);
338: PointPlacement pp = styleFactory.createPointPlacement(
339: anchorPoint, displacement, rotation);
340:
341: assertNotNull("failed to create PointPlacement", pp);
342:
343: assertEquals("Wrong X anchorPoint ", "1.0", pp.getAnchorPoint()
344: .getAnchorPointX().evaluate(feature).toString());
345: assertEquals("Wrong Y anchorPoint ", "0.5", pp.getAnchorPoint()
346: .getAnchorPointY().evaluate(feature).toString());
347: assertEquals("Wrong X displacement ", "10.0", pp
348: .getDisplacement().getDisplacementX().evaluate(feature)
349: .toString());
350: assertEquals("Wrong Y displacement ", "5.0", pp
351: .getDisplacement().getDisplacementY().evaluate(feature)
352: .toString());
353: assertEquals("Wrong Rotation ", "90.0", pp.getRotation()
354: .evaluate(feature).toString());
355: }
356:
357: /**
358: * Test of createHalo method, of class
359: * org.geotools.styling.StyleFactoryImpl.
360: */
361: public void testCreateHalo() {
362: LOGGER.finer("testCreateHalo");
363:
364: Halo h = styleFactory.createHalo(styleFactory.getDefaultFill(),
365: filterFactory.literal(4));
366:
367: assertNotNull("Failed to build halo", h);
368:
369: assertEquals("Wrong radius", 4, ((Number) h.getRadius()
370: .evaluate(feature)).intValue());
371: }
372:
373: //
374: // /** Test of getDefaultFill method, of class org.geotools.styling.StyleFactoryImpl. */
375: // public void testGetDefaultFill() {
376: // LOGGER.finer("testGetDefaultFill");
377: //
378: // }
379: //
380: // /** Test of getDefaultLineSymbolizer method, of class org.geotools.styling.StyleFactoryImpl. */
381: // public void testGetDefaultLineSymbolizer() {
382: // LOGGER.finer("testGetDefaultLineSymbolizer");
383: //
384: //
385: // }
386: //
387: // /** Test of getDefaultMark method, of class org.geotools.styling.StyleFactoryImpl. */
388: // public void testGetDefaultMark() {
389: // LOGGER.finer("testGetDefaultMark");
390: //
391: //
392: // }
393: //
394: // /** Test of getDefaultPointSymbolizer method, of class org.geotools.styling.StyleFactoryImpl. */
395: // public void testGetDefaultPointSymbolizer() {
396: // LOGGER.finer("testGetDefaultPointSymbolizer");
397: //
398: //
399: // }
400: //
401: // /** Test of getDefaultPolygonSymbolizer method, of class org.geotools.styling.StyleFactoryImpl. */
402: // public void testGetDefaultPolygonSymbolizer() {
403: // LOGGER.finer("testGetDefaultPolygonSymbolizer");
404: //
405: // }
406: //
407: // /** Test of getDefaultStroke method, of class org.geotools.styling.StyleFactoryImpl. */
408: // public void testGetDefaultStroke() {
409: // LOGGER.finer("testGetDefaultStroke");
410: //
411: //
412: // }
413: //
414: // /** Test of getDefaultStyle method, of class org.geotools.styling.StyleFactoryImpl. */
415: // public void testGetDefaultStyle() {
416: // LOGGER.finer("testGetDefaultStyle");
417: //
418: //
419: // }
420: //
421: // /** Test of getDefaultTextSymbolizer method, of class org.geotools.styling.StyleFactoryImpl. */
422: // public void testGetDefaultTextSymbolizer() {
423: // LOGGER.finer("testGetDefaultTextSymbolizer");
424: //
425: //
426: // }
427: //
428: // /** Test of getDefaultFont method, of class org.geotools.styling.StyleFactoryImpl. */
429: // public void testGetDefaultFont() {
430: // LOGGER.finer("testGetDefaultFont");
431: //
432: //
433: // }
434: //
435: // /** Test of getDefaultGraphic method, of class org.geotools.styling.StyleFactoryImpl. */
436: // public void testGetDefaultGraphic() {
437: // LOGGER.finer("testGetDefaultGraphic");
438: //
439: //
440: // }
441: //
442: // /** Test of createRasterSymbolizer method, of class org.geotools.styling.StyleFactoryImpl. */
443: // public void testCreateRasterSymbolizer() {
444: // LOGGER.finer("testCreateRasterSymbolizer");
445: //
446: //
447: // }
448: }
|