use of ddf.catalog.data.MetacardType in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnQuery.
@Test
public void testInjectsAttributesOnQuery() throws Exception {
final Metacard original = new MetacardImpl();
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(original), null)).getCreatedMetacards().get(0).getId();
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl("new attribute", true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final FilterFactory filterFactory = new FilterFactoryImpl();
final Filter filter = filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(id));
final QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
final QueryResponse response = framework.query(request);
final Metacard queryMetacard = response.getResults().get(0).getMetacard();
final MetacardType originalMetacardType = original.getMetacardType();
final MetacardType queryMetacardType = queryMetacard.getMetacardType();
assertThat(originalMetacardType.getName(), is(queryMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(queryMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
}
use of ddf.catalog.data.MetacardType in project ddf by codice.
the class CatalogFrameworkImplTest method testCreateStorageWithAttributeOverrides.
/**
* Tests that the framework properly passes a create request to the local provider with attribute overrides.
*/
@Test
public void testCreateStorageWithAttributeOverrides() throws Exception {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Serializable> propertiesMap = new HashMap<>();
HashMap<String, String> attributeMap = new HashMap<>();
attributeMap.put(Metacard.TITLE, "test");
attributeMap.put("foo", "bar");
propertiesMap.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeMap);
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
MetacardType metacardType = mock(MetacardType.class);
AttributeDescriptor stringAttributeDescriptor = new AttributeDescriptorImpl(Metacard.TITLE, true, true, true, true, new AttributeType<String>() {
private static final long serialVersionUID = 1L;
@Override
public Class<String> getBinding() {
return String.class;
}
@Override
public AttributeFormat getAttributeFormat() {
return AttributeFormat.STRING;
}
});
when(metacardType.getAttributeDescriptor(Metacard.TITLE)).thenReturn(stringAttributeDescriptor);
newCard.setType(metacardType);
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("blah".getBytes());
}
};
ContentItemImpl newItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, newCard);
contentItems.add(newItem);
CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, propertiesMap));
assertEquals(response.getCreatedMetacards().size(), provider.size());
assertEquals(response.getCreatedMetacards().size(), storageProvider.size());
for (Metacard curCard : response.getCreatedMetacards()) {
assertNotNull(curCard.getId());
// Assert valid attribute is set for the metacard
assertThat(curCard.getTitle(), is("test"));
// Assert invalid attribute is not set for the metacard
assertThat(curCard.getAttribute("foo"), nullValue());
}
// Assert That Attribute Overrides do not exist after create
assertThat(attributeMap.get(Constants.ATTRIBUTE_OVERRIDES_KEY), nullValue());
}
use of ddf.catalog.data.MetacardType in project ddf by codice.
the class TestGenericFeatureConverter method testMetacardCollectionToFeatureCollectionXml.
@Test
public void testMetacardCollectionToFeatureCollectionXml() {
XStream xstream = new XStream(new EnhancedStaxDriver());
xstream.setMode(XStream.NO_REFERENCES);
xstream.registerConverter(new FeatureCollectionConverterWfs20());
xstream.registerConverter(new GenericFeatureConverterWfs20());
xstream.registerConverter(new GmlGeometryConverter());
// Required the Implementing class. The interface would not work...
xstream.alias(Wfs20Constants.WFS_NAMESPACE_PREFIX + ":" + "FeatureCollection", Wfs20FeatureCollection.class);
Metacard mc = new SampleMetacard().getMetacard();
Wfs20FeatureCollection wfc = new Wfs20FeatureCollection();
wfc.getMembers().add(mc);
MetacardImpl mc2 = new SampleMetacard().getMetacard();
// Ignore the hack stuff, this was just to imitate having two different
// "MetacardTypes"
mc2.setType(new MetacardType() {
@Override
public String getName() {
return "otherType";
}
@Override
public Set<AttributeDescriptor> getAttributeDescriptors() {
return BasicTypes.BASIC_METACARD.getAttributeDescriptors();
}
@Override
public AttributeDescriptor getAttributeDescriptor(String arg0) {
return BasicTypes.BASIC_METACARD.getAttributeDescriptor(arg0);
}
});
wfc.getMembers().add(mc2);
String xml = xstream.toXML(wfc);
}
use of ddf.catalog.data.MetacardType in project ddf by codice.
the class TestGenericFeatureConverter method testUnmarshalSingleFeatureXmlToObject.
@Test
//DDF-733
@Ignore
public void testUnmarshalSingleFeatureXmlToObject() {
XStream xstream = new XStream(new WstxDriver());
MetacardType metacardType = buildMetacardType();
GenericFeatureConverterWfs20 converter = new GenericFeatureConverterWfs20();
converter.setMetacardType(buildMetacardType());
converter.setSourceId(SOURCE_ID);
converter.setCoordinateOrder(GeospatialUtil.LAT_LON_ORDER);
xstream.registerConverter(converter);
xstream.registerConverter(new GmlGeometryConverter());
xstream.alias(FEATURE_TYPE, MetacardImpl.class);
InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set.xml");
Metacard mc = (Metacard) xstream.fromXML(is);
assertEquals("video_data_set.2", mc.getId());
assertEquals(FEATURE_TYPE, mc.getContentTypeName());
assertEquals(metacardType.getName(), mc.getMetacardType().getName());
assertEquals(SOURCE_ID, mc.getSourceId());
assertEquals("video_data_set.2", mc.getTitle());
assertEquals(2L, mc.getAttribute(PROPERTY_PREFIX + ID_ELEMENT).getValue());
assertEquals(Long.valueOf(1L), mc.getAttribute(PROPERTY_PREFIX + VERSION_ELEMENT).getValue());
assertEquals(DatatypeConverter.parseDateTime("2005-04-07T09:54:38.983").getTime(), mc.getAttribute(PROPERTY_PREFIX + END_DATE_ELEMENT).getValue());
assertEquals("/data/test_suite/video/video/videoFile.mpg", mc.getAttribute(PROPERTY_PREFIX + FILENAME_ELEMENT).getValue());
assertEquals(720L, mc.getAttribute(PROPERTY_PREFIX + HEIGHT_ELEMENT).getValue());
assertEquals("a8a55092f0afae881099637ef7746cd8d7066270d9af4cf0f52c41dab53c4005", mc.getAttribute(PROPERTY_PREFIX + INDEX_ID_ELEMENT).getValue());
assertEquals(getOtherTagsXml(), mc.getAttribute(PROPERTY_PREFIX + OTHER_TAGS_XML_ELEMENT).getValue());
assertEquals(26L, mc.getAttribute(PROPERTY_PREFIX + REPOSITORY_ID_ELEMENT).getValue());
assertEquals(DatatypeConverter.parseDateTime("2005-04-07T09:53:39.000").getTime(), mc.getAttribute(PROPERTY_PREFIX + START_DATE_ELEMENT).getValue());
assertEquals(1280L, mc.getAttribute(PROPERTY_PREFIX + WIDTH_ELEMENT).getValue());
assertEquals(getLocation(), mc.getLocation());
assertEquals(mc.getLocation(), mc.getAttribute(PROPERTY_PREFIX + GROUND_GEOM_ELEMENT).getValue());
assertNotNull(mc.getCreatedDate());
assertNotNull(mc.getEffectiveDate());
assertNotNull(mc.getModifiedDate());
assertNotNull(mc.getContentTypeNamespace());
assertEquals(mc.getContentTypeNamespace().toString(), Wfs20Constants.NAMESPACE_URN_ROOT + metacardType.getName());
}
use of ddf.catalog.data.MetacardType in project ddf by codice.
the class AttributeRegistryImplTest method testDeregisterMetacardType.
@Test
public void testDeregisterMetacardType() {
MetacardType metacardType = generateMetacardType();
registry.deregisterMetacardType(generateMetacardType());
metacardType.getAttributeDescriptors().forEach(attributeDescriptor -> assertThat(registry.lookup(attributeDescriptor.getName()).isPresent(), is(false)));
}
Aggregations