use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnCreate.
@Test
public void testInjectsAttributesOnCreate() throws Exception {
final String title = "Create";
final String injectAttributeName = "new attribute";
final double injectAttributeValue = 2;
final MetacardImpl originalMetacard = new MetacardImpl();
originalMetacard.setTitle(title);
originalMetacard.setAttribute(injectAttributeName, injectAttributeValue);
final List<Metacard> metacards = Collections.singletonList(originalMetacard);
final CreateRequest request = new CreateRequestImpl(metacards, null);
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final CreateResponse response = framework.create(request);
final Metacard createdMetacard = response.getCreatedMetacards().get(0);
final MetacardType createdMetacardType = createdMetacard.getMetacardType();
final MetacardType originalMetacardType = originalMetacard.getMetacardType();
assertThat(createdMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(createdMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(createdMetacard.getTitle(), is(title));
assertThat(createdMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
use of ddf.catalog.data.impl.AttributeDescriptorImpl 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);
when(metacardType.getAttributeDescriptors()).thenReturn(Collections.singleton(new CoreAttributes().getAttributeDescriptor(Core.TITLE)));
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.impl.AttributeDescriptorImpl 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.impl.AttributeDescriptorImpl in project ddf by codice.
the class GetRecordsResponseConverterTest method createMetacardList.
private List<Metacard> createMetacardList(int start, int finish) {
List<Metacard> list = new LinkedList<>();
for (int i = start; i <= finish; i++) {
MetacardImpl metacard = new MetacardImpl();
metacard.setId(ID_PREFIX + i);
metacard.setSourceId(SOURCE_PREFIX + i);
metacard.setTitle(TITLE_PREFIX + i);
// for testing an attribute with multiple values
AttributeDescriptor ad = new AttributeDescriptorImpl(FORMAT, true, true, true, true, BasicTypes.STRING_TYPE);
Set<AttributeDescriptor> ads = new HashSet<>(metacard.getMetacardType().getAttributeDescriptors());
ads.add(ad);
metacard.setType(new MetacardTypeImpl("test", ads));
metacard.setLocation(WKT);
AttributeImpl attr = new AttributeImpl(FORMAT, FORMAT);
attr.addValue(FORMAT);
metacard.setAttribute(attr);
// for testing an attribute with no attribute descriptor
metacard.setAttribute(RELATION, RELATION);
list.add(metacard);
}
return list;
}
use of ddf.catalog.data.impl.AttributeDescriptorImpl in project ddf by codice.
the class GeoJsonMetacardTransformerTest method testWithMultiValueAttributes.
@Test
public void testWithMultiValueAttributes() throws Exception {
Set<AttributeDescriptor> descriptors = new HashSet(MetacardImpl.BASIC_METACARD.getAttributeDescriptors());
descriptors.add(new AttributeDescriptorImpl("multi-string", true, true, false, true, /* multivalued */
BasicTypes.STRING_TYPE));
MetacardType type = new MetacardTypeImpl("multi", descriptors);
MetacardImpl metacard = new MetacardImpl(type);
metacard.setAttribute("multi-string", (Serializable) Arrays.asList("foo", "bar"));
GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
BinaryContent content = transformer.transform(metacard, null);
String jsonText = new String(content.getByteArray());
JSONObject json = (JSONObject) PARSER.parse(jsonText);
Map properties = (Map) json.get("properties");
List<String> strings = (List<String>) properties.get("multi-string");
assertThat(strings.get(0), is("foo"));
assertThat(strings.get(1), is("bar"));
}
Aggregations