001: package org.geoserver.wfs;
002:
003: import org.geoserver.data.test.MockData;
004: import org.geotools.feature.Feature;
005:
006: /**
007: * This test must be run with the server configured with the wfs 1.0 cite
008: * configuration, with data initialized.
009: *
010: * @author Justin Deoliveira, The Open Planning Project
011: *
012: */
013: public class TransactionListenerTest extends WFSTestSupport {
014:
015: TransactionListenerTester listener;
016:
017: protected String[] getSpringContextLocations() {
018: String[] base = super .getSpringContextLocations();
019: String[] extended = new String[base.length + 1];
020: System.arraycopy(base, 0, extended, 0, base.length);
021: extended[base.length] = "classpath:/org/geoserver/wfs/TransactionListenerTestContext.xml";
022: return extended;
023: }
024:
025: protected void setUp() throws Exception {
026: super .setUp();
027: listener = (TransactionListenerTester) applicationContext
028: .getBean("transactionListenerTester");
029: listener.clear();
030: }
031:
032: public void testDelete() throws Exception {
033: // perform a delete
034: String delete = "<wfs:Transaction service=\"WFS\" version=\"1.0.0\" "
035: + "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
036: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
037: + "xmlns:wfs=\"http://www.opengis.net/wfs\"> "
038: + "<wfs:Delete typeName=\"cgf:Points\"> "
039: + "<ogc:Filter> "
040: + "<ogc:PropertyIsEqualTo> "
041: + "<ogc:PropertyName>cgf:id</ogc:PropertyName> "
042: + "<ogc:Literal>t0000</ogc:Literal> "
043: + "</ogc:PropertyIsEqualTo> "
044: + "</ogc:Filter> "
045: + "</wfs:Delete> " + "</wfs:Transaction>";
046:
047: postAsDOM("wfs", delete);
048: assertEquals(1, listener.events.size());
049: TransactionEvent event = (TransactionEvent) listener.events
050: .get(0);
051: assertEquals(TransactionEventType.PRE_DELETE, event.getType());
052: assertEquals(MockData.POINTS, event.getLayerName());
053: assertEquals(1, listener.features.size());
054: Feature deleted = (Feature) listener.features.get(0);
055: assertEquals("t0000", deleted.getAttribute("id"));
056: }
057:
058: public void testInsert() throws Exception {
059: // perform an insert
060: String insert = "<wfs:Transaction service=\"WFS\" version=\"1.0.0\" "
061: + "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
062: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
063: + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
064: + "xmlns:gml=\"http://www.opengis.net/gml\"> "
065: + "<wfs:Insert > "
066: + "<cgf:Lines>"
067: + "<cgf:lineStringProperty>"
068: + "<gml:LineString>"
069: + "<gml:coordinates decimal=\".\" cs=\",\" ts=\" \">"
070: + "494475.71056415,5433016.8189323 494982.70115662,5435041.95096618"
071: + "</gml:coordinates>"
072: + "</gml:LineString>"
073: + "</cgf:lineStringProperty>"
074: + "<cgf:id>t0002</cgf:id>"
075: + "</cgf:Lines>"
076: + "</wfs:Insert>" + "</wfs:Transaction>";
077:
078: postAsDOM("wfs", insert);
079: assertEquals(1, listener.events.size());
080: TransactionEvent firstEvent = (TransactionEvent) listener.events
081: .get(0);
082: assertEquals(TransactionEventType.PRE_INSERT, firstEvent
083: .getType());
084: assertEquals(MockData.LINES, firstEvent.getLayerName());
085: assertEquals(1, listener.features.size());
086: }
087:
088: public void testUpdate() throws Exception {
089: // perform an update
090: String insert = "<wfs:Transaction service=\"WFS\" version=\"1.0.0\" "
091: + "xmlns:cgf=\"http://www.opengis.net/cite/geometry\" "
092: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
093: + "xmlns:wfs=\"http://www.opengis.net/wfs\" "
094: + "xmlns:gml=\"http://www.opengis.net/gml\"> "
095: + "<wfs:Update typeName=\"cgf:Polygons\" > "
096: + "<wfs:Property>"
097: + "<wfs:Name>id</wfs:Name>"
098: + "<wfs:Value>t0003</wfs:Value>"
099: + "</wfs:Property>"
100: + "<ogc:Filter>"
101: + "<ogc:PropertyIsEqualTo>"
102: + "<ogc:PropertyName>id</ogc:PropertyName>"
103: + "<ogc:Literal>t0002</ogc:Literal>"
104: + "</ogc:PropertyIsEqualTo>"
105: + "</ogc:Filter>"
106: + "</wfs:Update>" + "</wfs:Transaction>";
107:
108: postAsDOM("wfs", insert);
109: assertEquals(2, listener.events.size());
110: TransactionEvent firstEvent = (TransactionEvent) listener.events
111: .get(0);
112: assertEquals(TransactionEventType.PRE_UPDATE, firstEvent
113: .getType());
114: assertEquals(MockData.POLYGONS, firstEvent.getLayerName());
115: Feature updatedBefore = (Feature) listener.features.get(0);
116: assertEquals("t0002", updatedBefore.getAttribute("id"));
117:
118: TransactionEvent secondEvent = (TransactionEvent) listener.events
119: .get(1);
120: assertEquals(TransactionEventType.POST_UPDATE, secondEvent
121: .getType());
122: assertEquals(MockData.POLYGONS, secondEvent.getLayerName());
123: Feature updatedAfter = (Feature) listener.features.get(1);
124: assertEquals("t0003", updatedAfter.getAttribute("id"));
125:
126: assertEquals(2, listener.features.size());
127: }
128: }
|