use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class FileSystemStorageProviderTest method testCreateWithQualifierAndOneInvalidItem.
@Test
public void testCreateWithQualifierAndOneInvalidItem() throws Exception {
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return IOUtils.toInputStream("This data is my data, this data is your data.");
}
};
ContentItem contentItem = new ContentItemImpl(uuid, null, byteSource, "application/text", "datadatadata", byteSource.size(), mock(Metacard.class));
String invalidUuid = "wow-this-isn't-a-valid-uuid-right?!@#%";
ContentItem badContentItem = new ContentItemImpl(invalidUuid, null, byteSource, "application/text", "datadatadata", byteSource.size(), mock(Metacard.class));
CreateStorageRequest createRequest = new CreateStorageRequestImpl(Lists.newArrayList(contentItem, badContentItem), null);
CreateStorageResponse createResponse = provider.create(createRequest);
assertThat(createResponse.getCreatedContentItems().size(), is(1));
assertThat(createResponse.getCreatedContentItems().get(0).getId(), is(uuid));
ContentItem updateContentItem = new ContentItemImpl(invalidUuid, null, byteSource, "application/text", "datadatadata", byteSource.size(), mock(Metacard.class));
UpdateStorageRequest updateRequest = new UpdateStorageRequestImpl(Lists.newArrayList(updateContentItem), null);
UpdateStorageResponse updateResponse = provider.update(updateRequest);
assertThat(updateResponse.getUpdatedContentItems().size(), is(0));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class FileSystemStorageProviderTest method testDeleteWithQualifier.
@Test
public void testDeleteWithQualifier() throws Exception {
CreateStorageResponse createResponse = assertContentItemWithQualifier(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, "", QUALIFIER);
String id = createResponse.getCreatedContentItems().get(0).getId();
DeleteStorageRequest deleteRequest = new DeleteStorageRequestImpl(createResponse.getCreatedContentItems().stream().map(ContentItem::getMetacard).collect(Collectors.toList()), null);
when(deleteRequest.getMetacards().get(0).getId()).thenReturn(id);
DeleteStorageResponse deleteResponse = provider.delete(deleteRequest);
provider.commit(deleteRequest);
List<ContentItem> items = deleteResponse.getDeletedContentItems();
ContentItem item = items.get(0);
LOGGER.debug("Item retrieved: {}", item);
assertEquals(id, item.getId());
assertThat(item.getFilename(), is(""));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class FileSystemStorageProviderTest method testUpdateWithMultipleItems.
@Test
public void testUpdateWithMultipleItems() throws Exception {
CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
URI unqualifiedUri = new URI(createResponse.getCreatedContentItems().get(0).getUri());
createResponse = assertContentItemWithQualifier(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, createResponse.getCreatedContentItems().get(0).getId(), QUALIFIER);
URI qualifiedUri = new URI(createResponse.getCreatedContentItems().get(0).getUri());
String id = createResponse.getCreatedContentItems().get(0).getId();
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return IOUtils.toInputStream("Updated NITF");
}
};
ContentItem updateItem = new ContentItemImpl(id, byteSource, NITF_MIME_TYPE, mock(Metacard.class));
submitAndVerifySuccessfulUpdateStorageRequest(updateItem);
updateItem = new ContentItemImpl(id, qualifiedUri.getFragment(), byteSource, NITF_MIME_TYPE, mock(Metacard.class));
submitAndVerifySuccessfulUpdateStorageRequest(updateItem);
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class FileSystemStorageProviderTest method testInvalidDelete.
@Test
public void testInvalidDelete() throws Exception {
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
Metacard metacard = mock(Metacard.class);
when(metacard.getId()).thenReturn(uuid);
ContentItem contentItem = new ContentItemImpl(uuid, null, null, "application/text", "datadatadata", 0, metacard);
DeleteStorageRequest deleteRequest = new DeleteStorageRequestImpl(Lists.newArrayList(metacard), null);
DeleteStorageResponse deleteResponse = provider.delete(deleteRequest);
assertThat(deleteResponse.getDeletedContentItems().size(), is(0));
}
use of ddf.catalog.content.data.ContentItem in project ddf by codice.
the class FileSystemStorageProviderTest method testDelete.
@Test
public void testDelete() throws Exception {
CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
String id = createResponse.getCreatedContentItems().get(0).getId();
DeleteStorageRequest deleteRequest = new DeleteStorageRequestImpl(createResponse.getCreatedContentItems().stream().map(ContentItem::getMetacard).collect(Collectors.toList()), null);
when(deleteRequest.getMetacards().get(0).getId()).thenReturn(id);
DeleteStorageResponse deleteResponse = provider.delete(deleteRequest);
List<ContentItem> items = deleteResponse.getDeletedContentItems();
ContentItem item = items.get(0);
LOGGER.debug("Item retrieved: {}", item);
assertEquals(id, item.getId());
assertThat(item.getFilename(), isEmptyString());
}
Aggregations