Search in sources :

Example 6 with GetRecordsResponseType

use of org.geotoolkit.csw.xml.v202.GetRecordsResponseType 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 7 with GetRecordsResponseType

use of org.geotoolkit.csw.xml.v202.GetRecordsResponseType in project ddf by codice.

the class CswSubscriptionEndpointTest method testCreateEventInvalidSchema.

@Test(expected = CswException.class)
public void testCreateEventInvalidSchema() throws Exception {
    GetRecordsResponseType getRecordsResponse = new GetRecordsResponseType();
    SearchResultsType searchResults = new SearchResultsType();
    searchResults.setRecordSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    getRecordsResponse.setSearchResults(searchResults);
    cswSubscriptionEndpoint.createEvent(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 8 with GetRecordsResponseType

use of org.geotoolkit.csw.xml.v202.GetRecordsResponseType in project ddf by codice.

the class CswSubscriptionEndpointTest method testDeleteEventInvalidSchema.

@Test(expected = CswException.class)
public void testDeleteEventInvalidSchema() throws Exception {
    GetRecordsResponseType getRecordsResponse = new GetRecordsResponseType();
    SearchResultsType searchResults = new SearchResultsType();
    searchResults.setRecordSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    getRecordsResponse.setSearchResults(searchResults);
    cswSubscriptionEndpoint.deleteEvent(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 9 with GetRecordsResponseType

use of org.geotoolkit.csw.xml.v202.GetRecordsResponseType in project ddf by codice.

the class CswSubscriptionEndpointTest method getRecordsResponse.

private GetRecordsResponseType getRecordsResponse(int metacardCount) throws IOException, CatalogTransformerException {
    InputTransformer inputTransformer = mock(InputTransformer.class);
    when(mockInputManager.getTransformerBySchema(METACARD_SCHEMA)).thenReturn(inputTransformer);
    Metacard metacard = mock(Metacard.class);
    when(inputTransformer.transform(any(InputStream.class))).thenReturn(metacard);
    GetRecordsResponseType getRecordsResponse = new GetRecordsResponseType();
    SearchResultsType searchResults = new SearchResultsType();
    searchResults.setRecordSchema(METACARD_SCHEMA);
    getRecordsResponse.setSearchResults(searchResults);
    List<Object> any = new ArrayList<>();
    Node node = mock(Node.class);
    for (int i = 0; i < metacardCount; i++) {
        any.add(node);
    }
    searchResults.setAny(any);
    return getRecordsResponse;
}
Also used : Metacard(ddf.catalog.data.Metacard) InputStream(java.io.InputStream) SearchResultsType(net.opengis.cat.csw.v_2_0_2.SearchResultsType) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) InputTransformer(ddf.catalog.transform.InputTransformer)

Example 10 with GetRecordsResponseType

use of org.geotoolkit.csw.xml.v202.GetRecordsResponseType 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)

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