use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class ContentItemValidatorTest method testInvalidQualifier.
@Test
public void testInvalidQualifier() throws Exception {
String id = "634e8505-bd4b-436e-97e8-2045d1b0d265".replace("-", "");
String qualifier = "!wow!#$These%^characters&*aren't(_`allowed!!";
ContentItem item = new ContentItemImpl(id, qualifier, null, "", null);
assertThat(ContentItemValidator.validate(item), is(false));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateItemWithQualifier.
/**
* Tests that the framework properly passes an update request to the local provider when the
* content item has a qualifier.
*/
@Test
public void testUpdateItemWithQualifier() throws Exception {
// store one item
MetacardImpl metacard = new MetacardImpl();
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("blah".getBytes());
}
};
ContentItemImpl contentItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, metacard);
CreateResponse response = framework.create(new CreateStorageRequestImpl(Collections.singletonList(contentItem), null));
Metacard createResponseMetacard = response.getCreatedMetacards().get(0);
// update with 2 more content items that have a qualifier and the same id and metacard as the already-created item
List<ContentItem> updateRequestContentItems = new ArrayList<>();
ByteSource q1ByteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("q1 data".getBytes());
}
};
ContentItem q1ContentItem = new ContentItemImpl(createResponseMetacard.getId(), "q1", q1ByteSource, "application/octet-stream", createResponseMetacard);
updateRequestContentItems.add(q1ContentItem);
ByteSource q2ByteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("q2 data".getBytes());
}
};
ContentItem q2ContentItem = new ContentItemImpl(createResponseMetacard.getId(), "q2", q2ByteSource, "application/octet-stream", createResponseMetacard);
updateRequestContentItems.add(q2ContentItem);
UpdateStorageRequest request = new UpdateStorageRequestImpl(updateRequestContentItems, null);
List<Result> mockFederationResults = Stream.of(createResponseMetacard).map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
// send update to framework
List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
assertThat(returnedCards, hasSize(1));
final Metacard updateResponseMetacard = returnedCards.get(0).getNewMetacard();
assertThat(updateResponseMetacard.getId(), notNullValue());
assertThat(updateResponseMetacard.getResourceURI().toString(), is(contentItem.getUri()));
assertThat(updateResponseMetacard.getResourceSize(), is(Long.toString(byteSource.size())));
assertThat(response.getCreatedMetacards(), hasSize(storageProvider.size()));
// make sure that the event was posted correctly
assertThat(eventAdmin.wasEventPosted(), is(true));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class HistorianTest method testNullContentItemStorageReadRequest.
@Test
public void testNullContentItemStorageReadRequest() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException {
List<Metacard> metacards = getMetacardUpdatePair();
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
// Make content item null
storageProvider.storageMap.put(METACARD_ID, null);
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
// Verify that the content item DIDN't updated
ReadStorageRequest request = mock(ReadStorageRequest.class);
when(request.getResourceUri()).thenReturn(new URI(RESOURCE_URI));
ContentItem item = storageProvider.read(request).getContentItem();
assertThat(item, nullValue());
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class InMemoryStorageProvider method delete.
@Override
public DeleteStorageResponse delete(DeleteStorageRequest deleteRequest) throws StorageException {
if (deleteRequest == null) {
throw new StorageException("delete request can't be null");
}
List<ContentItem> itemsToDelete = new ArrayList<>();
for (Metacard metacard : deleteRequest.getMetacards()) {
List<ContentItem> tmp = storageMap.values().stream().filter(item -> item.getMetacard().getId().equals(metacard.getId())).collect(Collectors.toList());
if (tmp.isEmpty()) {
throw new StorageException("can't delete a metacard that isn't stored");
}
itemsToDelete.addAll(tmp);
}
for (ContentItem item : itemsToDelete) {
deleteMap.put(item.getUri(), item);
}
return new DeleteStorageResponseImpl(deleteRequest, itemsToDelete);
}
use of ddf.catalog.content.data.ContentItem 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());
}
Aggregations