Search in sources :

Example 6 with XmlSchemaCollection

use of org.apache.ws.commons.schema.XmlSchemaCollection in project ddf by codice.

the class TestWfsSource method setUp.

public void setUp(final String schema, final List<Object> supportedGeos, final String srsName, final Integer numFeatures, final Integer numResults) throws WfsException, SecurityServiceException {
    mockFactory = mock(SecureCxfClientFactory.class);
    when(mockFactory.getClient()).thenReturn(mockWfs);
    // GetCapabilities Response
    when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilites);
    mockCapabilites.setFilterCapabilities(new FilterCapabilities());
    mockCapabilites.getFilterCapabilities().setSpatialCapabilities(new SpatialCapabilitiesType());
    mockCapabilites.getFilterCapabilities().getSpatialCapabilities().setSpatialOperators(new SpatialOperatorsType());
    if (null != supportedGeos && !supportedGeos.isEmpty()) {
        mockCapabilites.getFilterCapabilities().getSpatialCapabilities().getSpatialOperators().getBBOXOrEqualsOrDisjoint().addAll(supportedGeos);
    }
    // DescribeFeatureType Response
    XmlSchema xmlSchema = null;
    if (null != schema) {
        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        wfsUriResolver.setGmlNamespace(Wfs10Constants.GML_NAMESPACE);
        wfsUriResolver.setWfsNamespace(Wfs10Constants.WFS_NAMESPACE);
        schemaCollection.setSchemaResolver(wfsUriResolver);
        xmlSchema = schemaCollection.read(new StreamSource(new ByteArrayInputStream(schema.getBytes())));
    }
    when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenReturn(xmlSchema);
    sampleFeatures = new ArrayList<>();
    mockCapabilites.setFeatureTypeList(new FeatureTypeListType());
    if (numFeatures != null) {
        for (int ii = 0; ii < numFeatures; ii++) {
            FeatureTypeType feature = new FeatureTypeType();
            QName qName;
            if (ii == 0) {
                qName = new QName("SampleFeature" + ii);
            } else {
                qName = new QName("http://example.com", "SampleFeature" + ii, "Prefix" + ii);
            }
            sampleFeatures.add(qName);
            feature.setName(qName);
            // feature.setName(SAMPLE_FEATURE[ii]);
            if (null != srsName) {
                feature.setSRS(srsName);
            }
            mockCapabilites.getFeatureTypeList().getFeatureType().add(feature);
        }
    }
    // GetFeature Response
    when(mockWfs.getFeature(any(GetFeatureType.class))).thenReturn(mockFeatureCollection);
    when(mockFeatureCollection.getFeatureMembers()).thenAnswer(new Answer<List<Metacard>>() {

        @Override
        public List<Metacard> answer(InvocationOnMock invocation) {
            // Create as many metacards as there are features
            Integer resultsToReturn = numResults;
            if (resultsToReturn == null && numFeatures != null) {
                resultsToReturn = numFeatures;
            }
            List<Metacard> metacards = new ArrayList<Metacard>(resultsToReturn);
            for (int i = 0; i < resultsToReturn; i++) {
                MetacardImpl mc = new MetacardImpl();
                mc.setId("ID_" + String.valueOf(i + 1));
                metacards.add(mc);
            }
            return metacards;
        }
    });
    when(mockAvailabilityTask.isAvailable()).thenReturn(true);
    source = new WfsSource(new GeotoolsFilterAdapterImpl(), mockContext, mockAvailabilityTask, mockFactory, encryptionService);
}
Also used : SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) SpatialCapabilitiesType(ogc.schema.opengis.filter_capabilities.v_1_0_0.SpatialCapabilitiesType) FilterCapabilities(ogc.schema.opengis.filter_capabilities.v_1_0_0.FilterCapabilities) SpatialOperatorsType(ogc.schema.opengis.filter_capabilities.v_1_0_0.SpatialOperatorsType) List(java.util.List) ArrayList(java.util.ArrayList) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.GetCapabilitiesRequest) FeatureTypeType(ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeType) FeatureTypeListType(ogc.schema.opengis.wfs_capabilities.v_1_0_0.FeatureTypeListType) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) BigInteger(java.math.BigInteger) Metacard(ddf.catalog.data.Metacard) XmlSchema(org.apache.ws.commons.schema.XmlSchema) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.common.DescribeFeatureTypeRequest) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)

Aggregations

XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)6 XmlSchema (org.apache.ws.commons.schema.XmlSchema)5 ArrayList (java.util.ArrayList)3 Metacard (ddf.catalog.data.Metacard)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 List (java.util.List)2 QName (javax.xml.namespace.QName)2 StreamSource (javax.xml.transform.stream.StreamSource)2 SecureCxfClientFactory (org.codice.ddf.cxf.SecureCxfClientFactory)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 BigInteger (java.math.BigInteger)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Definition (javax.wsdl.Definition)1