use of ddf.catalog.util.impl.SourcePoller in project ddf by codice.
the class CatalogFrameworkImplTest method testGetResourceOptions.
/**
* Tests that you can get a resource's (product) options. Covers the case where the source ID
* specified is actually the local catalog provider's site name (so this reduces down to a
* getResourceOptions for local provider); and the case where a federated source is specified.
* <p>
* Test for DDF-1763.
*
* @throws Exception
*/
@Test
public void testGetResourceOptions() throws Exception {
String localProviderName = "ddf";
String federatedSite1Name = "fed-site-1";
String metacardId = "123";
// The resource's URI
URI metacardUri = new URI("http:///27+Nov+12+12%3A30%3A04?MyPhotograph%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc%2Fimages%2FActionable.jpg%0AMyAttachment%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc#abc.xyz.dao.URLResourceOptionDataAccessObject");
Set<String> supportedOptions = new HashSet<String>();
supportedOptions.add("MyPhotograph");
supportedOptions.add("MyAttachment");
// Catalog Provider
CatalogProvider provider = mock(CatalogProvider.class);
when(provider.getId()).thenReturn(localProviderName);
when(provider.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
when(provider.isAvailable()).thenReturn(true);
// Federated Source 1
FederatedSource federatedSource1 = mock(FederatedSource.class);
when(federatedSource1.getId()).thenReturn(federatedSite1Name);
when(federatedSource1.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
when(federatedSource1.isAvailable()).thenReturn(true);
when(federatedSource1.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
List<FederatedSource> federatedSources = new ArrayList<FederatedSource>();
federatedSources.add(federatedSource1);
// Mock register the provider in the container
// Mock the source poller
SourcePoller mockPoller = mock(SourcePoller.class);
when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
MetacardImpl metacard = new MetacardImpl(BASIC_METACARD);
metacard.setId(metacardId);
metacard.setResourceURI(metacardUri);
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<>();
results.add(result);
QueryResponse queryResponse = mock(QueryResponse.class);
when(queryResponse.getResults()).thenReturn(results);
FederationStrategy strategy = mock(FederationStrategy.class);
when(strategy.federate(isA(federatedSources.getClass()), isA(QueryRequest.class))).thenReturn(queryResponse);
ResourceReader resourceReader = mock(ResourceReader.class);
Set<String> supportedSchemes = new HashSet<String>();
supportedSchemes.add("http");
when(resourceReader.getSupportedSchemes()).thenReturn(supportedSchemes);
when(resourceReader.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
List<ResourceReader> resourceReaders = new ArrayList<ResourceReader>();
resourceReaders.add(resourceReader);
FrameworkProperties props = new FrameworkProperties();
props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
props.setFederatedSources(Collections.singletonMap(federatedSite1Name, federatedSource1));
props.setResourceReaders(resourceReaders);
props.setFederationStrategy(strategy);
props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
props.setSourcePoller(mockPoller);
props.setFilterBuilder(new GeotoolsFilterBuilder());
props.setDefaultAttributeValueRegistry(defaultAttributeValueRegistry);
CatalogFrameworkImpl framework = createFramework(props);
framework.setId("ddf");
Set<String> ids = new HashSet<String>();
for (FederatedSource source : federatedSources) {
ids.add(source.getId());
}
ids.add(framework.getId());
// site name = local provider
Map<String, Set<String>> optionsMap = framework.getResourceOptions(metacardId, localProviderName);
LOGGER.debug("localProvider optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
// site name = federated site's name
optionsMap = framework.getResourceOptions(metacardId, federatedSite1Name);
LOGGER.debug("federatedSource optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
// site name = null (should default to local provider)
optionsMap = framework.getResourceOptions(metacardId, null);
LOGGER.debug("localProvider optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
// site name = empty string (should default to local provider)
optionsMap = framework.getResourceOptions(metacardId, "");
LOGGER.debug("localProvider optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
}
use of ddf.catalog.util.impl.SourcePoller in project ddf by codice.
the class CatalogFrameworkImplTest method testGetAllSiteNames.
@Test
public void testGetAllSiteNames() {
String frameworkName = "DDF";
CatalogProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
List<FederatedSource> federatedSources = createDefaultFederatedSourceList(true);
// Expected Set of Names
Set<String> expectedNameSet = new HashSet<String>();
for (FederatedSource curSite : federatedSources) {
expectedNameSet.add(curSite.getId());
}
// Mock register the provider in the container
// Mock the source poller
SourcePoller mockPoller = mock(SourcePoller.class);
when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
FrameworkProperties frameworkProperties = new FrameworkProperties();
frameworkProperties.setSourcePoller(mockPoller);
Map<String, FederatedSource> sources = new HashMap<>();
for (FederatedSource federatedSource : federatedSources) {
sources.put(federatedSource.getId(), federatedSource);
}
frameworkProperties.setFederatedSources(sources);
frameworkProperties.setCatalogProviders(Collections.singletonList(provider));
CatalogFrameworkImpl framework = createFramework(frameworkProperties);
framework.setId(frameworkName);
// Returned Set of Names
// Returned Sites
SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
SourceInfoResponse response = null;
try {
response = framework.getSourceInfo(request);
} catch (SourceUnavailableException e) {
LOGGER.debug("SourceUnavilable", e);
fail();
}
assert (response != null);
Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
// should contain ONLY the original federated sites
assertEquals(expectedNameSet.size(), sourceDescriptors.size());
Set<String> returnedSourceIds = new HashSet<String>();
for (SourceDescriptor sd : sourceDescriptors) {
returnedSourceIds.add(sd.getSourceId());
}
for (String id : returnedSourceIds) {
LOGGER.debug("returned sourceId: {}", id);
}
assertTrue(expectedNameSet.equals(returnedSourceIds));
}
use of ddf.catalog.util.impl.SourcePoller 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.util.impl.SourcePoller in project ddf by codice.
the class FanoutCatalogFrameworkTest method initFramework.
@Before
public void initFramework() {
// Mock register the provider in the container
SourcePollerRunner runner = new SourcePollerRunner();
SourcePoller poller = new SourcePoller(runner);
ArrayList<PostIngestPlugin> postIngestPlugins = new ArrayList<PostIngestPlugin>();
frameworkProperties = new FrameworkProperties();
frameworkProperties.setSourcePoller(poller);
frameworkProperties.setFederationStrategy(new MockFederationStrategy());
frameworkProperties.setPostIngest(postIngestPlugins);
uuidGenerator = mock(UuidGenerator.class);
when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
framework = createCatalogFramework(frameworkProperties);
}
Aggregations