Search in sources :

Example 11 with SourcePoller

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));
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) CachedSource(ddf.catalog.util.impl.CachedSource) FederatedSource(ddf.catalog.source.FederatedSource) SourcePoller(ddf.catalog.util.impl.SourcePoller) Result(ddf.catalog.data.Result) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) HashSet(java.util.HashSet) QueryRequest(ddf.catalog.operation.QueryRequest) FederationStrategy(ddf.catalog.federation.FederationStrategy) SourceMonitor(ddf.catalog.source.SourceMonitor) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 12 with SourcePoller

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));
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) ContentType(ddf.catalog.data.ContentType) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) Date(java.util.Date) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) CachedSource(ddf.catalog.util.impl.CachedSource) FederatedSource(ddf.catalog.source.FederatedSource) SourcePoller(ddf.catalog.util.impl.SourcePoller) FederatedSource(ddf.catalog.source.FederatedSource) CatalogProvider(ddf.catalog.source.CatalogProvider) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with SourcePoller

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);
}
Also used : OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) ContentType(ddf.catalog.data.ContentType) ArrayList(java.util.ArrayList) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) CachedSource(ddf.catalog.util.impl.CachedSource) Source(ddf.catalog.source.Source) SourcePoller(ddf.catalog.util.impl.SourcePoller) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Historian(ddf.catalog.history.Historian) DefaultAttributeValueRegistryImpl(ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl) SourceOperations(ddf.catalog.impl.operations.SourceOperations) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) CachedSource(ddf.catalog.util.impl.CachedSource) TransformOperations(ddf.catalog.impl.operations.TransformOperations) Date(java.util.Date) QueryOperations(ddf.catalog.impl.operations.QueryOperations) UpdateOperations(ddf.catalog.impl.operations.UpdateOperations) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) CreateOperations(ddf.catalog.impl.operations.CreateOperations) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) Before(org.junit.Before)

Example 14 with SourcePoller

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);
}
Also used : UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) SourcePollerRunner(ddf.catalog.util.impl.SourcePollerRunner) ArrayList(java.util.ArrayList) SourcePoller(ddf.catalog.util.impl.SourcePoller) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) Before(org.junit.Before)

Aggregations

SourcePoller (ddf.catalog.util.impl.SourcePoller)14 FederatedSource (ddf.catalog.source.FederatedSource)11 Source (ddf.catalog.source.Source)10 CachedSource (ddf.catalog.util.impl.CachedSource)10 ByteSource (com.google.common.io.ByteSource)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 QueryRequest (ddf.catalog.operation.QueryRequest)7 FederationStrategy (ddf.catalog.federation.FederationStrategy)6 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)6 CatalogProvider (ddf.catalog.source.CatalogProvider)6 Date (java.util.Date)6 Matchers.anyString (org.mockito.Matchers.anyString)6 Result (ddf.catalog.data.Result)5 SourcePollerRunner (ddf.catalog.util.impl.SourcePollerRunner)5 ContentType (ddf.catalog.data.ContentType)4 Metacard (ddf.catalog.data.Metacard)4 QueryOperations (ddf.catalog.impl.operations.QueryOperations)4 SourceOperations (ddf.catalog.impl.operations.SourceOperations)4 QueryResponse (ddf.catalog.operation.QueryResponse)4