Search in sources :

Example 1 with MediaAttributes

use of ddf.catalog.data.impl.types.MediaAttributes in project ddf by codice.

the class OverrideAttributesSupportTest method testOverrideMetacardDescriptors.

@Test
public void testOverrideMetacardDescriptors() throws URISyntaxException {
    MetacardImpl metacard = new MetacardImpl();
    metacard.setMetadata("original");
    metacard.setTitle("original");
    metacard.setId("original");
    metacard.setResourceURI(new URI("content:stuff"));
    MetacardImpl overrideMetacard = new MetacardImpl(new MetacardTypeImpl("other", metacard.getMetacardType(), new MediaAttributes().getAttributeDescriptors()));
    overrideMetacard.setTitle("updated");
    overrideMetacard.setId("updated");
    overrideMetacard.setMetadata("updated");
    overrideMetacard.setResourceURI(new URI("content:newstuff"));
    overrideMetacard.setAttribute(Media.DURATION, 1.0);
    Metacard updatedMetacard = OverrideAttributesSupport.overrideMetacard(metacard, overrideMetacard, false);
    assertThat(updatedMetacard.getMetadata(), is("updated"));
    assertThat(updatedMetacard.getTitle(), is("updated"));
    assertThat(updatedMetacard.getResourceURI().toString(), is("content:newstuff"));
    assertThat(updatedMetacard.getId(), is("original"));
    assertThat(updatedMetacard.getMetacardType().getName(), is("ddf.metacard"));
    Set<AttributeDescriptor> allAttributes = new HashSet<>(metacard.getMetacardType().getAttributeDescriptors());
    allAttributes.addAll(overrideMetacard.getMetacardType().getAttributeDescriptors());
    assertThat(updatedMetacard.getMetacardType().getAttributeDescriptors().size(), is(allAttributes.size()));
    allAttributes.removeAll(updatedMetacard.getMetacardType().getAttributeDescriptors());
    assertThat(allAttributes.size(), is(0));
    assertThat(updatedMetacard.getAttribute(Media.DURATION).getValue(), is(1.0));
}
Also used : Metacard(ddf.catalog.data.Metacard) MediaAttributes(ddf.catalog.data.impl.types.MediaAttributes) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with MediaAttributes

use of ddf.catalog.data.impl.types.MediaAttributes 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 3 with MediaAttributes

use of ddf.catalog.data.impl.types.MediaAttributes 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)

Example 4 with MediaAttributes

use of ddf.catalog.data.impl.types.MediaAttributes in project ddf by codice.

the class TransactionMessageBodyReaderTest method setup.

@Before
public void setup() {
    cswRecordConverter = new CswRecordConverter(CswQueryFactoryTest.getCswMetacardType());
    new CoreAttributes().getAttributeDescriptors().stream().forEach(d -> registry.register(d));
    new ContactAttributes().getAttributeDescriptors().stream().forEach(d -> registry.register(d));
    new LocationAttributes().getAttributeDescriptors().stream().forEach(d -> registry.register(d));
    new MediaAttributes().getAttributeDescriptors().stream().forEach(d -> registry.register(d));
    new TopicAttributes().getAttributeDescriptors().stream().forEach(d -> registry.register(d));
    new AssociationsAttributes().getAttributeDescriptors().stream().forEach(d -> registry.register(d));
}
Also used : ContactAttributes(ddf.catalog.data.impl.types.ContactAttributes) LocationAttributes(ddf.catalog.data.impl.types.LocationAttributes) CoreAttributes(ddf.catalog.data.impl.types.CoreAttributes) AssociationsAttributes(ddf.catalog.data.impl.types.AssociationsAttributes) MediaAttributes(ddf.catalog.data.impl.types.MediaAttributes) CswRecordConverter(org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter) TopicAttributes(ddf.catalog.data.impl.types.TopicAttributes) Before(org.junit.Before)

Example 5 with MediaAttributes

use of ddf.catalog.data.impl.types.MediaAttributes in project ddf by codice.

the class TestTransactionRequestConverter method setup.

@Before
public void setup() {
    cswRecordConverter = mock(Converter.class);
    when(cswRecordConverter.canConvert(any())).thenReturn(true);
    new CoreAttributes().getAttributeDescriptors().stream().forEach(d -> mockRegistry.register(d));
    new ContactAttributes().getAttributeDescriptors().stream().forEach(d -> mockRegistry.register(d));
    new LocationAttributes().getAttributeDescriptors().stream().forEach(d -> mockRegistry.register(d));
    new MediaAttributes().getAttributeDescriptors().stream().forEach(d -> mockRegistry.register(d));
    new TopicAttributes().getAttributeDescriptors().stream().forEach(d -> mockRegistry.register(d));
    new AssociationsAttributes().getAttributeDescriptors().stream().forEach(d -> mockRegistry.register(d));
    xStream = new XStream(new Xpp3Driver());
    xStream.registerConverter(new TransactionRequestConverter(cswRecordConverter, mockRegistry));
    xStream.alias(CswConstants.CSW_TRANSACTION, CswTransactionRequest.class);
}
Also used : Xpp3Driver(com.thoughtworks.xstream.io.xml.Xpp3Driver) ContactAttributes(ddf.catalog.data.impl.types.ContactAttributes) LocationAttributes(ddf.catalog.data.impl.types.LocationAttributes) XStream(com.thoughtworks.xstream.XStream) CoreAttributes(ddf.catalog.data.impl.types.CoreAttributes) AssociationsAttributes(ddf.catalog.data.impl.types.AssociationsAttributes) Converter(com.thoughtworks.xstream.converters.Converter) MediaAttributes(ddf.catalog.data.impl.types.MediaAttributes) TopicAttributes(ddf.catalog.data.impl.types.TopicAttributes) Before(org.junit.Before)

Aggregations

MediaAttributes (ddf.catalog.data.impl.types.MediaAttributes)8 ContactAttributes (ddf.catalog.data.impl.types.ContactAttributes)7 TopicAttributes (ddf.catalog.data.impl.types.TopicAttributes)7 AssociationsAttributes (ddf.catalog.data.impl.types.AssociationsAttributes)6 LocationAttributes (ddf.catalog.data.impl.types.LocationAttributes)6 CoreAttributes (ddf.catalog.data.impl.types.CoreAttributes)5 Before (org.junit.Before)5 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)4 CswRecordConverter (org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter)4 Metacard (ddf.catalog.data.Metacard)3 Test (org.junit.Test)3 XStream (com.thoughtworks.xstream.XStream)2 Converter (com.thoughtworks.xstream.converters.Converter)2 Xpp3Driver (com.thoughtworks.xstream.io.xml.Xpp3Driver)2 MetacardType (ddf.catalog.data.MetacardType)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