use of net.opengis.wfs.v_2_0_0.FeatureTypeListType in project ddf by codice.
the class TestWfsSource method getWfsSource.
public WfsSource getWfsSource(final String schema, final FilterCapabilities filterCapabilities, final String srsName, final int numFeatures, final boolean throwExceptionOnDescribeFeatureType, boolean prefix, int numReturned) throws WfsException, SecurityServiceException {
mockFactory = mock(SecureCxfClientFactory.class);
when(mockFactory.getClient()).thenReturn(mockWfs);
// GetCapabilities Response
when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilites);
when(mockFeatureCollection.getMembers()).thenAnswer(new Answer<List<Metacard>>() {
@Override
public List<Metacard> answer(InvocationOnMock invocation) {
// Create as many metacards as there are features
List<Metacard> metacards = new ArrayList<Metacard>(numFeatures);
for (int i = 0; i < numFeatures; i++) {
MetacardImpl mc = new MetacardImpl();
mc.setId("ID_" + String.valueOf(i + 1));
metacards.add(mc);
}
return metacards;
}
});
if (numReturned != NULL_NUM_RETURNED) {
when(mockFeatureCollection.getNumberReturned()).thenReturn(BigInteger.valueOf(numReturned));
} else {
when(mockFeatureCollection.getNumberReturned()).thenReturn(null);
}
when(mockWfs.getFeature(any(GetFeatureType.class))).thenReturn(mockFeatureCollection);
mockCapabilites.setFilterCapabilities(filterCapabilities);
when(mockAvailabilityTask.isAvailable()).thenReturn(true);
mockCapabilites.setFeatureTypeList(new FeatureTypeListType());
for (int ii = 0; ii < numFeatures; ii++) {
FeatureTypeType feature = new FeatureTypeType();
QName qName;
if (prefix) {
qName = new QName("http://example.com", SAMPLE_FEATURE_NAME + ii, "Prefix" + ii);
} else {
qName = new QName("http://example.com", SAMPLE_FEATURE_NAME + ii);
}
feature.setName(qName);
feature.setDefaultCRS(GeospatialUtil.EPSG_4326_URN);
mockCapabilites.getFeatureTypeList().getFeatureType().add(feature);
}
XmlSchema xmlSchema = null;
if (StringUtils.isNotBlank(schema)) {
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
WfsUriResolver wfsUriResolver = new WfsUriResolver();
wfsUriResolver.setGmlNamespace(Wfs20Constants.GML_3_2_NAMESPACE);
wfsUriResolver.setWfsNamespace(Wfs20Constants.WFS_2_0_NAMESPACE);
schemaCollection.setSchemaResolver(wfsUriResolver);
xmlSchema = schemaCollection.read(new StreamSource(new ByteArrayInputStream(schema.getBytes())));
}
if (throwExceptionOnDescribeFeatureType) {
when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenThrow(new WfsException(""));
} else {
when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenReturn(xmlSchema);
}
WfsSource wfsSource = new WfsSource(new GeotoolsFilterAdapterImpl(), mockContext, mockAvailabilityTask, mockFactory, encryptionService);
wfsSource.setFeatureCollectionReader(mockReader);
return wfsSource;
}
use of net.opengis.wfs.v_2_0_0.FeatureTypeListType 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);
}
Aggregations