use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class CswSourceTest method testRefreshWithNullConfiguration.
@Test
public void testRefreshWithNullConfiguration() throws SecurityServiceException {
AbstractCswSource cswSource = getCswSource(null, null, "type", null, null, encryptionService, permissions);
CswSourceConfiguration defaultCswSourceConfiguration = getStandardCswSourceConfiguration(null, null, null, encryptionService, permissions);
// Assert that the default configuration is set
assertDefaultCswSourceConfiguration(cswSource.cswSourceConfiguration, defaultCswSourceConfiguration);
cswSource.refresh(null);
// Assert that the configuration does not change with a null map
assertDefaultCswSourceConfiguration(cswSource.cswSourceConfiguration, defaultCswSourceConfiguration);
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class CswSourceTest method testRefreshWithUnregisterForEvents.
@Test
public void testRefreshWithUnregisterForEvents() throws Exception {
String subscriptionId = "subscriptionid";
String eventEndpoint = "https://ddf/services/csw/subscriptions";
CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
cswSource.filterlessSubscriptionId = subscriptionId;
CswSubscribe client = mock(CswSubscribe.class);
Response response = mock(Response.class);
AcknowledgementType ack = mock(AcknowledgementType.class);
when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
when(response.getStatus()).thenReturn(200);
when(response.readEntity(any(Class.class))).thenReturn(ack);
when(ack.getRequestId()).thenReturn(subscriptionId);
when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
when(cswSource.getSubscriberClientFactory().getClientForSystemSubject(cswSource.getSubject())).thenReturn(client);
cswSource.cswSourceConfiguration.setRegisterForEvents(true);
cswSource.cswSourceConfiguration.setEventServiceAddress(eventEndpoint);
// Set Configuration Map
Map<String, Object> configuration = getConfigurationMap(cswSource);
configuration.put(cswSource.REGISTER_FOR_EVENTS, false);
configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
// Call Refresh
cswSource.refresh(configuration);
// Get Configuration
CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
// Assert Refresh Changes
Assert.assertFalse(cswSourceConfiguration.isRegisterForEvents());
Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
verify(client).deleteRecordsSubscription(subscriptionId);
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class CswSourceTest method getCswSource.
private AbstractCswSource getCswSource(Csw csw, BundleContext context, String contentMapping, String queryTypeQName, String queryTypePrefix, EncryptionService encryptionService, Permissions permissions) {
CswSourceConfiguration cswSourceConfiguration = getStandardCswSourceConfiguration(contentMapping, queryTypeQName, queryTypePrefix, encryptionService, permissions);
cswSourceConfiguration.putMetacardCswMapping(Metacard.CONTENT_TYPE, contentMapping);
SecureCxfClientFactory<Csw> mockFactory = mock(SecureCxfClientFactory.class);
doReturn(csw).when(mockFactory).getClient();
doReturn(csw).when(mockFactory).getClientForSubject(any(Subject.class));
doReturn(csw).when(mockFactory).getClientForSystemSubject(any(Subject.class));
ClientBuilderFactory clientBuilderFactory = mock(ClientBuilderFactory.class);
ClientBuilder<Csw> clientBuilder = new ClientBuilderImpl<Csw>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {
@Override
public SecureCxfClientFactory<Csw> build() {
return mockFactory;
}
};
when(clientBuilderFactory.<Csw>getClientBuilder()).thenReturn(clientBuilder);
CswSourceStub cswSource = new CswSourceStub(mockContext, cswSourceConfiguration, mockProvider, clientBuilderFactory, encryptionService, new Security(), permissions);
cswSource.setFilterAdapter(new GeotoolsFilterAdapterImpl());
cswSource.setFilterBuilder(builder);
cswSource.setContext(context);
cswSource.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
cswSource.setAvailabilityTask(mockAvailabilityTask);
cswSource.configureCswSource();
return cswSource;
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class CswSourceTest method testRefreshWithUpdateRegisterForEvents.
@Test
public void testRefreshWithUpdateRegisterForEvents() throws Exception {
String subscriptionId = "subscriptionid";
String eventEndpoint = "https://ddf/services/csw/subscriptions";
CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
cswSource.filterlessSubscriptionId = subscriptionId;
CswSubscribe client = mock(CswSubscribe.class);
Response response = mock(Response.class);
AcknowledgementType ack = mock(AcknowledgementType.class);
when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
when(response.getStatus()).thenReturn(200);
when(response.readEntity(any(Class.class))).thenReturn(ack);
when(ack.getRequestId()).thenReturn(subscriptionId);
when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
when(cswSource.getSubscriberClientFactory().getClientForSystemSubject(cswSource.getSubject())).thenReturn(client);
cswSource.cswSourceConfiguration.setRegisterForEvents(true);
cswSource.cswSourceConfiguration.setEventServiceAddress(eventEndpoint + "/original");
// Set Configuration Map
Map<String, Object> configuration = getConfigurationMap(cswSource);
configuration.put(cswSource.REGISTER_FOR_EVENTS, true);
configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
// Call Refresh
cswSource.refresh(configuration);
// Get Configuration
CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
// Assert Refresh Changes
Assert.assertTrue(cswSourceConfiguration.isRegisterForEvents());
Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
verify(client).deleteRecordsSubscription(subscriptionId);
verify(ack).getRequestId();
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class GetRecordsMessageBodyReaderTest method testPartialContentResponseHandling.
@Test
public void testPartialContentResponseHandling() throws Exception {
CswSourceConfiguration config = new CswSourceConfiguration(encryptionService, permissions);
config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
String sampleData = "SampleData";
byte[] data = sampleData.getBytes();
CswRecordCollection cswRecords = null;
try (ByteArrayInputStream dataInputStream = new ByteArrayInputStream(data)) {
MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
httpHeaders.add(CswConstants.PRODUCT_RETRIEVAL_HTTP_HEADER, "TRUE");
httpHeaders.add(HttpHeaders.CONTENT_DISPOSITION, String.format("inline; filename=ResourceName"));
httpHeaders.add(HttpHeaders.CONTENT_RANGE, String.format("bytes 1-%d/%d", sampleData.length() - 1, sampleData.length()));
MediaType mediaType = new MediaType("text", "plain");
cswRecords = reader.readFrom(CswRecordCollection.class, null, null, mediaType, httpHeaders, dataInputStream);
}
Resource resource = cswRecords.getResource();
// assert that the CswRecordCollection properly extracted the bytes skipped from the Partial
// Content response
assertThat(cswRecords.getResourceProperties().get(GetRecordsMessageBodyReader.BYTES_SKIPPED), is(1L));
// assert that the input stream has not been skipped at this stage. Since AbstractCswSource has
// the number
// of bytes that was attempted to be skipped, the stream must be aligned there instead.
assertThat(resource.getByteArray(), is(data));
}
Aggregations