Search in sources :

Example 1 with GetRecordsResponseConverter

use of org.codice.ddf.spatial.ogc.csw.catalog.converter.GetRecordsResponseConverter in project ddf by codice.

the class GetRecordsMessageBodyReaderTest method testFullThreadCswRecordCollection.

@Test
public void testFullThreadCswRecordCollection() throws Exception {
    Metacard metacard = createMetacard();
    List<Metacard> inputMetacards = Collections.singletonList(metacard);
    CswRecordCollection collection = new CswRecordCollection();
    collection.setCswRecords(inputMetacards);
    MetacardType cswMetacardType = new MetacardTypeImpl(CswConstants.CSW_METACARD_TYPE_NAME, Arrays.asList(new ContactAttributes(), new LocationAttributes(), new MediaAttributes(), new TopicAttributes(), new AssociationsAttributes()));
    CswRecordConverter recordConverter = new CswRecordConverter(cswMetacardType);
    TransformerManager mockInputManager = mock(TransformerManager.class);
    when(mockInputManager.getTransformerByProperty(anyString(), anyString())).thenReturn(recordConverter);
    CswTransformProvider metacardProvider = new CswTransformProvider(null, mockInputManager);
    GetRecordsResponseConverter provider = new GetRecordsResponseConverter(metacardProvider);
    CswSourceConfiguration config = createConfig();
    GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(provider, config);
    CswRecordCollection cswRecords = null;
    try (InputStream is = GetRecordsMessageBodyReaderTest.class.getResourceAsStream("/getRecordsResponse.xml")) {
        MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
        cswRecords = reader.readFrom(CswRecordCollection.class, null, null, null, httpHeaders, is);
    }
    List<Metacard> metacards = cswRecords.getCswRecords();
    assertThat(metacards, hasSize(3));
    assertThat(metacards.get(0).getMetacardType().getName(), is("csw:Record"));
    assertThat(metacards.get(0).getTitle(), containsString("title"));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) ContactAttributes(ddf.catalog.data.impl.types.ContactAttributes) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) LocationAttributes(ddf.catalog.data.impl.types.LocationAttributes) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MediaAttributes(ddf.catalog.data.impl.types.MediaAttributes) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) CswTransformProvider(org.codice.ddf.spatial.ogc.csw.catalog.converter.CswTransformProvider) MetacardType(ddf.catalog.data.MetacardType) TopicAttributes(ddf.catalog.data.impl.types.TopicAttributes) CswRecordConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) GetRecordsResponseConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.GetRecordsResponseConverter) Metacard(ddf.catalog.data.Metacard) AssociationsAttributes(ddf.catalog.data.impl.types.AssociationsAttributes) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Test(org.junit.Test)

Example 2 with GetRecordsResponseConverter

use of org.codice.ddf.spatial.ogc.csw.catalog.converter.GetRecordsResponseConverter in project ddf by codice.

the class GetRecordsMessageBodyReaderTest method testFullThreadCswRecordCollectionAltPrefixes.

@Test
public void testFullThreadCswRecordCollectionAltPrefixes() throws Exception {
    Metacard metacard = createMetacard();
    List<Metacard> inputMetacards = Collections.singletonList(metacard);
    CswRecordCollection collection = new CswRecordCollection();
    collection.setCswRecords(inputMetacards);
    MetacardType cswMetacardType = new MetacardTypeImpl(CswConstants.CSW_METACARD_TYPE_NAME, Arrays.asList(new ContactAttributes(), new LocationAttributes(), new MediaAttributes(), new TopicAttributes(), new AssociationsAttributes()));
    CswRecordConverter recordConverter = new CswRecordConverter(cswMetacardType);
    TransformerManager mockInputManager = mock(TransformerManager.class);
    when(mockInputManager.getTransformerByProperty(anyString(), anyString())).thenReturn(recordConverter);
    CswTransformProvider metacardProvider = new CswTransformProvider(null, mockInputManager);
    GetRecordsResponseConverter provider = new GetRecordsResponseConverter(metacardProvider);
    CswSourceConfiguration config = createConfig();
    GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(provider, config);
    CswRecordCollection cswRecords = null;
    try (InputStream is = GetRecordsMessageBodyReaderTest.class.getResourceAsStream("/getRecordsResponse-alt-prefixes.xml")) {
        MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
        cswRecords = reader.readFrom(CswRecordCollection.class, null, null, null, httpHeaders, is);
    }
    List<Metacard> metacards = cswRecords.getCswRecords();
    assertThat(metacards.size(), is(3));
    assertThat(metacards.get(0).getMetacardType().getName(), is("csw:Record"));
    assertThat(metacards.get(0).getTitle(), containsString("title"));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) ContactAttributes(ddf.catalog.data.impl.types.ContactAttributes) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) LocationAttributes(ddf.catalog.data.impl.types.LocationAttributes) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MediaAttributes(ddf.catalog.data.impl.types.MediaAttributes) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) CswTransformProvider(org.codice.ddf.spatial.ogc.csw.catalog.converter.CswTransformProvider) MetacardType(ddf.catalog.data.MetacardType) TopicAttributes(ddf.catalog.data.impl.types.TopicAttributes) CswRecordConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) GetRecordsResponseConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.GetRecordsResponseConverter) Metacard(ddf.catalog.data.Metacard) AssociationsAttributes(ddf.catalog.data.impl.types.AssociationsAttributes) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Test(org.junit.Test)

Aggregations

Metacard (ddf.catalog.data.Metacard)2 MetacardType (ddf.catalog.data.MetacardType)2 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)2 AssociationsAttributes (ddf.catalog.data.impl.types.AssociationsAttributes)2 ContactAttributes (ddf.catalog.data.impl.types.ContactAttributes)2 LocationAttributes (ddf.catalog.data.impl.types.LocationAttributes)2 MediaAttributes (ddf.catalog.data.impl.types.MediaAttributes)2 TopicAttributes (ddf.catalog.data.impl.types.TopicAttributes)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)2 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)2 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)2 TransformerManager (org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager)2 CswRecordConverter (org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter)2 CswTransformProvider (org.codice.ddf.spatial.ogc.csw.catalog.converter.CswTransformProvider)2 GetRecordsResponseConverter (org.codice.ddf.spatial.ogc.csw.catalog.converter.GetRecordsResponseConverter)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2