01: package org.geoserver.wfs.v1_1;
02:
03: import java.io.ByteArrayOutputStream;
04: import java.io.StringReader;
05:
06: import net.opengis.wfs.DescribeFeatureTypeType;
07: import net.opengis.wfs.GetFeatureType;
08: import net.opengis.wfs.WfsFactory;
09:
10: import org.geoserver.data.test.MockData;
11: import org.geoserver.platform.Operation;
12: import org.geoserver.platform.Service;
13: import org.geoserver.util.ReaderUtils;
14: import org.geoserver.wfs.WFSTestSupport;
15: import org.geoserver.wfs.xml.v1_1_0.XmlSchemaEncoder;
16: import org.vfny.geoserver.global.Data;
17: import org.vfny.geoserver.global.FeatureTypeInfo;
18: import org.w3c.dom.Element;
19: import org.w3c.dom.NodeList;
20:
21: public class DescribeFeatureResponseTest extends WFSTestSupport {
22:
23: Operation request() {
24: Service service = new Service("wfs", null, null);
25: DescribeFeatureTypeType type = WfsFactory.eINSTANCE
26: .createDescribeFeatureTypeType();
27: type.setBaseUrl("http://localhost:8080/geoserver");
28:
29: Operation request = new Operation("wfs", service, null,
30: new Object[] { type });
31: return request;
32: }
33:
34: public void testSingle() throws Exception {
35: Data catalog = getCatalog();
36: FeatureTypeInfo meta = catalog
37: .getFeatureTypeInfo(MockData.BASIC_POLYGONS);
38:
39: ByteArrayOutputStream output = new ByteArrayOutputStream();
40:
41: XmlSchemaEncoder response = new XmlSchemaEncoder(getWFS(),
42: catalog, getResourceLoader());
43: response.write(new FeatureTypeInfo[] { meta }, output,
44: request());
45:
46: Element schema = ReaderUtils.parse(new StringReader(new String(
47: output.toByteArray())));
48: assertEquals("xsd:schema", schema.getNodeName());
49:
50: NodeList types = schema.getElementsByTagName("xsd:complexType");
51: assertEquals(1, types.getLength());
52: }
53:
54: public void testWithDifferntNamespaces() throws Exception {
55:
56: FeatureTypeInfo meta1 = getCatalog().getFeatureTypeInfo(
57: MockData.BASIC_POLYGONS);
58: FeatureTypeInfo meta2 = getCatalog().getFeatureTypeInfo(
59: MockData.POLYGONS);
60:
61: ByteArrayOutputStream output = new ByteArrayOutputStream();
62:
63: XmlSchemaEncoder response = new XmlSchemaEncoder(getWFS(),
64: getCatalog(), getResourceLoader());
65: response.write(new FeatureTypeInfo[] { meta1, meta2 }, output,
66: request());
67:
68: Element schema = ReaderUtils.parse(new StringReader(new String(
69: output.toByteArray())));
70: assertEquals("xsd:schema", schema.getNodeName());
71:
72: NodeList imprts = schema.getElementsByTagName("xsd:import");
73: assertEquals(2, imprts.getLength());
74:
75: }
76:
77: }
|