Search in sources :

Example 1 with StorageRequest

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));
}
Also used : Serializable(java.io.Serializable) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) StorageRequest(ddf.catalog.content.operation.StorageRequest) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Example 2 with StorageRequest

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));
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) StorageRequest(ddf.catalog.content.operation.StorageRequest) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) StorageProvider(ddf.catalog.content.StorageProvider) Update(ddf.catalog.operation.Update) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 3 with StorageRequest

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));
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) StorageRequest(ddf.catalog.content.operation.StorageRequest) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) StorageProvider(ddf.catalog.content.StorageProvider) Update(ddf.catalog.operation.Update) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Aggregations

StorageRequest (ddf.catalog.content.operation.StorageRequest)3 Test (org.junit.Test)3 StorageProvider (ddf.catalog.content.StorageProvider)2 ContentItem (ddf.catalog.content.data.ContentItem)2 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)2 DeleteStorageRequest (ddf.catalog.content.operation.DeleteStorageRequest)2 ReadStorageRequest (ddf.catalog.content.operation.ReadStorageRequest)2 ReadStorageResponse (ddf.catalog.content.operation.ReadStorageResponse)2 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)2 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)2 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)2 Metacard (ddf.catalog.data.Metacard)2 Update (ddf.catalog.operation.Update)2 UpdateResponse (ddf.catalog.operation.UpdateResponse)2 ImmutableList (com.google.common.collect.ImmutableList)1 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 List (java.util.List)1