001: package org.geoserver.wfs;
002:
003: import org.w3c.dom.Document;
004: import org.w3c.dom.Element;
005:
006: public class LockFeatureTest extends WFSTestSupport {
007:
008: public void testLockActionSomeAlreadyLocked() throws Exception {
009:
010: // get a feature
011: String xml = "<wfs:GetFeature" + " service=\"WFS\""
012: + " version=\"1.0.0\"" + " outputFormat=\"GML2\""
013: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
014: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
015: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
016: + " <wfs:Query typeName=\"cdf:Locks\" />"
017: + "</wfs:GetFeature>";
018:
019: Document dom = postAsDOM("wfs", xml);
020: assertEquals("wfs:FeatureCollection", dom.getDocumentElement()
021: .getNodeName());
022:
023: // get a fid
024: String fid = ((Element) dom.getElementsByTagName("cdf:Locks")
025: .item(0)).getAttribute("fid");
026:
027: // lock the feature
028: xml = "<wfs:LockFeature" + " service=\"WFS\""
029: + " version=\"1.0.0\"" + " expiry=\"10\""
030: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
031: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
032: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
033: + " <wfs:Lock typeName=\"cdf:Locks\">"
034: + " <ogc:Filter>" + " <ogc:FeatureId fid=\""
035: + fid + "\"/>" + " </ogc:Filter>" + " </wfs:Lock>"
036: + "</wfs:LockFeature>";
037:
038: dom = postAsDOM("wfs", xml);
039: assertEquals("WFS_LockFeatureResponse", dom
040: .getDocumentElement().getNodeName());
041:
042: String lockId = dom.getElementsByTagName("LockId").item(0)
043: .getFirstChild().getNodeValue();
044:
045: // try to lock again with releaseAction = SOME
046: xml = "<wfs:LockFeature" + " service=\"WFS\""
047: + " version=\"1.0.0\"" + " expiry=\"10\""
048: + " lockAction=\"SOME\""
049: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
050: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
051: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
052: + " <wfs:Lock typeName=\"cdf:Locks\">"
053: + " <ogc:Filter>" + " <ogc:FeatureId fid=\""
054: + fid + "\"/>" + " </ogc:Filter>" + " </wfs:Lock>"
055: + "</wfs:LockFeature>";
056: dom = postAsDOM("wfs", xml);
057:
058: // release the lock
059: get("wfs?request=ReleaseLock&lockId=" + lockId);
060:
061: assertEquals("WFS_LockFeatureResponse", dom
062: .getDocumentElement().getNodeName());
063: assertFalse(dom.getElementsByTagName("FeaturesNotLocked")
064: .getLength() == 0);
065: }
066:
067: public void testDeleteWithoutLockId() throws Exception {
068: // get a feature
069: String xml = "<wfs:GetFeature" + " service=\"WFS\""
070: + " version=\"1.0.0\"" + " outputFormat=\"GML2\""
071: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
072: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
073: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
074: + " <wfs:Query typeName=\"cdf:Locks\" />"
075: + "</wfs:GetFeature>";
076:
077: Document dom = postAsDOM("wfs", xml);
078: assertEquals("wfs:FeatureCollection", dom.getDocumentElement()
079: .getNodeName());
080:
081: // get a fid
082: String fid = ((Element) dom.getElementsByTagName("cdf:Locks")
083: .item(0)).getAttribute("fid");
084:
085: // lock the feature
086: xml = "<wfs:LockFeature" + " service=\"WFS\""
087: + " version=\"1.0.0\"" + " expiry=\"10\""
088: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
089: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
090: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
091: + " <wfs:Lock typeName=\"cdf:Locks\">"
092: + " <ogc:Filter>" + " <ogc:FeatureId fid=\""
093: + fid + "\"/>" + " </ogc:Filter>" + " </wfs:Lock>"
094: + "</wfs:LockFeature>";
095: dom = postAsDOM("wfs", xml);
096: assertEquals("WFS_LockFeatureResponse", dom
097: .getDocumentElement().getNodeName());
098:
099: String lockId = dom.getElementsByTagName("LockId").item(0)
100: .getFirstChild().getNodeValue();
101:
102: xml = "<wfs:Transaction" + " service=\"WFS\""
103: + " version=\"1.0.0\""
104: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
105: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
106: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
107: + " <wfs:Delete typeName=\"cdf:Locks\">"
108: + " <ogc:Filter>" + " <ogc:FeatureId fid=\""
109: + fid + "\"/>" + " </ogc:Filter>"
110: + " </wfs:Delete>" + "</wfs:Transaction>";
111: dom = postAsDOM("wfs", xml);
112:
113: // release the lock
114: get("wfs?request=ReleaseLock&lockId=" + lockId);
115:
116: assertTrue("ServiceExceptionReport".equals(dom
117: .getDocumentElement().getNodeName())
118: || dom.getElementsByTagName("wfs:FAILED").getLength() == 1);
119:
120: }
121:
122: public void testUpdateWithLockId() throws Exception {
123: // get a feature
124: String xml = "<wfs:GetFeature" + " service=\"WFS\""
125: + " version=\"1.0.0\"" + " outputFormat=\"GML2\""
126: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
127: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
128: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
129: + " <wfs:Query typeName=\"cdf:Locks\" />"
130: + "</wfs:GetFeature>";
131:
132: Document dom = postAsDOM("wfs", xml);
133: assertEquals("wfs:FeatureCollection", dom.getDocumentElement()
134: .getNodeName());
135:
136: // get a fid
137: String fid = ((Element) dom.getElementsByTagName("cdf:Locks")
138: .item(0)).getAttribute("fid");
139:
140: // lock the feature
141: xml = "<wfs:LockFeature" + " service=\"WFS\""
142: + " version=\"1.0.0\"" + " expiry=\"10\""
143: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
144: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
145: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
146: + " <wfs:Lock typeName=\"cdf:Locks\">"
147: + " <ogc:Filter>" + " <ogc:FeatureId fid=\""
148: + fid + "\"/>" + " </ogc:Filter>" + " </wfs:Lock>"
149: + "</wfs:LockFeature>";
150: dom = postAsDOM("wfs", xml);
151: assertEquals("WFS_LockFeatureResponse", dom
152: .getDocumentElement().getNodeName());
153:
154: // get the lockId
155: String lockId = dom.getElementsByTagName("LockId").item(0)
156: .getFirstChild().getNodeValue();
157:
158: // update the feawture
159: xml = "<wfs:Transaction" + " service=\"WFS\""
160: + " version=\"1.0.0\""
161: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
162: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
163: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
164: + " <wfs:LockId>" + lockId + "</wfs:LockId>"
165: + " <wfs:Update typeName=\"cdf:Locks\">"
166: + " <wfs:Property>"
167: + " <wfs:Name>cdf:id</wfs:Name>"
168: + " <wfs:Value>lfbt0002</wfs:Value>"
169: + " </wfs:Property>" + " <ogc:Filter>"
170: + " <ogc:FeatureId fid=\"" + fid + "\"/>"
171: + " </ogc:Filter>" + " </wfs:Update>"
172: + "</wfs:Transaction>";
173: dom = postAsDOM("wfs", xml);
174:
175: // release the lock
176: get("wfs?request=ReleaseLock&lockId=" + lockId);
177:
178: assertFalse(dom.getElementsByTagName("wfs:SUCCESS").getLength() == 0);
179: }
180:
181: }
|