use of ddf.catalog.content.data.impl.ContentItemImpl 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.impl.ContentItemImpl 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.impl.ContentItemImpl 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.impl.ContentItemImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateStorage.
/**
* Tests that the framework properly passes an update request to the local provider.
*/
@Test
public void testUpdateStorage() throws Exception {
List<ContentItem> contentItems = new ArrayList<>();
MetacardImpl metacard = new MetacardImpl();
metacard.setId(null);
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);
contentItems.add(contentItem);
CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, null));
Metacard insertedCard = response.getCreatedMetacards().get(0);
List<ContentItem> updatedContentItems = new ArrayList<>();
updatedContentItems.add(new ContentItemImpl(insertedCard.getId(), byteSource, "application/octet-stream", insertedCard));
UpdateStorageRequest request = new UpdateStorageRequestImpl(updatedContentItems, null);
List<Result> mockFederationResults = Stream.of(insertedCard).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 newMetacard = returnedCards.get(0).getNewMetacard();
assertThat(newMetacard.getId(), notNullValue());
assertThat(newMetacard.getResourceURI().toString(), is(contentItem.getUri()));
assertThat(newMetacard.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.impl.ContentItemImpl in project ddf by codice.
the class FtpRequestHandler method getCreateStorageRequest.
private CreateStorageRequest getCreateStorageRequest(String fileName, TemporaryFileBackedOutputStream outputStream) throws IOException {
String fileExtension = FilenameUtils.getExtension(fileName);
String mimeType = getMimeType(fileExtension, outputStream);
ContentItem newItem = new ContentItemImpl(uuidGenerator.generateUuid(), outputStream.asByteSource(), mimeType, fileName, 0L, null);
return new CreateStorageRequestImpl(Collections.singletonList(newItem), null);
}
Aggregations