use of ddf.catalog.impl.operations.SourceOperations in project ddf by codice.
the class CatalogFrameworkQueryTest method initFramework.
@Before
public void initFramework() {
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
// Mock register the provider in the container
// Mock the source poller
SourcePoller mockPoller = mock(SourcePoller.class);
CachedSource source = mock(CachedSource.class);
when(source.isAvailable()).thenReturn(Boolean.TRUE);
when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(source);
ArrayList<PostIngestPlugin> postIngestPlugins = new ArrayList<>();
FrameworkProperties props = new FrameworkProperties();
props.setCatalogProviders(Collections.singletonList(provider));
props.setPostIngest(postIngestPlugins);
props.setFederationStrategy(new MockFederationStrategy());
props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
props.setSourcePoller(mockPoller);
props.setFilterBuilder(new GeotoolsFilterBuilder());
props.setDefaultAttributeValueRegistry(new DefaultAttributeValueRegistryImpl());
UuidGenerator uuidGenerator = mock(UuidGenerator.class);
when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
MetacardFactory metacardFactory = new MetacardFactory(props.getMimeTypeToTransformerMapper(), uuidGenerator);
OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(props, metacardFactory);
SourceOperations sourceOperations = new SourceOperations(props);
QueryOperations queryOperations = new QueryOperations(props, sourceOperations, opsSecurity, opsMetacard);
ResourceOperations resourceOperations = new ResourceOperations(props, queryOperations, opsSecurity);
TransformOperations transformOperations = new TransformOperations(props);
OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(props, sourceOperations);
OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
CreateOperations createOperations = new CreateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
UpdateOperations updateOperations = new UpdateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
DeleteOperations deleteOperations = new DeleteOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard);
Historian historian = new Historian();
historian.setHistoryEnabled(false);
opsStorage.setHistorian(historian);
updateOperations.setHistorian(historian);
deleteOperations.setHistorian(historian);
deleteOperations.setOpsCatStoreSupport(opsCatStore);
framework = new CatalogFrameworkImpl(createOperations, updateOperations, deleteOperations, queryOperations, resourceOperations, sourceOperations, transformOperations);
sourceOperations.bind(provider);
}
use of ddf.catalog.impl.operations.SourceOperations 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);
}
use of ddf.catalog.impl.operations.SourceOperations 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);
}
Aggregations