Search in sources :

Example 6 with CreateStorageResponse

use of ddf.catalog.content.operation.CreateStorageResponse 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 7 with CreateStorageResponse

use of ddf.catalog.content.operation.CreateStorageResponse 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 8 with CreateStorageResponse

use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.

the class FileSystemStorageProviderTest method testReadDeletedReference.

@Test(expected = StorageException.class)
public void testReadDeletedReference() throws Exception {
    Path tempFile = Files.createTempFile("test", "nitf");
    Files.write(tempFile, TEST_INPUT_CONTENTS.getBytes());
    CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, Collections.singletonMap(Constants.STORE_REFERENCE_KEY, tempFile.toFile().getAbsolutePath()));
    URI uri = new URI(createResponse.getCreatedContentItems().get(0).getUri());
    ReadStorageResponse read = provider.read(new ReadStorageRequestImpl(new URI(createResponse.getCreatedContentItems().get(0).getUri()), Collections.emptyMap()));
    assertThat(read.getContentItem(), notNullValue());
    Files.delete(tempFile);
    provider.read(new ReadStorageRequestImpl(new URI(createResponse.getCreatedContentItems().get(0).getUri()), Collections.emptyMap()));
}
Also used : Path(java.nio.file.Path) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) ReadStorageRequestImpl(ddf.catalog.content.operation.impl.ReadStorageRequestImpl) URI(java.net.URI) Test(org.junit.Test)

Example 9 with CreateStorageResponse

use of ddf.catalog.content.operation.CreateStorageResponse 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)

Example 10 with CreateStorageResponse

use of ddf.catalog.content.operation.CreateStorageResponse in project ddf by codice.

the class FileSystemStorageProviderTest method testReadWithQualifier.

@Test
public void testReadWithQualifier() throws Exception {
    CreateStorageResponse createResponse = assertContentItemWithQualifier(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, "", QUALIFIER);
    String uriString = createResponse.getCreatedContentItems().get(0).getUri();
    assertReadRequest(uriString, NITF_MIME_TYPE);
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test)

Aggregations

CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)24 ContentItem (ddf.catalog.content.data.ContentItem)18 Test (org.junit.Test)17 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)16 Metacard (ddf.catalog.data.Metacard)11 ByteSource (com.google.common.io.ByteSource)9 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)9 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)7 StorageException (ddf.catalog.content.StorageException)5 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)5 DeleteStorageRequest (ddf.catalog.content.operation.DeleteStorageRequest)5 DeleteStorageResponse (ddf.catalog.content.operation.DeleteStorageResponse)5 DeleteStorageRequestImpl (ddf.catalog.content.operation.impl.DeleteStorageRequestImpl)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ReadStorageResponse (ddf.catalog.content.operation.ReadStorageResponse)4 ReadStorageRequestImpl (ddf.catalog.content.operation.impl.ReadStorageRequestImpl)4 IOException (java.io.IOException)4 URI (java.net.URI)4 ReadStorageRequest (ddf.catalog.content.operation.ReadStorageRequest)3