use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class TestCswSource 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);
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 TestCswSourceBase method generateCswCollection.
protected CswRecordCollection generateCswCollection(String file) {
InputStream stream = getClass().getResourceAsStream(file);
GetRecordsResponseType recordsResponse = parseXml(stream);
GetRecordsResponseType records = new GetRecordsResponseType();
recordsResponse.copyTo(records);
List<Metacard> cswRecords = new LinkedList<>();
for (JAXBElement<? extends AbstractRecordType> rec : records.getSearchResults().getAbstractRecord()) {
MetacardImpl metacard = new MetacardImpl();
cswRecords.add(metacard);
if (rec.getValue() instanceof BriefRecordType) {
BriefRecordType record = (BriefRecordType) rec.getValue();
metacard.setId(record.getIdentifier().get(0).getValue().getContent().get(0));
if (!CollectionUtils.isEmpty(record.getType().getContent())) {
metacard.setContentTypeName(record.getType().getContent().get(0));
}
} else if (rec.getValue() instanceof SummaryRecordType) {
SummaryRecordType record = (SummaryRecordType) rec.getValue();
metacard.setId(record.getIdentifier().get(0).getValue().getContent().get(0));
if (!CollectionUtils.isEmpty(record.getType().getContent())) {
metacard.setContentTypeName(record.getType().getContent().get(0));
}
} else if (rec.getValue() instanceof RecordType) {
RecordType record = (RecordType) rec.getValue();
for (JAXBElement<SimpleLiteral> jb : record.getDCElement()) {
if ("identifier".equals(jb.getName().getLocalPart())) {
metacard.setId(jb.getValue().getContent().get(0));
}
if ("type".equals(jb.getName().getLocalPart()) && !CollectionUtils.isEmpty(jb.getValue().getContent())) {
metacard.setContentTypeName(jb.getValue().getContent().get(0));
}
}
}
}
CswRecordCollection collection = new CswRecordCollection();
collection.setCswRecords(cswRecords);
collection.setNumberOfRecordsMatched(records.getSearchResults().getNumberOfRecordsMatched().intValue());
collection.setNumberOfRecordsReturned(records.getSearchResults().getNumberOfRecordsReturned().intValue());
return collection;
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class TestCswSource method testRetrieveResourceUsingGetRecordByIdWithNoId.
@Test(expected = ResourceNotFoundException.class)
public void testRetrieveResourceUsingGetRecordByIdWithNoId() 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);
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<>();
cswSource.retrieveResource(new URI("http://example.com/resource"), props);
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class TestCswEndpoint method testPostRetrieveProductGetRecordByIdWithNoMimeType.
@Test
public void testPostRetrieveProductGetRecordByIdWithNoMimeType() 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(false);
CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdType, null);
assertThat(cswRecordCollection.getResource(), is(notNullValue()));
assertThat(cswRecordCollection.getResource().getMimeType().toString(), is(MediaType.APPLICATION_OCTET_STREAM));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class TestCswEndpoint method testGetRecordById.
@Test
public void testGetRecordById() throws CswException, FederationException, SourceUnavailableException, UnsupportedQueryException {
final GetRecordByIdRequest getRecordByIdRequest = new GetRecordByIdRequest();
getRecordByIdRequest.setId("123");
getRecordByIdRequest.setOutputFormat(MediaType.APPLICATION_XML);
getRecordByIdRequest.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
getRecordByIdRequest.setElementSetName("full");
final Metacard metacard = new MetacardImpl();
final List<Result> mockResults = Collections.singletonList(new ResultImpl(metacard));
final QueryResponseImpl queryResponse = new QueryResponseImpl(null, mockResults, mockResults.size());
doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
final CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdRequest, null);
verifyCswRecordCollection(cswRecordCollection, metacard);
assertThat(cswRecordCollection.getElementSetType(), is(ElementSetType.FULL));
}
Aggregations