use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class FileSystemStorageProviderTest method testUpdateMultipleQualifiedItemsInTheSameRequest.
@Test
public void testUpdateMultipleQualifiedItemsInTheSameRequest() throws Exception {
// store unqualified content item
final CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
final ContentItem createdContentItem = createResponse.getCreatedContentItems().get(0);
final String id = createdContentItem.getId();
final Metacard metacard = createdContentItem.getMetacard();
// add 2 new qualified content items with the same id
final ByteSource q1ByteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return IOUtils.toInputStream("q1 content", StandardCharsets.UTF_8);
}
};
final ContentItem q1ContentItem = new ContentItemImpl(id, "q1", q1ByteSource, "image/png", "q1.png", q1ByteSource.size(), metacard);
final ByteSource q2ByteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return IOUtils.toInputStream("q2 content", StandardCharsets.UTF_8);
}
};
final ContentItem q2ContentItem = new ContentItemImpl(id, "q2", q2ByteSource, "image/png", "q2.png", q2ByteSource.size(), metacard);
submitAndVerifySuccessfulUpdateStorageRequest(q1ContentItem, q2ContentItem);
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class CatalogFrameworkImplTest method testCreateStorage.
/**
* Tests that the framework properly passes a create request to the local provider.
*/
@Test
public void testCreateStorage() throws Exception {
List<ContentItem> contentItems = new ArrayList<>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
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, null));
assertEquals(response.getCreatedMetacards().size(), provider.size());
assertEquals(response.getCreatedMetacards().size(), storageProvider.size());
for (Metacard curCard : response.getCreatedMetacards()) {
assertNotNull(curCard.getId());
}
// make sure that the event was posted correctly
assertTrue(eventAdmin.wasEventPosted());
Metacard[] array = {};
array = response.getCreatedMetacards().toArray(array);
assertTrue(eventAdmin.wasEventPosted());
assertEquals(eventAdmin.getLastEvent(), array[array.length - 1]);
}
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(), any())).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 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);
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 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 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());
}
Aggregations