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();
}
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);
}
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);
}
Aggregations