Search in sources :

Example 1 with WfsFeatureCollectionImpl

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollectionImpl in project ddf by codice.

the class WfsSourceTest method setUpMocks.

private void setUpMocks(final List<String> supportedGeos, final String srsName, final int results, final int hits) throws WfsException {
    SecureCxfClientFactory<ExtendedWfs> mockFactory = mock(SecureCxfClientFactory.class);
    when(mockFactory.getClient()).thenReturn(mockWfs);
    clientBuilderFactory = mock(ClientBuilderFactory.class);
    ClientBuilder<ExtendedWfs> clientBuilder = new ClientBuilderImpl<ExtendedWfs>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {

        @Override
        public SecureCxfClientFactory<ExtendedWfs> build() {
            return mockFactory;
        }
    };
    when(clientBuilderFactory.<ExtendedWfs>getClientBuilder()).thenReturn(clientBuilder);
    // GetCapabilities Response
    when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilities);
    mockCapabilities.setFilterCapabilities(new FilterCapabilities());
    mockCapabilities.getFilterCapabilities().setSpatialCapabilities(new SpatialCapabilitiesType());
    mockCapabilities.getFilterCapabilities().getSpatialCapabilities().setSpatialOperators(new SpatialOperatorsType());
    if (CollectionUtils.isNotEmpty(supportedGeos)) {
        mockCapabilities.getFilterCapabilities().getSpatialCapabilities().getSpatialOperators().getSpatialOperator().addAll(supportedGeos.stream().map(opName -> {
            SpatialOperatorType spatialOperatorType = new SpatialOperatorType();
            spatialOperatorType.setName(SpatialOperatorNameType.fromValue(opName));
            return spatialOperatorType;
        }).collect(Collectors.toList()));
    }
    mockCapabilities.getFilterCapabilities().getSpatialCapabilities().setGeometryOperands(new GeometryOperandsType());
    mockCapabilities.getFilterCapabilities().getSpatialCapabilities().getGeometryOperands().getGeometryOperand().addAll(Arrays.asList(Wfs11Constants.POLYGON, Wfs11Constants.POINT));
    sampleFeatures = new ArrayList<>();
    mockCapabilities.setFeatureTypeList(new FeatureTypeListType());
    for (int ii = 0; ii < results; 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);
        if (null != srsName) {
            feature.setDefaultSRS(srsName);
        }
        mockCapabilities.getFeatureTypeList().getFeatureType().add(feature);
    }
    List<Metacard> metacards = new ArrayList<>(results);
    for (int i = 0; i < results; i++) {
        MetacardImpl mc = new MetacardImpl();
        mc.setId("ID_" + (i + 1));
        metacards.add(mc);
    }
    when(mockWfs.getFeature(withResultType(ResultTypeType.HITS))).thenReturn(new WfsFeatureCollectionImpl(hits));
    when(mockWfs.getFeature(withResultType(ResultTypeType.RESULTS))).thenReturn(new WfsFeatureCollectionImpl(results, metacards));
    final ScheduledFuture<?> mockAvailabilityPollFuture = mock(ScheduledFuture.class);
    doReturn(mockAvailabilityPollFuture).when(mockScheduler).scheduleWithFixedDelay(any(), anyInt(), anyInt(), any());
    source = new WfsSource(clientBuilderFactory, encryptionService, mockScheduler);
    source.setId(WFS_ID);
    source.setFilterAdapter(new GeotoolsFilterAdapterImpl());
    source.setContext(mockContext);
    source.setWfsMetacardTypeRegistry(mockWfsMetacardTypeRegistry);
    source.setMetacardTypeEnhancers(Collections.emptyList());
    source.setMetacardMappers(metacardMappers);
    source.setPollInterval(10);
    source.setWfsUrl(SAMPLE_WFS_URL);
    source.setSupportsStartIndex(false);
    source.setForceAllGeometryOperands(forceAllGeometryOperands);
    source.init();
}
Also used : SecurityManager(ddf.security.service.SecurityManager) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) ArrayList(java.util.ArrayList) SpatialCapabilitiesType(net.opengis.filter.v_1_1_0.SpatialCapabilitiesType) FilterCapabilities(net.opengis.filter.v_1_1_0.FilterCapabilities) SpatialOperatorsType(net.opengis.filter.v_1_1_0.SpatialOperatorsType) WfsFeatureCollectionImpl(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollectionImpl) GeometryOperandsType(net.opengis.filter.v_1_1_0.GeometryOperandsType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.wfs.v110.catalog.common.GetCapabilitiesRequest) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) FeatureTypeType(net.opengis.wfs.v_1_1_0.FeatureTypeType) FeatureTypeListType(net.opengis.wfs.v_1_1_0.FeatureTypeListType) QName(javax.xml.namespace.QName) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) SpatialOperatorType(net.opengis.filter.v_1_1_0.SpatialOperatorType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SecurityLogger(ddf.security.audit.SecurityLogger)

Example 2 with WfsFeatureCollectionImpl

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollectionImpl in project ddf by codice.

the class WfsSourceTest method testPagingToSecondPageWithStartIndex.

@Test
public void testPagingToSecondPageWithStartIndex() throws Exception {
    int pageSize = 4;
    int startIndex = 5;
    mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, MAX_FEATURES);
    setUpMocks(null, null, pageSize, MAX_FEATURES);
    List<Metacard> metacards = new ArrayList<>(pageSize);
    for (int i = startIndex; i < startIndex + pageSize; i++) {
        MetacardImpl mc = new MetacardImpl();
        mc.setId("ID_" + i);
        metacards.add(mc);
    }
    when(mockWfs.getFeature(withResultType(ResultTypeType.HITS))).thenReturn(new WfsFeatureCollectionImpl(MAX_FEATURES));
    when(mockWfs.getFeature(hasStartIndex(startIndex))).thenReturn(new WfsFeatureCollectionImpl(pageSize, metacards));
    source.setSupportsStartIndex(true);
    SourceResponse response = executeQuery(startIndex, pageSize);
    List<Result> results = response.getResults();
    assertThat(response.getHits(), equalTo((long) MAX_FEATURES));
    // Verify that metacards 5 thru 8 were returned
    assertCorrectMetacardsReturned(results, startIndex, pageSize);
}
Also used : Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) WfsFeatureCollectionImpl(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollectionImpl) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 3 with WfsFeatureCollectionImpl

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollectionImpl in project ddf by codice.

the class WfsSourceTest method testPagingWithFirstPageWithStartIndex.

@Test
public void testPagingWithFirstPageWithStartIndex() throws Exception {
    int pageSize = 4;
    int startIndex = 1;
    mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, MAX_FEATURES);
    setUpMocks(null, null, pageSize, MAX_FEATURES);
    List<Metacard> metacards = new ArrayList<>(pageSize);
    for (int i = startIndex; i < startIndex + pageSize; i++) {
        MetacardImpl mc = new MetacardImpl();
        mc.setId("ID_" + i);
        metacards.add(mc);
    }
    when(mockWfs.getFeature(withResultType(ResultTypeType.HITS))).thenReturn(new WfsFeatureCollectionImpl(MAX_FEATURES));
    when(mockWfs.getFeature(hasStartIndex(startIndex))).thenReturn(new WfsFeatureCollectionImpl(pageSize, metacards));
    source.setSupportsStartIndex(true);
    SourceResponse response = executeQuery(startIndex, pageSize);
    List<Result> results = response.getResults();
    assertThat(response.getHits(), equalTo((long) MAX_FEATURES));
    // Verify that metacards 1 thru 4 were returned
    assertCorrectMetacardsReturned(results, startIndex, pageSize);
}
Also used : Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) WfsFeatureCollectionImpl(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollectionImpl) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

Metacard (ddf.catalog.data.Metacard)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 ArrayList (java.util.ArrayList)3 WfsFeatureCollectionImpl (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollectionImpl)3 Result (ddf.catalog.data.Result)2 SourceResponse (ddf.catalog.operation.SourceResponse)2 Test (org.junit.Test)2 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)1 SecurityLogger (ddf.security.audit.SecurityLogger)1 SecurityManager (ddf.security.service.SecurityManager)1 QName (javax.xml.namespace.QName)1 FilterCapabilities (net.opengis.filter.v_1_1_0.FilterCapabilities)1 GeometryOperandsType (net.opengis.filter.v_1_1_0.GeometryOperandsType)1 SpatialCapabilitiesType (net.opengis.filter.v_1_1_0.SpatialCapabilitiesType)1 SpatialOperatorType (net.opengis.filter.v_1_1_0.SpatialOperatorType)1 SpatialOperatorsType (net.opengis.filter.v_1_1_0.SpatialOperatorsType)1 FeatureTypeListType (net.opengis.wfs.v_1_1_0.FeatureTypeListType)1 FeatureTypeType (net.opengis.wfs.v_1_1_0.FeatureTypeType)1 ClientBuilderFactory (org.codice.ddf.cxf.client.ClientBuilderFactory)1 ClientBuilderImpl (org.codice.ddf.cxf.client.impl.ClientBuilderImpl)1