Search in sources :

Example 16 with UpdateStorageResponse

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

the class FileSystemStorageProviderTest method submitAndVerifySuccessfulUpdateStorageRequest.

private void submitAndVerifySuccessfulUpdateStorageRequest(ContentItem... requestContentItems) throws Exception {
    final UpdateStorageRequest updateStorageRequest = new UpdateStorageRequestImpl(Arrays.asList(requestContentItems), null);
    final UpdateStorageResponse updateStorageResponse = provider.update(updateStorageRequest);
    final List<ContentItem> responseContentItems = updateStorageResponse.getUpdatedContentItems();
    assertThat("Expect number of ContentItems in UpdateStorageResponse", responseContentItems, hasSize(requestContentItems.length));
    for (final ContentItem responseContentItem : responseContentItems) {
        // assert file exists
        final URI uri = new URI(responseContentItem.getUri());
        final List<String> parts = provider.getContentFilePathParts(uri.getSchemeSpecificPart(), uri.getFragment());
        final String expectedFilePath = baseDir + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_REPOSITORY + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_STORE + File.separator + FileSystemStorageProvider.DEFAULT_TMP + File.separator + updateStorageRequest.getId() + File.separator + parts.get(0) + File.separator + parts.get(1) + File.separator + parts.get(2) + (StringUtils.isNotBlank(responseContentItem.getQualifier()) ? File.separator + responseContentItem.getQualifier() : "") + File.separator + responseContentItem.getFilename();
        assertThat("Expect file exists at " + expectedFilePath, Files.exists(Paths.get(expectedFilePath)));
        // assert metacard attributes set
        final ArgumentCaptor<Attribute> captor = ArgumentCaptor.forClass(Attribute.class);
        final Metacard metacard = responseContentItem.getMetacard();
        if (StringUtils.isBlank(responseContentItem.getQualifier())) {
            verify(metacard, times(2)).setAttribute(captor.capture());
            Attribute resourceUriAttribute = captor.getAllValues().get(0);
            assertThat(resourceUriAttribute.getName(), is(Metacard.RESOURCE_URI));
            assertThat(resourceUriAttribute.getValue(), is(uri.toString()));
            Attribute resourceSizeAttribute = captor.getAllValues().get(1);
            assertThat(resourceSizeAttribute.getName(), is(Metacard.RESOURCE_SIZE));
            assertThat(resourceSizeAttribute.getValue(), is(responseContentItem.getSize()));
        } else {
            verify(metacard, never()).setAttribute(any());
        }
    }
    provider.commit(updateStorageRequest);
    for (ContentItem responseContentItem : responseContentItems) {
        assertReadRequest(responseContentItem.getUri(), responseContentItem.getMimeType().toString());
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) Attribute(ddf.catalog.data.Attribute) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem)

Aggregations

UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)16 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)14 Metacard (ddf.catalog.data.Metacard)13 Test (org.junit.Test)12 UpdateResponse (ddf.catalog.operation.UpdateResponse)11 ContentItem (ddf.catalog.content.data.ContentItem)9 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)8 StorageProvider (ddf.catalog.content.StorageProvider)4 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)4 ReadStorageRequest (ddf.catalog.content.operation.ReadStorageRequest)4 HashMap (java.util.HashMap)4 StorageException (ddf.catalog.content.StorageException)3 ReadStorageResponse (ddf.catalog.content.operation.ReadStorageResponse)3 StorageRequest (ddf.catalog.content.operation.StorageRequest)3 UpdateStorageRequestImpl (ddf.catalog.content.operation.impl.UpdateStorageRequestImpl)3 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)3 ArrayList (java.util.ArrayList)3 ByteSource (com.google.common.io.ByteSource)2 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)2 DeleteStorageRequest (ddf.catalog.content.operation.DeleteStorageRequest)2