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));
}
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"));
}
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"));
}
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));
}
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);
}
Aggregations