use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class CswEndpointTest method testPostGetRecordsHits.
@Test
public void testPostGetRecordsHits() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
GetRecordsType grr = createDefaultPostRecordsRequest();
grr.setResultType(ResultType.HITS);
QueryType query = new QueryType();
List<QName> typeNames = new ArrayList<>();
typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
query.setTypeNames(typeNames);
QueryConstraintType constraint = new QueryConstraintType();
constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY);
query.setConstraint(constraint);
JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
grr.setAbstractQuery(jaxbQuery);
CswRecordCollection collection = csw.getRecords(grr);
assertThat(collection.getCswRecords(), is(empty()));
assertThat(collection.getResultType(), is(ResultType.HITS));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class CswEndpointTest method testPostRetrieveProductGetRecordByIdWithRange.
@Test
public void testPostRetrieveProductGetRecordByIdWithRange() throws IOException, ResourceNotFoundException, ResourceNotSupportedException, CswException {
final GetRecordByIdType getRecordByIdType = new GetRecordByIdType();
getRecordByIdType.setOutputFormat(MediaType.APPLICATION_OCTET_STREAM);
getRecordByIdType.setOutputSchema(OCTET_STREAM_OUTPUT_SCHEMA);
getRecordByIdType.setId(Collections.singletonList("123"));
setUpMocksForProductRetrieval(true);
CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdType, RANGE_VALUE);
assertThat(cswRecordCollection.getResource(), is(notNullValue()));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class CswSourceTest method testRetrieveResourceUsingGetRecordById.
@Test
public void testRetrieveResourceUsingGetRecordById() throws CswException, ResourceNotFoundException, IOException, ResourceNotSupportedException, URISyntaxException {
Csw csw = createMockCsw();
CswRecordCollection collection = mock(CswRecordCollection.class);
Resource resource = mock(Resource.class);
when(collection.getResource()).thenReturn(resource);
when(csw.getRecordById(any(GetRecordByIdRequest.class), anyString())).thenReturn(collection);
AbstractCswSource cswSource = getCswSource(csw, mockContext, null, null, null, null, permissions);
ResourceReader reader = mock(ResourceReader.class);
when(reader.retrieveResource(any(URI.class), any(Map.class))).thenReturn(mock(ResourceResponse.class));
cswSource.setResourceReader(reader);
Map<String, Serializable> props = new HashMap<>();
props.put(Core.ID, "ID");
cswSource.retrieveResource(new URI("http://example.com/resource"), props);
// Verify
verify(csw, times(1)).getRecordById(any(GetRecordByIdRequest.class), any(String.class));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection 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));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class GetRecordsMessageBodyReaderTest method testReadProductData.
@Test
public void testReadProductData() 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"));
MediaType mediaType = new MediaType("text", "plain");
cswRecords = reader.readFrom(CswRecordCollection.class, null, null, mediaType, httpHeaders, dataInputStream);
}
Resource resource = cswRecords.getResource();
assertThat(resource, notNullValue());
assertThat(resource.getName(), is("ResourceName"));
assertThat(resource.getMimeType().toString(), is(MediaType.TEXT_PLAIN));
assertThat(resource.getByteArray(), is(data));
}
Aggregations