Search in sources :

Example 6 with CswRecordCollection

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.

the class TestGetRecordsResponseConverter method createCswRecordCollection.

private CswRecordCollection createCswRecordCollection(GetRecordsType request, int resultCount) {
    CswRecordCollection collection = new CswRecordCollection();
    int first = 1;
    int last = 2;
    if (request != null) {
        first = request.getStartPosition().intValue();
        int next = request.getMaxRecords().intValue() + first;
        last = next - 1;
        if (last >= resultCount) {
            last = resultCount;
        }
    }
    int returned = last - first + 1;
    collection.setCswRecords(createMetacardList(first, last));
    collection.setNumberOfRecordsMatched(resultCount);
    collection.setNumberOfRecordsReturned(returned);
    return collection;
}
Also used : CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)

Example 7 with CswRecordCollection

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionGetBrief.

@Ignore
public void testMarshalRecordCollectionGetBrief() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    ElementSetNameType set = new ElementSetNameType();
    set.setValue(ElementSetType.BRIEF);
    query.setElementSetName(set);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementSetType(ElementSetType.BRIEF);
    ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
    String xml = xstream.toXML(collection);
    // Verify the context arguments were set correctly
    verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
    MarshallingContext context = captor.getValue();
    assertThat(context, not(nullValue()));
    assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.BRIEF));
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
    SearchResultsType resultsType = response.getSearchResults();
    assertThat(resultsType, not(nullValue()));
    assertThat(resultsType.getElementSet(), is(ElementSetType.BRIEF));
    assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
    assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Also used : HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Example 8 with CswRecordCollection

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionGetFull.

@Ignore
public void testMarshalRecordCollectionGetFull() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    ElementSetNameType set = new ElementSetNameType();
    set.setValue(ElementSetType.FULL);
    query.setElementSetName(set);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementSetType(ElementSetType.FULL);
    ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
    String xml = xstream.toXML(collection);
    // Verify the context arguments were set correctly
    verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
    MarshallingContext context = captor.getValue();
    assertThat(context, not(nullValue()));
    assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.FULL));
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    // Assert the GetRecordsResponse elements and attributes
    assertThat(response, not(nullValue()));
    SearchResultsType resultsType = response.getSearchResults();
    assertThat(resultsType, not(nullValue()));
    assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
    assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
    assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Also used : HierarchicalStreamWriter(com.thoughtworks.xstream.io.HierarchicalStreamWriter) XStream(com.thoughtworks.xstream.XStream) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Example 9 with CswRecordCollection

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.

the class CswRecordCollectionMessageBodyWriterTest method createCswRecordCollection.

private CswRecordCollection createCswRecordCollection(int resultCount) {
    CswRecordCollection collection = new CswRecordCollection();
    collection.setCswRecords(createMetacardList(resultCount));
    return collection;
}
Also used : CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)

Example 10 with CswRecordCollection

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.

the class CswRecordCollectionMessageBodyWriterTest method testWriteValidate.

@Test
public void testWriteValidate() throws WebApplicationException, IOException, JAXBException, CatalogTransformerException {
    CswRecordCollectionMessageBodyWriter writer = new CswRecordCollectionMessageBodyWriter(mockManager);
    when(mockManager.getTransformerBySchema(anyString())).thenReturn(mockTransformer);
    ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
    when(mockTransformer.transform(any(SourceResponse.class), any(Map.class))).thenReturn(mockContent);
    when(mockContent.getInputStream()).thenReturn(new ByteArrayInputStream("bytes".getBytes()));
    CswRecordCollection collection = createCswRecordCollection(6);
    collection.setNumberOfRecordsMatched(22);
    collection.setNumberOfRecordsReturned(6);
    collection.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    collection.setById(true);
    QName example = new QName("example");
    collection.setElementName(Arrays.asList(example));
    collection.setElementSetType(ElementSetType.BRIEF);
    collection.setResultType(ResultType.VALIDATE);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    writer.writeTo(collection, null, null, null, null, null, stream);
    verify(mockManager, times(1)).getTransformerBySchema(anyString());
    verify(mockTransformer).transform(any(SourceResponse.class), captor.capture());
    Map arguments = captor.getValue();
    assertThat(arguments.get(CswConstants.WRITE_NAMESPACES), is(false));
    assertThat(arguments.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat(arguments.get(CswConstants.RESULT_TYPE_PARAMETER), is(ResultType.VALIDATE));
    assertThat(arguments.get(CswConstants.IS_BY_ID_QUERY), is(true));
    assertThat(arguments.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.BRIEF));
    assertThat(((QName[]) arguments.get(CswConstants.ELEMENT_NAMES))[0], is(example));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Map(java.util.Map) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) 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