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; either
09: * version 2.1 of the License, or (at your option) any later version.
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.data;
17:
18: import java.io.IOException;
19:
20: import junit.framework.TestCase;
21:
22: import org.geotools.feature.Feature;
23: import org.geotools.feature.FeatureType;
24:
25: import com.vividsolutions.jts.geom.Coordinate;
26: import com.vividsolutions.jts.geom.Envelope;
27: import com.vividsolutions.jts.geom.GeometryFactory;
28: import com.vividsolutions.jts.geom.Point;
29:
30: public class DiffWriterTest extends TestCase {
31:
32: DiffFeatureWriter writer;
33: private Point geom;
34: private FeatureType type;
35:
36: protected void setUp() throws Exception {
37: type = DataUtilities.createType("default",
38: "name:String,*geom:Geometry");
39: GeometryFactory fac = new GeometryFactory();
40: geom = fac.createPoint(new Coordinate(10, 10));
41:
42: Diff diff = new Diff();
43: diff.add("1", type.create(new Object[] { "diff1", geom }, "1"));
44: diff.modify("original", type.create(new Object[] { "diff2",
45: geom }, "original"));
46: FeatureReader reader = new TestReader(type, type.create(
47: new Object[] { "original", geom }, "original"));
48: writer = new DiffFeatureWriter(reader, diff) {
49:
50: protected void fireNotification(int eventType,
51: Envelope bounds) {
52: //
53: }
54:
55: };
56: }
57:
58: public void testRemove() throws Exception {
59: writer.next();
60: Feature feature = writer.next();
61: writer.remove();
62: assertNull(writer.diff.added.get(feature.getID()));
63: }
64:
65: public void testHasNext() throws Exception {
66: assertTrue(writer.hasNext());
67: assertEquals(2, writer.diff.added.size()
68: + writer.diff.modified2.size());
69: writer.next();
70: assertTrue(writer.hasNext());
71: assertEquals(2, writer.diff.added.size()
72: + writer.diff.modified2.size());
73: writer.next();
74: assertFalse(writer.hasNext());
75: assertEquals(2, writer.diff.added.size()
76: + writer.diff.modified2.size());
77: }
78:
79: public void testWrite() throws IOException, Exception {
80: while (writer.hasNext()) {
81: writer.next();
82: }
83:
84: Feature feature = writer.next();
85: feature.setAttribute("name", "new1");
86:
87: writer.write();
88: assertEquals(2, writer.diff.added.size());
89: feature = writer.next();
90: feature.setAttribute("name", "new2");
91:
92: writer.write();
93:
94: assertEquals(3, writer.diff.added.size());
95: }
96:
97: }
|