001: package org.geoserver.wfs;
002:
003: import org.w3c.dom.Document;
004: import org.w3c.dom.Element;
005: import org.w3c.dom.NodeList;
006:
007: public class GetFeatureWithLockTest extends WFSTestSupport {
008:
009: public void testUpdateLockedFeatureWithLockId() throws Exception {
010: // get feature
011: String xml = "<wfs:GetFeature " + "service=\"WFS\" "
012: + "version=\"1.0.0\" " + "expiry=\"10\" "
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:
021: // get a fid
022: assertEquals("wfs:FeatureCollection", dom.getDocumentElement()
023: .getNodeName());
024: assertFalse(dom.getElementsByTagName("cdf:Locks").getLength() == 0);
025:
026: String fid = ((Element) dom.getElementsByTagName("cdf:Locks")
027: .item(0)).getAttribute("fid");
028:
029: // lock a feature
030: xml = "<wfs:GetFeatureWithLock " + "service=\"WFS\" "
031: + "version=\"1.0.0\" " + "expiry=\"10\" "
032: + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
033: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
034: + "xmlns:wfs=\"http://www.opengis.net/wfs\">"
035: + "<wfs:Query typeName=\"cdf:Locks\">" + "<ogc:Filter>"
036: + "<ogc:FeatureId fid=\"" + fid + "\"/>"
037: + "</ogc:Filter>" + "</wfs:Query>"
038: + "</wfs:GetFeatureWithLock>";
039:
040: dom = postAsDOM("wfs", xml);
041: assertEquals("wfs:FeatureCollection", dom.getDocumentElement()
042: .getNodeName());
043:
044: String lockId = dom.getDocumentElement().getAttribute("lockId");
045:
046: // try to update it
047: xml = "<wfs:Transaction " + " service=\"WFS\" "
048: + " version=\"1.0.0\" "
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:LockId>" + lockId + "</wfs:LockId>"
053: + " <wfs:Update typeName=\"cdf:Locks\"> "
054: + " <wfs:Property> "
055: + " <wfs:Name>cdf:id</wfs:Name> "
056: + " <wfs:Value>gfwlbt0001</wfs:Value> "
057: + " </wfs:Property> " + " <ogc:Filter> "
058: + " <ogc:FeatureId fid=\"" + fid + "\"/> "
059: + " </ogc:Filter> " + " </wfs:Update> "
060: + "</wfs:Transaction> ";
061:
062: dom = postAsDOM("wfs", xml);
063:
064: // release the lock
065: get("wfs?request=ReleaseLock&version=1.1.0&lockId=" + lockId);
066:
067: assertEquals("wfs:WFS_TransactionResponse", dom
068: .getDocumentElement().getNodeName());
069: assertEquals(1, dom.getElementsByTagName("wfs:SUCCESS")
070: .getLength());
071: }
072:
073: public void testUpdateLockedFeatureWithoutLockId() throws Exception {
074:
075: // get feature
076: String xml = "<wfs:GetFeature " + "service=\"WFS\" "
077: + "version=\"1.0.0\" " + "expiry=\"10\" "
078: + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
079: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
080: + "xmlns:wfs=\"http://www.opengis.net/wfs\">"
081: + "<wfs:Query typeName=\"cdf:Locks\"/>"
082: + "</wfs:GetFeature>";
083:
084: Document dom = postAsDOM("wfs", xml);
085:
086: // get a fid
087: assertEquals("wfs:FeatureCollection", dom.getDocumentElement()
088: .getNodeName());
089: assertFalse(dom.getElementsByTagName("cdf:Locks").getLength() == 0);
090:
091: String fid = ((Element) dom.getElementsByTagName("cdf:Locks")
092: .item(0)).getAttribute("fid");
093:
094: // lock a feature
095: xml = "<wfs:GetFeatureWithLock " + "service=\"WFS\" "
096: + "version=\"1.0.0\" " + "expiry=\"10\" "
097: + "xmlns:cdf=\"http://www.opengis.net/cite/data\" "
098: + "xmlns:ogc=\"http://www.opengis.net/ogc\" "
099: + "xmlns:wfs=\"http://www.opengis.net/wfs\">"
100: + "<wfs:Query typeName=\"cdf:Locks\">" + "<ogc:Filter>"
101: + "<ogc:FeatureId fid=\"" + fid + "\"/>"
102: + "</ogc:Filter>" + "</wfs:Query>"
103: + "</wfs:GetFeatureWithLock>";
104:
105: dom = postAsDOM("wfs", xml);
106: assertEquals("wfs:FeatureCollection", dom.getDocumentElement()
107: .getNodeName());
108:
109: String lockId = dom.getDocumentElement().getAttribute("lockId");
110:
111: // try to update it
112: xml = "<wfs:Transaction " + " service=\"WFS\" "
113: + " version=\"1.0.0\" "
114: + " xmlns:cdf=\"http://www.opengis.net/cite/data\" "
115: + " xmlns:ogc=\"http://www.opengis.net/ogc\" "
116: + " xmlns:wfs=\"http://www.opengis.net/wfs\" " + "> "
117: + " <wfs:Update typeName=\"cdf:Locks\"> "
118: + " <wfs:Property> "
119: + " <wfs:Name>cdf:id</wfs:Name> "
120: + " <wfs:Value>gfwlbt0001</wfs:Value> "
121: + " </wfs:Property> " + " <ogc:Filter> "
122: + " <ogc:FeatureId fid=\"" + fid + "\"/> "
123: + " </ogc:Filter> " + " </wfs:Update> "
124: + "</wfs:Transaction> ";
125:
126: dom = postAsDOM("wfs", xml);
127:
128: // release the lock
129: get("wfs?request=ReleaseLock&lockId=" + lockId);
130:
131: // assertEquals( "wfs:WFS_TransactionResponse",
132: // dom.getDocumentElement().getNodeName() );
133: assertTrue(1 == dom.getElementsByTagName("wfs:FAILED")
134: .getLength()
135: || "ServiceExceptionReport".equals(dom
136: .getDocumentElement().getNodeName()));
137: }
138:
139: public void testGetFeatureWithLockReleaseActionSome()
140: throws Exception {
141: String xml = "<wfs:GetFeature" + " 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:Query typeName=\"cdf:Locks\"/>"
147: + "</wfs:GetFeature>";
148: Document dom = postAsDOM("wfs", xml);
149:
150: // get two fids
151: NodeList locks = dom.getElementsByTagName("cdf:Locks");
152: String fid1 = ((Element) locks.item(0)).getAttribute("fid");
153: String fid2 = ((Element) locks.item(1)).getAttribute("fid");
154:
155: xml = "<wfs:GetFeatureWithLock" + " service=\"WFS\""
156: + " version=\"1.0.0\"" + " expiry=\"10\""
157: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
158: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
159: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
160: + " <wfs:Query typeName=\"cdf:Locks\">"
161: + " <ogc:Filter>" + " <ogc:FeatureId fid=\""
162: + fid1 + "\"/>" + " <ogc:FeatureId fid=\"" + fid2
163: + "\"/>" + " </ogc:Filter>" + " </wfs:Query>"
164: + "</wfs:GetFeatureWithLock>";
165:
166: dom = postAsDOM("wfs", xml);
167:
168: assertEquals("wfs:FeatureCollection", dom.getDocumentElement()
169: .getNodeName());
170:
171: String lockId = dom.getDocumentElement().getAttribute("lockId");
172: //System.out.println(lockId);
173: xml = "<wfs:Transaction" + " service=\"WFS\""
174: + " version=\"1.0.0\"" + " releaseAction=\"SOME\""
175: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
176: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
177: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
178: + " <wfs:LockId>" + lockId + "</wfs:LockId>"
179: + " <wfs:Update typeName=\"cdf:Locks\">"
180: + " <wfs:Property>"
181: + " <wfs:Name>cdf:id</wfs:Name>"
182: + " <wfs:Value>gfwlrs0003</wfs:Value>"
183: + " </wfs:Property>" + " <ogc:Filter>"
184: + " <ogc:FeatureId fid=\"" + fid1 + "\"/>"
185: + " </ogc:Filter>" + " </wfs:Update>"
186: + "</wfs:Transaction>";
187:
188: dom = postAsDOM("wfs", xml);
189:
190: assertEquals("wfs:WFS_TransactionResponse", dom
191: .getDocumentElement().getNodeName());
192: assertEquals(1, dom.getElementsByTagName("wfs:SUCCESS")
193: .getLength());
194:
195: xml = "<wfs:Transaction" + " service=\"WFS\""
196: + " version=\"1.0.0\""
197: + " xmlns:cdf=\"http://www.opengis.net/cite/data\""
198: + " xmlns:ogc=\"http://www.opengis.net/ogc\""
199: + " xmlns:wfs=\"http://www.opengis.net/wfs\"" + ">"
200: + " <wfs:LockId>" + lockId + "</wfs:LockId>"
201: + " <wfs:Update typeName=\"cdf:Locks\">"
202: + " <wfs:Property>"
203: + " <wfs:Name>cdf:id</wfs:Name>"
204: + " <wfs:Value>gfwlrs0004</wfs:Value>"
205: + " </wfs:Property>" + " <ogc:Filter>"
206: + " <ogc:FeatureId fid=\"" + fid2 + "\"/>"
207: + " </ogc:Filter>" + " </wfs:Update>"
208: + "</wfs:Transaction>";
209:
210: dom = postAsDOM("wfs", xml);
211:
212: // release locks
213: get("wfs?request=ReleaseLock&lockId=" + lockId);
214:
215: assertEquals("wfs:WFS_TransactionResponse", dom
216: .getDocumentElement().getNodeName());
217: assertEquals(1, dom.getElementsByTagName("wfs:SUCCESS")
218: .getLength());
219:
220: }
221: }
|