use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class TestVideoThumbnailPlugin method testUpdatedItemGifThumbnail.
@Test
public void testUpdatedItemGifThumbnail() throws Exception {
setUpMockContentItem("/medium.mp4");
final UpdateStorageResponse mockUpdateResponse = mock(UpdateStorageResponse.class);
doReturn(Collections.singletonList(mockContentItem)).when(mockUpdateResponse).getUpdatedContentItems();
final UpdateStorageRequest mockUpdateRequest = mock(UpdateStorageRequest.class);
doReturn(mockUpdateRequest).when(mockUpdateResponse).getRequest();
doReturn(properties).when(mockUpdateResponse).getProperties();
final UpdateStorageResponse processedUpdateResponse = videoThumbnailPlugin.process(mockUpdateResponse);
final byte[] thumbnail = (byte[]) processedUpdateResponse.getUpdatedContentItems().get(0).getMetacard().getAttribute(Metacard.THUMBNAIL).getValue();
assertThat(thumbnail, notNullValue());
verifyThumbnailIsGif(thumbnail);
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class HistorianTest method testNullContentItemStorageReadRequest.
@Test
public void testNullContentItemStorageReadRequest() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException {
List<Metacard> metacards = getMetacardUpdatePair();
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
// Make content item null
storageProvider.storageMap.put(METACARD_ID, null);
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
// Verify that the content item DIDN't updated
ReadStorageRequest request = mock(ReadStorageRequest.class);
when(request.getResourceUri()).thenReturn(new URI(RESOURCE_URI));
ContentItem item = storageProvider.read(request).getContentItem();
assertThat(item, nullValue());
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class HistorianTest method testBadContentItemSize.
@Test
public void testBadContentItemSize() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException, IOException {
// The metacard and updated metacard
List<Metacard> metacards = getMetacardUpdatePair();
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
storeMetacard(metacards.get(0));
// send a request to update the metacard
updateMetacard(storageRequest, storageResponse, metacards.get(1));
storageProvider.update(storageRequest);
when(storageProvider.storageMap.get(RESOURCE_URI).getSize()).thenThrow(IOException.class);
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
// Verify that the metacard updated
Metacard update = readMetacard();
assertThat(update, equalTo(metacards.get(1)));
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class HistorianTest method testRollbackFailed.
@Test(expected = IngestException.class)
public void testRollbackFailed() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException {
List<Metacard> metacards = getMetacardUpdatePair();
// Mock out a bad storage provider
StorageProvider exceptionStorageProvider = mock(StorageProvider.class);
doThrow(StorageException.class).when(exceptionStorageProvider).commit(any());
doThrow(StorageException.class).when(exceptionStorageProvider).rollback(any());
ContentItem item = mock(ContentItem.class);
when(item.getId()).thenReturn(METACARD_ID);
when(item.getUri()).thenReturn(RESOURCE_URI);
when(item.getMetacard()).thenReturn(metacards.get(0));
ReadStorageResponse readStorageResponse = mock(ReadStorageResponse.class);
when(readStorageResponse.getContentItem()).thenReturn(item);
when(exceptionStorageProvider.read(any())).thenReturn(readStorageResponse);
when(exceptionStorageProvider.create(any())).thenReturn(mock(CreateStorageResponse.class));
historian.setStorageProviders(Collections.singletonList(exceptionStorageProvider));
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
UpdateResponse updateResponse = mock(UpdateResponse.class);
// send a request to update the metacard
updateMetacard(storageRequest, storageResponse, metacards.get(1));
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
verify(exceptionStorageProvider).rollback(any(StorageRequest.class));
}
use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.
the class HistorianTest method testUpdateStorageResponseSetSkipFlag.
@Test
public void testUpdateStorageResponseSetSkipFlag() throws SourceUnavailableException, IngestException, StorageException, UnsupportedQueryException {
Map<String, Serializable> storageRequestProperties = new HashMap<>();
Map<String, Serializable> storageResponseProperties = new HashMap<>();
// The metacard and updated metacard
List<Metacard> metacards = getMetacardUpdatePair();
// Parameters for historian
UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
when(storageRequest.getProperties()).thenReturn(storageRequestProperties);
UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
when(storageResponse.getProperties()).thenReturn(storageResponseProperties);
UpdateResponse updateResponse = mock(UpdateResponse.class);
storeMetacard(metacards.get(0));
// send a request to update the metacard
updateMetacard(storageRequest, storageResponse, metacards.get(1));
storageProvider.update(storageRequest);
mockQuery(metacards.get(1));
historian.version(storageRequest, storageResponse, updateResponse);
assertThat(storageRequestProperties, hasEntry(MetacardVersion.SKIP_VERSIONING, true));
assertThat(storageResponseProperties, hasEntry(MetacardVersion.SKIP_VERSIONING, true));
}
Aggregations