Search in sources :

Example 1 with CswRecordCollection

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

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionHits.

@Ignore
public void testMarshalRecordCollectionHits() 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);
    collection.setResultType(ResultType.HITS);
    String xml = xstream.toXML(collection);
    // Verify the context arguments were set correctly
    verify(mockProvider, never()).marshal(any(Object.class), any(HierarchicalStreamWriter.class), any(MarshallingContext.class));
    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(0));
    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 2 with CswRecordCollection

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

the class TestGetRecordsResponseConverter method getRecords.

private void getRecords(final int maxRecords, final int startPosition, final int totalResults, final int expectedNext, final int expectedReturn) throws JAXBException, UnsupportedEncodingException {
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType query = new GetRecordsType();
    query.setMaxRecords(BigInteger.valueOf(maxRecords));
    query.setStartPosition(BigInteger.valueOf(startPosition));
    CswRecordCollection collection = createCswRecordCollection(query, totalResults);
    collection.setStartPosition(startPosition);
    String xml = xstream.toXML(collection);
    JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    GetRecordsResponseType response = jaxb.getValue();
    assertThat(response.getSearchResults().getNumberOfRecordsMatched().intValue(), is(totalResults));
    assertThat(response.getSearchResults().getNumberOfRecordsReturned().intValue(), is(expectedReturn));
    assertThat(response.getSearchResults().getAbstractRecord().size(), is(expectedReturn));
    assertThat(response.getSearchResults().getNextRecord().intValue(), is(expectedNext));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XStream(com.thoughtworks.xstream.XStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement)

Example 3 with CswRecordCollection

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

the class TestGetRecordsResponseConverter method testUnmarshalGetRecordsResponseConversionWithEmptyBoundingBox.

@Test
public void testUnmarshalGetRecordsResponseConversionWithEmptyBoundingBox() {
    XStream xstream = new XStream(new WstxDriver());
    xstream.setClassLoader(this.getClass().getClassLoader());
    GetRecordsResponseConverter grrc = new GetRecordsResponseConverter(mockProvider);
    xstream.registerConverter(grrc);
    xstream.alias("GetRecordsResponse", CswRecordCollection.class);
    String xml = "<csw:GetRecordsResponse xmlns:csw=\"http://www.opengis.net/cat/csw\">\r\n" + "  <csw:SearchStatus status=\"subset\" timestamp=\"2013-05-01T02:13:36+0200\"/>\r\n" + "  <csw:SearchResults elementSet=\"full\" nextRecord=\"11\" numberOfRecordsMatched=\"479\" numberOfRecordsReturned=\"10\" recordSchema=\"csw:Record\">\r\n" + "    <csw:Record xmlns:csw=\"http://www.opengis.net/cat/csw\">\r\n" + "      <dc:identifier xmlns:dc=\"http://purl.org/dc/elements/1.1/\">{8C1F6297-EC96-4302-A01E-14988C9149FD}</dc:identifier>\r\n" + "      <dc:title xmlns:dc=\"http://purl.org/dc/elements/1.1/\">title 1</dc:title>\r\n" + "      <dct:modified xmlns:dct=\"http://purl.org/dc/terms/\">2008-12-15</dct:modified>\r\n" + "      <dc:subject xmlns:dc=\"http://purl.org/dc/elements/1.1/\">subject 1</dc:subject>\r\n" + "      <dc:subject xmlns:dc=\"http://purl.org/dc/elements/1.1/\">second subject</dc:subject>\r\n" + "      <dct:abstract xmlns:dct=\"http://purl.org/dc/terms/\">abstract 1</dct:abstract>\r\n" + "      <dc:rights xmlns:dc=\"http://purl.org/dc/elements/1.1/\">copyright 1</dc:rights>\r\n" + "      <dc:rights xmlns:dc=\"http://purl.org/dc/elements/1.1/\">copyright 2</dc:rights>\r\n" + "      <dc:language xmlns:dc=\"http://purl.org/dc/elements/1.1/\">english</dc:language>      \r\n" + "      <ows:BoundingBox xmlns:ows=\"http://www.opengis.net/ows\" crs=\"EPSG:RD_New (28992)\">\r\n" + "        <ows:LowerCorner></ows:LowerCorner>\r\n" + "        <ows:UpperCorner></ows:UpperCorner>\r\n" + "      </ows:BoundingBox>   \r\n" + "      <dc:type xmlns:dc=\"http://purl.org/dc/elements/1.1/\">dataset</dc:type>\r\n" + "      <dc:format xmlns:dc=\"http://purl.org/dc/elements/1.1/\">Shapefile</dc:format> \r\n" + "    </csw:Record>\r\n" + "  </csw:SearchResults>\r\n" + "</csw:GetRecordsResponse>";
    InputStream inStream = IOUtils.toInputStream(xml);
    CswRecordCollection cswRecords = (CswRecordCollection) xstream.fromXML(inStream);
    IOUtils.closeQuietly(inStream);
    assertThat(cswRecords.getNumberOfRecordsReturned(), is(10L));
    assertThat(cswRecords.getNumberOfRecordsMatched(), is(479L));
    List<Metacard> metacards = cswRecords.getCswRecords();
    assertThat(metacards, not(nullValue()));
    assertThat(metacards.size(), is(1));
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) XStream(com.thoughtworks.xstream.XStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with CswRecordCollection

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

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionFullXml.

@Ignore
public void testMarshalRecordCollectionFullXml() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    TransformerManager mockMetacardManager = mock(TransformerManager.class);
    when(mockMetacardManager.getTransformerBySchema(anyString())).thenReturn(new CswRecordConverter(TestCswRecordConverter.getCswMetacardType()));
    GetRecordsResponseConverter rrConverter = new GetRecordsResponseConverter(new CswTransformProvider(mockMetacardManager, null));
    XStream xstream = new XStream(new StaxDriver(new NoNameCoder()));
    xstream.registerConverter(rrConverter);
    xstream.alias(CswConstants.CSW_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.GET_RECORDS_RESPONSE, CswRecordCollection.class);
    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);
    String xml = xstream.toXML(collection);
    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 : TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) 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) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder) StaxDriver(com.thoughtworks.xstream.io.xml.StaxDriver) 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) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Example 5 with CswRecordCollection

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

the class TestGetRecordsResponseConverter method testMarshalRecordCollectionGetElements.

@Ignore
public void testMarshalRecordCollectionGetElements() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
    GetRecordsType getRecords = new GetRecordsType();
    QueryType query = new QueryType();
    List<QName> elements = new LinkedList<>();
    elements.add(CswConstants.CSW_TITLE_QNAME);
    elements.add(CswConstants.CSW_SOURCE_QNAME);
    query.setElementName(elements);
    ObjectFactory objectFactory = new ObjectFactory();
    getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
    CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
    collection.setElementName(elements);
    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(nullValue()));
    assertThat(context.get(CswConstants.ELEMENT_NAMES), is(notNullValue()));
    List<QName> qnames = (List<QName>) context.get(CswConstants.ELEMENT_NAMES);
    assertThat(qnames.contains(CswConstants.CSW_TITLE_QNAME), is(true));
    assertThat(qnames.contains(CswConstants.CSW_SOURCE_QNAME), is(true));
    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(nullValue()));
    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) QName(javax.xml.namespace.QName) 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) LinkedList(java.util.LinkedList) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) MarshallingContext(com.thoughtworks.xstream.converters.MarshallingContext) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Ignore(jdk.nashorn.internal.ir.annotations.Ignore)

Aggregations

CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)84 Test (org.junit.Test)56 ByteArrayInputStream (java.io.ByteArrayInputStream)37 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)29 JAXBElement (javax.xml.bind.JAXBElement)25 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)21 XStream (com.thoughtworks.xstream.XStream)20 Metacard (ddf.catalog.data.Metacard)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)20 Matchers.anyString (org.mockito.Matchers.anyString)20 ArrayList (java.util.ArrayList)18 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)15 QName (javax.xml.namespace.QName)15 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)15 Resource (ddf.catalog.resource.Resource)14 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)14 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)13 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)13 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)12 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)12