use of ddf.catalog.content.operation.StorageRequest in project ddf by codice.
the class ContentProducerDataAccessObjectTest method testProcessHeaders.
@Test
public void testProcessHeaders() throws IOException {
Map<String, Serializable> requestProperties = new HashMap<>();
StorageRequest storageRequest = mock(StorageRequest.class);
doReturn(requestProperties).when(storageRequest).getProperties();
Map<String, Object> camelHeaders = new HashMap<>();
Map<String, Serializable> attributeOverrides = new HashMap<>();
attributeOverrides.put("example", ImmutableList.of("something", "something1"));
attributeOverrides.put("example2", ImmutableList.of("something2"));
camelHeaders.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeOverrides);
contentProducerDataAccessObject.processHeaders(camelHeaders, storageRequest, Files.createTempFile("foobar", "txt").toFile());
assertThat(requestProperties.containsKey(Constants.STORE_REFERENCE_KEY), is(false));
assertThat(((Map<String, List<String>>) requestProperties.get(Constants.ATTRIBUTE_OVERRIDES_KEY)).get("example"), is(Arrays.asList("something", "something1")));
requestProperties.clear();
camelHeaders.put(Constants.ATTRIBUTE_OVERRIDES_KEY, ImmutableMap.of());
camelHeaders.put(Constants.STORE_REFERENCE_KEY, "true");
contentProducerDataAccessObject.processHeaders(camelHeaders, storageRequest, Files.createTempFile("foobar", "txt").toFile());
assertThat(requestProperties.containsKey(Constants.STORE_REFERENCE_KEY), is(true));
assertThat(requestProperties.containsKey(Constants.ATTRIBUTE_OVERRIDES_KEY), is(false));
}
use of ddf.catalog.content.operation.StorageRequest in project ddf by codice.
the class HistorianTest method testTryCommitStorageException.
@Test(expected = IngestException.class)
public void testTryCommitStorageException() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException {
List<Metacard> metacards = getMetacardUpdatePair();
// Mock out a bad storage provider
StorageProvider exceptionStorageProvider = mock(StorageProvider.class);
doThrow(StorageException.class).when(exceptionStorageProvider).commit(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);
Update update1 = mock(Update.class);
when(update1.getOldMetacard()).thenReturn(metacards.get(0));
when(updateResponse.getUpdatedMetacards()).thenReturn(ImmutableList.of(update1));
// 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.StorageRequest 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);
Update update1 = mock(Update.class);
when(update1.getOldMetacard()).thenReturn(metacards.get(0));
when(updateResponse.getUpdatedMetacards()).thenReturn(ImmutableList.of(update1));
// 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));
}
Aggregations