Search in sources :

Example 16 with GetRecordsResponseType

use of net.opengis.cat.csw._3.GetRecordsResponseType in project ARLAS-server by gisaia.

the class XmlGetRecordsMessageBodyWriter method writeTo.

@Override
public void writeTo(GetRecordsResponseType getRecordsResponseType, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException {
    ObjectFactory cswFactory = new ObjectFactory();
    JAXB.marshal(cswFactory.createGetRecordsResponse(getRecordsResponseType), outputStream);
}
Also used : ObjectFactory(net.opengis.cat.csw._3.ObjectFactory)

Example 17 with GetRecordsResponseType

use of net.opengis.cat.csw._3.GetRecordsResponseType in project ddf by codice.

the class CswSubscriptionEndpointTest method testUpdateEventInvalidSchema.

@Test(expected = CswException.class)
public void testUpdateEventInvalidSchema() throws Exception {
    GetRecordsResponseType getRecordsResponse = new GetRecordsResponseType();
    SearchResultsType searchResults = new SearchResultsType();
    searchResults.setRecordSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    getRecordsResponse.setSearchResults(searchResults);
    cswSubscriptionEndpoint.updateEvent(getRecordsResponse);
}
Also used : SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) Test(org.junit.Test)

Example 18 with GetRecordsResponseType

use of net.opengis.cat.csw._3.GetRecordsResponseType in project ddf by codice.

the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetFull.

@Ignore
@Test
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.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(org.junit.Ignore) Test(org.junit.Test)

Example 19 with GetRecordsResponseType

use of net.opengis.cat.csw._3.GetRecordsResponseType in project ddf by codice.

the class GetRecordsResponseConverterTest 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JAXBElement(javax.xml.bind.JAXBElement)

Example 20 with GetRecordsResponseType

use of net.opengis.cat.csw._3.GetRecordsResponseType in project ddf by codice.

the class GetRecordsResponseConverterTest method testMarshalRecordCollectionFullXml.

@Ignore
@Test
public void testMarshalRecordCollectionFullXml() throws UnsupportedEncodingException, JAXBException {
    final int totalResults = 5;
    TransformerManager mockMetacardManager = mock(TransformerManager.class);
    when(mockMetacardManager.getTransformerBySchema(anyString())).thenReturn(new CswRecordConverter(CswRecordConverterTest.getCswMetacardType()));
    GetRecordsResponseConverter rrConverter = new GetRecordsResponseConverter(new CswTransformProvider(mockMetacardManager, null));
    XStream xstream = createXstream(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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.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(org.junit.Ignore) Test(org.junit.Test)

Aggregations

GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)19 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)16 JAXBElement (javax.xml.bind.JAXBElement)15 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)15 XStream (com.thoughtworks.xstream.XStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)14 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)14 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)12 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)12 Test (org.junit.Test)11 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)10 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Ignore (jdk.nashorn.internal.ir.annotations.Ignore)6 Ignore (org.junit.Ignore)6 Matchers.anyString (org.mockito.Matchers.anyString)6 ArrayList (java.util.ArrayList)5 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3