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());
}
}
Aggregations