01: package org.geoserver.wfs.response;
02:
03: import java.io.File;
04: import java.io.FileOutputStream;
05:
06: import javax.xml.parsers.DocumentBuilderFactory;
07:
08: import org.geoserver.wfs.WFSTestSupport;
09: import org.w3c.dom.Document;
10: import org.w3c.dom.Element;
11: import org.w3c.dom.NodeList;
12:
13: public class WfsXmlWriterTest extends WFSTestSupport {
14:
15: public void test() throws Exception {
16: File tmp = File.createTempFile("wfs", "xml");
17: tmp.deleteOnExit();
18:
19: WfsXmlWriter writer = new WfsXmlWriter.WFS1_0(getWFS(),
20: new FileOutputStream(tmp));
21: writer.openTag("wfs", "FeatureCollection");
22: writer.openTag("gml", "Feature", new String[] { "id", "foo",
23: "srs", "4326" });
24: writer.text("some text");
25: writer.closeTag("gml", "Feature");
26: writer.closeTag("wfs", "FeatureCollection");
27: writer.close();
28:
29: DocumentBuilderFactory factory = DocumentBuilderFactory
30: .newInstance();
31: factory.setNamespaceAware(true);
32:
33: Document doc = factory.newDocumentBuilder().parse(tmp);
34:
35: assertNotNull(doc);
36:
37: assertEquals("wfs:FeatureCollection", doc.getDocumentElement()
38: .getNodeName());
39: NodeList features = doc.getElementsByTagName("gml:Feature");
40: assertEquals(1, features.getLength());
41:
42: Element feature = (Element) features.item(0);
43: assertEquals("foo", feature.getAttribute("id"));
44: assertEquals("4326", feature.getAttribute("srs"));
45: }
46: }
|