001: package org.geoserver.wfs.xml;
002:
003: import java.io.ByteArrayInputStream;
004: import java.io.ByteArrayOutputStream;
005:
006: import javax.xml.parsers.DocumentBuilder;
007: import javax.xml.parsers.DocumentBuilderFactory;
008:
009: import net.opengis.wfs.FeatureCollectionType;
010: import net.opengis.wfs.GetFeatureType;
011: import net.opengis.wfs.WfsFactory;
012:
013: import org.geoserver.data.test.MockData;
014: import org.geoserver.platform.Operation;
015: import org.geoserver.platform.Service;
016: import org.geoserver.wfs.WFSTestSupport;
017: import org.geoserver.wfs.xml.v1_1_0.WFSConfiguration;
018: import org.geotools.data.FeatureSource;
019: import org.geotools.feature.FeatureCollection;
020: import org.vfny.geoserver.global.DataStoreInfo;
021: import org.w3c.dom.Document;
022:
023: public class GML3FeatureProducerTest extends WFSTestSupport {
024:
025: GML3OutputFormat producer() {
026: WFSConfiguration configuration = new WFSConfiguration(
027: getCatalog(), new FeatureTypeSchemaBuilder.GML3(
028: getWFS(), getCatalog(), getResourceLoader()));
029: return new GML3OutputFormat(getWFS(), getCatalog(),
030: configuration);
031: }
032:
033: Operation request() {
034: Service service = new Service("wfs", null, null);
035: GetFeatureType type = WfsFactory.eINSTANCE
036: .createGetFeatureType();
037: type.setBaseUrl("http://localhost:8080/geoserver");
038:
039: Operation request = new Operation("wfs", service, null,
040: new Object[] { type });
041: return request;
042: }
043:
044: public void testSingle() throws Exception {
045: DataStoreInfo dataStore = getCatalog().getDataStoreInfo(
046: MockData.CDF_PREFIX);
047: FeatureSource source = dataStore.getDataStore()
048: .getFeatureSource(MockData.SEVEN.getLocalPart());
049: FeatureCollection features = source.getFeatures();
050:
051: FeatureCollectionType fcType = WfsFactory.eINSTANCE
052: .createFeatureCollectionType();
053:
054: fcType.getFeature().add(features);
055:
056: ByteArrayOutputStream output = new ByteArrayOutputStream();
057: producer().write(fcType, output, request());
058:
059: DocumentBuilder docBuilder = DocumentBuilderFactory
060: .newInstance().newDocumentBuilder();
061: Document document = docBuilder.parse(new ByteArrayInputStream(
062: output.toByteArray()));
063: assertEquals(7, document.getElementsByTagName("cdf:Seven")
064: .getLength());
065:
066: }
067:
068: public void testMultipleSameNamespace() throws Exception {
069: DataStoreInfo dataStore = getCatalog().getDataStoreInfo(
070: MockData.CDF_PREFIX);
071:
072: FeatureCollectionType fcType = WfsFactory.eINSTANCE
073: .createFeatureCollectionType();
074: fcType.getFeature().add(
075: dataStore.getDataStore().getFeatureSource(
076: MockData.SEVEN.getLocalPart()).getFeatures());
077: fcType.getFeature().add(
078: dataStore.getDataStore().getFeatureSource(
079: MockData.FIFTEEN.getLocalPart()).getFeatures());
080:
081: ByteArrayOutputStream output = new ByteArrayOutputStream();
082: producer().write(fcType, output, request());
083:
084: DocumentBuilder docBuilder = DocumentBuilderFactory
085: .newInstance().newDocumentBuilder();
086: Document document = docBuilder.parse(new ByteArrayInputStream(
087: output.toByteArray()));
088: assertEquals(7 + 15, document.getElementsByTagName("cdf:Seven")
089: .getLength()
090: + document.getElementsByTagName("cdf:Fifteen")
091: .getLength());
092: }
093:
094: public void testMultipleDifferentNamespace() throws Exception {
095: DataStoreInfo seven = getCatalog().getDataStoreInfo(
096: MockData.CDF_PREFIX);
097: DataStoreInfo polys = getCatalog().getDataStoreInfo(
098: MockData.CGF_PREFIX);
099:
100: FeatureCollectionType fcType = WfsFactory.eINSTANCE
101: .createFeatureCollectionType();
102: fcType.getFeature().add(
103: seven.getDataStore().getFeatureSource(
104: MockData.SEVEN.getLocalPart()).getFeatures());
105: fcType.getFeature()
106: .add(
107: polys.getDataStore().getFeatureSource(
108: MockData.POLYGONS.getLocalPart())
109: .getFeatures());
110: int npolys = polys.getDataStore().getFeatureSource(
111: MockData.POLYGONS.getLocalPart()).getFeatures().size();
112:
113: ByteArrayOutputStream output = new ByteArrayOutputStream();
114: producer().write(fcType, output, request());
115:
116: DocumentBuilder docBuilder = DocumentBuilderFactory
117: .newInstance().newDocumentBuilder();
118: Document document = docBuilder.parse(new ByteArrayInputStream(
119: output.toByteArray()));
120: assertEquals(7 + npolys, document.getElementsByTagName(
121: "cdf:Seven").getLength()
122: + document.getElementsByTagName("cgf:Polygons")
123: .getLength());
124: }
125:
126: }
|