use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class TestGetRecordsMessageBodyReader method testPartialContentResponseHandling.
@Test
public void testPartialContentResponseHandling() throws Exception {
CswSourceConfiguration config = new CswSourceConfiguration(encryptionService);
config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
String sampleData = "SampleData";
byte[] data = sampleData.getBytes();
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");
CswRecordCollection 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));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class TestGetRecordsMessageBodyReader method testGetMultipleMetacardsWithForeignText.
// verifies UTF-8 encoding configured properly when XML includes foreign text with special characters
@Test
public void testGetMultipleMetacardsWithForeignText() throws Exception {
List<Metacard> inputMetacards = new ArrayList<>();
MetacardImpl metacard = new MetacardImpl(BasicTypes.BASIC_METACARD);
inputMetacards.add(metacard);
CswRecordCollection collection = new CswRecordCollection();
collection.setCswRecords(inputMetacards);
when(mockProvider.unmarshal(any(), any())).thenReturn(collection);
CswSourceConfiguration config = new CswSourceConfiguration(encryptionService);
config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
InputStream is = TestGetRecordsMessageBodyReader.class.getResourceAsStream("/geomaticsGetRecordsResponse.xml");
MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
CswRecordCollection cswRecords = reader.readFrom(CswRecordCollection.class, null, null, null, httpHeaders, is);
List<Metacard> metacards = cswRecords.getCswRecords();
assertThat(metacards, contains(metacard));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class TestCswSource 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);
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 TestCswSource method testRefreshWithEmptyConfiguration.
@Test
public void testRefreshWithEmptyConfiguration() throws SecurityServiceException {
AbstractCswSource cswSource = getCswSource(null, null, "type", null, null, encryptionService);
CswSourceConfiguration defaultCswSourceConfiguration = getStandardCswSourceConfiguration(null, null, null, encryptionService);
Map<String, Object> configuration = new HashMap<>();
// Assert that the default configuration is set
assertDefaultCswSourceConfiguration(cswSource.cswSourceConfiguration, defaultCswSourceConfiguration);
cswSource.refresh(configuration);
// Assert that the configuration does not change with an empty map
assertDefaultCswSourceConfiguration(cswSource.cswSourceConfiguration, defaultCswSourceConfiguration);
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.
the class TestCswSource method testRefreshWithNullConfiguration.
@Test
public void testRefreshWithNullConfiguration() throws SecurityServiceException {
AbstractCswSource cswSource = getCswSource(null, null, "type", null, null, encryptionService);
CswSourceConfiguration defaultCswSourceConfiguration = getStandardCswSourceConfiguration(null, null, null, encryptionService);
// 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);
}
Aggregations