Search in sources :

Example 1 with DeleteStorageRequestImpl

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

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

use of ddf.catalog.content.operation.impl.DeleteStorageRequestImpl in project ddf by codice.

the class FileSystemStorageProviderTest method testDeleteIdWithMultpleContent.

@Test
public void testDeleteIdWithMultpleContent() throws Exception {
    CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME);
    createResponse = assertContentItemWithQualifier(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, createResponse.getCreatedContentItems().get(0).getId(), 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();
    assertThat(items, hasSize(2));
    for (ContentItem item : items) {
        LOGGER.debug("Item retrieved: {}", item);
        assertThat(item.getId(), is(id));
        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 4 with DeleteStorageRequestImpl

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

use of ddf.catalog.content.operation.impl.DeleteStorageRequestImpl in project ddf by codice.

the class FileSystemStorageProviderTest method testDeleteReference.

@Test
public void testDeleteReference() throws Exception {
    String path = baseTmpDir + File.separator + TEST_INPUT_FILENAME;
    File tempFile = new File(path);
    FileUtils.writeStringToFile(tempFile, TEST_INPUT_CONTENTS);
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(Constants.STORE_REFERENCE_KEY, tempFile.toURI().toASCIIString());
    CreateStorageResponse createResponse = assertContentItem(TEST_INPUT_CONTENTS, NITF_MIME_TYPE, TEST_INPUT_FILENAME, properties);
    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());
    assertTrue(tempFile.exists());
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) Serializable(java.io.Serializable) DeleteStorageResponse(ddf.catalog.content.operation.DeleteStorageResponse) HashMap(java.util.HashMap) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) File(java.io.File) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Aggregations

DeleteStorageRequestImpl (ddf.catalog.content.operation.impl.DeleteStorageRequestImpl)10 DeleteStorageRequest (ddf.catalog.content.operation.DeleteStorageRequest)9 Test (org.junit.Test)8 ContentItem (ddf.catalog.content.data.ContentItem)6 DeleteStorageResponse (ddf.catalog.content.operation.DeleteStorageResponse)6 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)6 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)5 StorageException (ddf.catalog.content.StorageException)3 Metacard (ddf.catalog.data.Metacard)3 DeleteResponse (ddf.catalog.operation.DeleteResponse)3 DeleteRequestImpl (ddf.catalog.operation.impl.DeleteRequestImpl)3 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)2 DeleteRequest (ddf.catalog.operation.DeleteRequest)2 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)2 IngestException (ddf.catalog.source.IngestException)2 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)1 StopProcessingException (ddf.catalog.plugin.StopProcessingException)1 InternalIngestException (ddf.catalog.source.InternalIngestException)1 File (java.io.File)1 Serializable (java.io.Serializable)1