use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testPropertyIsLikeQuery.
@Test
public void testPropertyIsLikeQuery() throws Exception {
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
propertyIsLikeQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
assertThat(getFeatureType.getQuery().size(), is(ONE_FEATURE));
QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
assertThat(query.getFilter().isSetComparisonOps(), is(true));
assertThat(query.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType 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();
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testIntersectQuery.
@Test
public void testIntersectQuery() throws Exception {
mapSchemaToFeatures(ONE_GML_PROPERTY_SCHEMA, ONE_FEATURE);
setUpMocks(Arrays.asList("Intersects", "BBOX"), SRS_NAME, ONE_FEATURE, ONE_FEATURE);
Filter intersectFilter = builder.attribute(Metacard.ANY_GEO).is().intersecting().wkt(POLYGON_WKT);
QueryImpl intersectQuery = new QueryImpl(intersectFilter);
intersectQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(intersectQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertMaxFeatures(getFeatureType, intersectQuery);
assertThat(getFeatureType.getQuery().size(), is(ONE_FEATURE));
QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
assertThat(query.getFilter().isSetSpatialOps(), is(true));
assertThat(query.getFilter().getSpatialOps().getValue(), is(instanceOf(SpatialOpsType.class)));
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method assertFeature.
private void assertFeature(ExtendedGetFeatureType getFeatureType, boolean sortingEnabled, String sortProperty, String sortOrder) {
assertThat(getFeatureType.getQuery().size(), is(ONE_FEATURE));
final QueryType queryType = getFeatureType.getQuery().get(0);
if (sortingEnabled) {
assertThat(queryType.isSetSortBy(), is(true));
assertThat(queryType.getSortBy().getSortProperty().size(), is(1));
assertThat(queryType.getSortBy().getSortProperty().get(0).getPropertyName().getContent().size(), is(1));
assertThat(queryType.getSortBy().getSortProperty().get(0).getPropertyName().getContent().get(0), is(sortProperty));
assertThat(queryType.getSortBy().getSortProperty().get(0).getSortOrder().value(), is(sortOrder));
} else {
assertThat(queryType.isSetSortBy(), is(false));
}
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testAndQuery.
@Test
public void testAndQuery() throws Exception {
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
Filter propertyIsLikeFilter = builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL);
Filter contentTypeFilter = builder.attribute(Metacard.ANY_TEXT).is().like().text(sampleFeatures.get(0).getLocalPart());
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.allOf(propertyIsLikeFilter, contentTypeFilter));
propertyIsLikeQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
assertThat(getFeatureType.getQuery().size(), is(ONE_FEATURE));
QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
assertThat(query.getFilter().isSetLogicOps(), is(true));
assertThat(query.getFilter().getLogicOps().getValue(), is(instanceOf(BinaryLogicOpType.class)));
}
Aggregations