Search in sources :

Example 21 with CswRecordCollection

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));
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) Resource(ddf.catalog.resource.Resource) Matchers.anyString(org.mockito.Matchers.anyString) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) URI(java.net.URI) ResourceResponse(ddf.catalog.operation.ResourceResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 22 with CswRecordCollection

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;
}
Also used : SummaryRecordType(net.opengis.cat.csw.v_2_0_2.SummaryRecordType) InputStream(java.io.InputStream) BriefRecordType(net.opengis.cat.csw.v_2_0_2.BriefRecordType) LinkedList(java.util.LinkedList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) AbstractRecordType(net.opengis.cat.csw.v_2_0_2.AbstractRecordType) RecordType(net.opengis.cat.csw.v_2_0_2.RecordType) SummaryRecordType(net.opengis.cat.csw.v_2_0_2.SummaryRecordType) BriefRecordType(net.opengis.cat.csw.v_2_0_2.BriefRecordType) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) SimpleLiteral(net.opengis.cat.csw.v_2_0_2.dc.elements.SimpleLiteral)

Example 23 with CswRecordCollection

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);
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) Resource(ddf.catalog.resource.Resource) Matchers.anyString(org.mockito.Matchers.anyString) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) URI(java.net.URI) ResourceResponse(ddf.catalog.operation.ResourceResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 24 with CswRecordCollection

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));
}
Also used : CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordByIdType(net.opengis.cat.csw.v_2_0_2.GetRecordByIdType) Test(org.junit.Test)

Example 25 with CswRecordCollection

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ResultImpl(ddf.catalog.data.impl.ResultImpl) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Aggregations

CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)51 Test (org.junit.Test)26 ByteArrayInputStream (java.io.ByteArrayInputStream)21 Matchers.anyString (org.mockito.Matchers.anyString)18 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 JAXBElement (javax.xml.bind.JAXBElement)12 Metacard (ddf.catalog.data.Metacard)11 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)11 XStream (com.thoughtworks.xstream.XStream)10 ArrayList (java.util.ArrayList)10 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)9 QName (javax.xml.namespace.QName)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 Resource (ddf.catalog.resource.Resource)8 Result (ddf.catalog.data.Result)7 Ignore (jdk.nashorn.internal.ir.annotations.Ignore)7 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)7 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)7 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)7 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)7