use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class OverrideAttributesSupportTest method testNoOverrideMetacard.
@Test
public void testNoOverrideMetacard() throws URISyntaxException {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Metacard> metacardMap = new HashMap<>();
MetacardImpl metacard = new MetacardImpl();
metacard.setMetadata("original");
metacard.setTitle("original");
metacard.setId("original");
metacard.setResourceURI(new URI("content:stuff"));
metacardMap.put(metacard.getId(), metacard);
contentItems.add(new ContentItemImpl("original", null, "txt/plain", null));
OverrideAttributesSupport.overrideAttributes(contentItems, metacardMap);
assertNotNull(metacardMap.get("original"));
assertThat(metacardMap.get("original").getMetadata(), is("original"));
assertThat(metacardMap.get("original").getTitle(), is("original"));
assertThat(metacardMap.get("original").getResourceURI().toString(), is("content:stuff"));
assertThat(metacardMap.get("original").getId(), is("original"));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class OverrideAttributesSupportTest method testOverrideAttributesBasic.
@Test
public void testOverrideAttributesBasic() throws URISyntaxException {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Metacard> metacardMap = new HashMap<>();
MetacardImpl overrideMetacard = new MetacardImpl();
MetacardImpl metacard = new MetacardImpl(new MetacardTypeImpl("special", overrideMetacard.getMetacardType().getAttributeDescriptors()));
metacard.setMetadata("original");
metacard.setTitle("original");
metacard.setId("original");
metacard.setResourceURI(new URI("content:stuff"));
overrideMetacard.setTitle("updated");
overrideMetacard.setId("updated");
overrideMetacard.setResourceURI(new URI("content:newstuff"));
overrideMetacard.setMetadata("updated");
metacardMap.put(metacard.getId(), metacard);
contentItems.add(new ContentItemImpl("original", null, "txt/plain", overrideMetacard));
OverrideAttributesSupport.overrideAttributes(contentItems, metacardMap);
assertNotNull(metacardMap.get("original"));
assertThat(metacardMap.get("original").getMetadata(), is("updated"));
assertThat(metacardMap.get("original").getTitle(), is("updated"));
assertThat(metacardMap.get("original").getResourceURI().toString(), is("content:newstuff"));
assertThat(metacardMap.get("original").getId(), is("original"));
assertThat(metacardMap.get("original").getMetacardType().getName(), is("special"));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class OverrideAttributesSupportTest method testOverrideAttributesOther.
@Test
public void testOverrideAttributesOther() throws URISyntaxException {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Metacard> metacardMap = new HashMap<>();
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().getAttributeDescriptors()));
overrideMetacard.setTitle("updated");
overrideMetacard.setId("updated");
overrideMetacard.setMetadata("updated");
overrideMetacard.setResourceURI(new URI("content:newstuff"));
metacardMap.put(metacard.getId(), metacard);
contentItems.add(new ContentItemImpl("original", null, "txt/plain", overrideMetacard));
OverrideAttributesSupport.overrideAttributes(contentItems, metacardMap);
assertNotNull(metacardMap.get("original"));
assertThat(metacardMap.get("original").getMetadata(), is("updated"));
assertThat(metacardMap.get("original").getTitle(), is("updated"));
assertThat(metacardMap.get("original").getResourceURI().toString(), is("content:newstuff"));
assertThat(metacardMap.get("original").getId(), is("original"));
assertThat(metacardMap.get("original").getMetacardType().getName(), is("other"));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class CatalogFrameworkImplTest method testCreateStorageWithAttributeOverridesInvalidType.
/**
* Tests that the framework properly passes a create request to the local provider with attribute overrides.
*/
@Test
public void testCreateStorageWithAttributeOverridesInvalidType() throws Exception {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Serializable> propertiesMap = new HashMap<>();
HashMap<String, Object> attributeMap = new HashMap<>();
attributeMap.put(Metacard.CREATED, "bad date");
propertiesMap.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeMap);
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
MetacardType metacardType = mock(MetacardType.class);
AttributeDescriptor dateAttributeDescriptor = new AttributeDescriptorImpl(Metacard.CREATED, true, true, true, true, new AttributeType<Date>() {
private static final long serialVersionUID = 1L;
@Override
public Class<Date> getBinding() {
return Date.class;
}
@Override
public AttributeFormat getAttributeFormat() {
return AttributeFormat.DATE;
}
});
when(metacardType.getAttributeDescriptor(Metacard.TITLE)).thenReturn(dateAttributeDescriptor);
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 value is not set for invalid format
assertThat(curCard.getCreatedDate(), nullValue());
}
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class FanoutCatalogFrameworkTest method testBlacklistedTagUpdateStorageRequestFails.
@Test(expected = IngestException.class)
public void testBlacklistedTagUpdateStorageRequestFails() throws Exception {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
ContentItem item = new ContentItemImpl(uuidGenerator.generateUuid(), ByteSource.empty(), "text/xml", "filename.xml", 0L, metacard);
UpdateStorageRequest request = new UpdateStorageRequestImpl(Collections.singletonList(item), new HashMap<>());
framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
framework.update(request);
}
Aggregations