Search in sources :

Example 16 with ContentItem

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));
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) Metacard(ddf.catalog.data.Metacard) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ByteSource(com.google.common.io.ByteSource) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Example 17 with ContentItem

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(""));
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) DeleteStorageResponse(ddf.catalog.content.operation.DeleteStorageResponse) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 18 with ContentItem

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);
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) Metacard(ddf.catalog.data.Metacard) ByteSource(com.google.common.io.ByteSource) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 19 with ContentItem

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));
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) Metacard(ddf.catalog.data.Metacard) DeleteStorageResponse(ddf.catalog.content.operation.DeleteStorageResponse) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 20 with ContentItem

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());
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) DeleteStorageResponse(ddf.catalog.content.operation.DeleteStorageResponse) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Aggregations

ContentItem (ddf.catalog.content.data.ContentItem)65 Metacard (ddf.catalog.data.Metacard)37 Test (org.junit.Test)36 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)27 ArrayList (java.util.ArrayList)22 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)20 HashMap (java.util.HashMap)19 URI (java.net.URI)17 ByteSource (com.google.common.io.ByteSource)16 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)16 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)15 IOException (java.io.IOException)14 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)13 StorageException (ddf.catalog.content.StorageException)12 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)12 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)11 InputStream (java.io.InputStream)11 Map (java.util.Map)11 StorageProvider (ddf.catalog.content.StorageProvider)10 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)10