Search in sources :

Example 16 with UpdateStorageRequest

use of ddf.catalog.content.operation.UpdateStorageRequest 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)));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) Test(org.junit.Test)

Example 17 with UpdateStorageRequest

use of ddf.catalog.content.operation.UpdateStorageRequest 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));
}
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) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 18 with UpdateStorageRequest

use of ddf.catalog.content.operation.UpdateStorageRequest 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));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Serializable(java.io.Serializable) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) HashMap(java.util.HashMap) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) Test(org.junit.Test)

Example 19 with UpdateStorageRequest

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

the class TestChecksum method testProcessUpdateWithValidInput.

@Test
public void testProcessUpdateWithValidInput() throws PluginExecutionException {
    UpdateStorageRequest request = checksum.process(mockUpdateRequest);
    String checksumResult = (String) request.getContentItems().get(0).getMetacard().getAttribute(Metacard.CHECKSUM).getValue();
    String checksumAlgorithm = (String) request.getContentItems().get(0).getMetacard().getAttribute(Metacard.CHECKSUM_ALGORITHM).getValue();
    assertThat(checksumResult, is(SAMPLE_CHECKSUM_VALUE));
    assertThat(checksumAlgorithm, is(SAMPLE_CHECKSUM_ALGORITHM));
}
Also used : UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) Test(org.junit.Test)

Example 20 with UpdateStorageRequest

use of ddf.catalog.content.operation.UpdateStorageRequest 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

UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)20 Metacard (ddf.catalog.data.Metacard)16 Test (org.junit.Test)14 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)13 UpdateResponse (ddf.catalog.operation.UpdateResponse)13 ContentItem (ddf.catalog.content.data.ContentItem)10 UpdateStorageRequestImpl (ddf.catalog.content.operation.impl.UpdateStorageRequestImpl)9 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)8 StorageProvider (ddf.catalog.content.StorageProvider)6 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)6 IngestException (ddf.catalog.source.IngestException)6 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)6 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)5 CreateResponse (ddf.catalog.operation.CreateResponse)5 HashMap (java.util.HashMap)5 ByteSource (com.google.common.io.ByteSource)4 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)4 ReadStorageRequest (ddf.catalog.content.operation.ReadStorageRequest)4 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)4 ReadStorageResponse (ddf.catalog.content.operation.ReadStorageResponse)3