Search in sources :

Example 1 with StorageProvider

use of ddf.catalog.content.StorageProvider in project ddf by codice.

the class HistorianTest method testReadStorageException.

@Test
public void testReadStorageException() throws StorageException, SourceUnavailableException, IngestException, UnsupportedQueryException, URISyntaxException {
    StorageProvider exceptionStorageProvider = mock(StorageProvider.class);
    when(exceptionStorageProvider.read(any())).thenThrow(StorageException.class);
    historian.setStorageProviders(Collections.singletonList(exceptionStorageProvider));
    Metacard metacard = getMetacardUpdatePair().get(0);
    // Parameters for historian
    UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
    UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
    UpdateResponse updateResponse = mock(UpdateResponse.class);
    // create the update request
    updateMetacard(storageRequest, storageResponse, metacard);
    mockQuery(metacard);
    historian.version(storageRequest, storageResponse, updateResponse);
    // Verify that it wasn't updated
    verify(catalogProvider, times(0)).create(anyObject());
}
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) StorageProvider(ddf.catalog.content.StorageProvider) Test(org.junit.Test)

Example 2 with StorageProvider

use of ddf.catalog.content.StorageProvider 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);
    // 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 3 with StorageProvider

use of ddf.catalog.content.StorageProvider 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 4 with StorageProvider

use of ddf.catalog.content.StorageProvider in project ddf by codice.

the class FanoutCatalogFrameworkTest method testBlacklistedTagCreateStorageRequestFails.

@Test(expected = IngestException.class)
public void testBlacklistedTagCreateStorageRequestFails() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    doReturn(true).when(catalogProvider).isAvailable();
    StorageProvider storageProvider = new MockMemoryStorageProvider();
    MimeTypeMapper mimeTypeMapper = mock(MimeTypeMapper.class);
    doReturn("extension").when(mimeTypeMapper).getFileExtensionForMimeType(anyString());
    InputTransformer transformer = mock(InputTransformer.class);
    doReturn(metacard).when(transformer).transform(any(InputStream.class));
    MimeTypeToTransformerMapper mimeTypeToTransformerMapper = mock(MimeTypeToTransformerMapper.class);
    doReturn(Collections.singletonList(transformer)).when(mimeTypeToTransformerMapper).findMatches(any(Class.class), any(MimeType.class));
    frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setMimeTypeMapper(mimeTypeMapper);
    frameworkProperties.setMimeTypeToTransformerMapper(mimeTypeToTransformerMapper);
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(frameworkProperties.getMimeTypeToTransformerMapper(), uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
    SourceOperations sourceOperations = new SourceOperations(frameworkProperties);
    sourceOperations.bind(catalogProvider);
    sourceOperations.bind(storageProvider);
    TransformOperations transformOperations = new TransformOperations(frameworkProperties);
    QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
    OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
    ResourceOperations resourceOperations = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity);
    OperationsMetacardSupport opsMetacardSupport = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
    // Need to set these for InputValidation to work
    System.setProperty("bad.files", "none");
    System.setProperty("bad.file.extensions", "none");
    System.setProperty("bad.mime.types", "none");
    CreateOperations createOperations = new CreateOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, opsMetacardSupport, opsCatStore, opsStorage);
    framework = new CatalogFrameworkImpl(createOperations, null, null, queryOperations, resourceOperations, sourceOperations, transformOperations);
    framework.setId(NEW_SOURCE_ID);
    framework.setFanoutEnabled(true);
    framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
    ContentItem item = new ContentItemImpl(uuidGenerator.generateUuid(), ByteSource.empty(), "text/xml", "filename.xml", 0L, metacard);
    CreateStorageRequest request = new CreateStorageRequestImpl(Collections.singletonList(item), new HashMap<>());
    framework.create(request);
}
Also used : MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) MimeTypeMapper(ddf.mime.MimeTypeMapper) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) InputTransformer(ddf.catalog.transform.InputTransformer) MimeType(javax.activation.MimeType) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) SourceOperations(ddf.catalog.impl.operations.SourceOperations) InputStream(java.io.InputStream) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) StorageProvider(ddf.catalog.content.StorageProvider) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) TransformOperations(ddf.catalog.impl.operations.TransformOperations) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryOperations(ddf.catalog.impl.operations.QueryOperations) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) CreateOperations(ddf.catalog.impl.operations.CreateOperations) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Example 5 with StorageProvider

use of ddf.catalog.content.StorageProvider in project ddf by codice.

the class FanoutCatalogFrameworkTest method testBlacklistedTagDeleteRequestFails.

@Test(expected = IngestException.class)
public void testBlacklistedTagDeleteRequestFails() throws Exception {
    Metacard metacard = new MetacardImpl();
    metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    doReturn(true).when(catalogProvider).isAvailable();
    StorageProvider storageProvider = new MockMemoryStorageProvider();
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    FilterAdapter filterAdapter = mock(FilterAdapter.class);
    ValidationQueryFactory validationQueryFactory = new ValidationQueryFactory(filterAdapter, filterBuilder);
    QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class));
    ResultImpl result = new ResultImpl(metacard);
    List<Result> results = new ArrayList<>();
    results.add(result);
    QueryResponseImpl queryResponse = new QueryResponseImpl(queryRequest, results, 1);
    FederationStrategy strategy = mock(FederationStrategy.class);
    when(strategy.federate(anyList(), any())).thenReturn(queryResponse);
    QueryResponsePostProcessor queryResponsePostProcessor = mock(QueryResponsePostProcessor.class);
    doNothing().when(queryResponsePostProcessor).processResponse(any());
    frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setFilterBuilder(filterBuilder);
    frameworkProperties.setValidationQueryFactory(validationQueryFactory);
    frameworkProperties.setFederationStrategy(strategy);
    frameworkProperties.setQueryResponsePostProcessor(queryResponsePostProcessor);
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(frameworkProperties.getMimeTypeToTransformerMapper(), uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
    SourceOperations sourceOperations = new SourceOperations(frameworkProperties);
    sourceOperations.bind(catalogProvider);
    sourceOperations.bind(storageProvider);
    TransformOperations transformOperations = new TransformOperations(frameworkProperties);
    QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
    ResourceOperations resourceOperations = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity);
    DeleteOperations deleteOperations = new DeleteOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, null);
    deleteOperations.setOpsCatStoreSupport(opsCatStore);
    framework = new CatalogFrameworkImpl(null, null, deleteOperations, queryOperations, resourceOperations, sourceOperations, transformOperations);
    framework.setId(NEW_SOURCE_ID);
    framework.setFanoutEnabled(true);
    framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
    DeleteRequest request = new DeleteRequestImpl(metacard.getId());
    framework.delete(request);
}
Also used : OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) Query(ddf.catalog.operation.Query) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) ArrayList(java.util.ArrayList) FilterAdapter(ddf.catalog.filter.FilterAdapter) ResultImpl(ddf.catalog.data.impl.ResultImpl) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) Result(ddf.catalog.data.Result) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) SourceOperations(ddf.catalog.impl.operations.SourceOperations) FederationStrategy(ddf.catalog.federation.FederationStrategy) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ValidationQueryFactory(ddf.catalog.cache.solr.impl.ValidationQueryFactory) StorageProvider(ddf.catalog.content.StorageProvider) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) TransformOperations(ddf.catalog.impl.operations.TransformOperations) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryOperations(ddf.catalog.impl.operations.QueryOperations) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Aggregations

StorageProvider (ddf.catalog.content.StorageProvider)5 Metacard (ddf.catalog.data.Metacard)5 Test (org.junit.Test)5 ContentItem (ddf.catalog.content.data.ContentItem)3 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)3 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)3 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)3 UpdateResponse (ddf.catalog.operation.UpdateResponse)3 MockMemoryStorageProvider (ddf.catalog.content.impl.MockMemoryStorageProvider)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 StorageRequest (ddf.catalog.content.operation.StorageRequest)2 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 MetacardFactory (ddf.catalog.impl.operations.MetacardFactory)2 OperationsCatalogStoreSupport (ddf.catalog.impl.operations.OperationsCatalogStoreSupport)2 OperationsMetacardSupport (ddf.catalog.impl.operations.OperationsMetacardSupport)2 OperationsSecuritySupport (ddf.catalog.impl.operations.OperationsSecuritySupport)2