Search in sources :

Example 16 with FederatedSource

use of ddf.catalog.source.FederatedSource in project ddf by codice.

the class CatalogFrameworkImplTest method setup.

@Before
public void setup() throws StopProcessingException, PluginExecutionException, URISyntaxException, FederationException, IOException, CatalogTransformerException, InterruptedException {
    System.setProperty("bad.files", "crossdomain.xml,clientaccesspolicy.xml,.htaccess,.htpasswd,hosts,passwd,group,resolv.conf,nfs.conf,ftpd.conf,ntp.conf,web.config,robots.txt");
    System.setProperty("bad.file.extensions", ".exe,.jsp,.html,.js,.php,.phtml,.php3,.php4,.php5,.phps,.shtml,.jhtml,.pl,.py,.cgi,.msi,.com,.scr,.gadget,.application,.pif,.hta,.cpl,.msc,.jar,.kar,.bat,.cmd,.vb,.vbs,.vbe,.jse,.ws,.wsf,.wsc,.wsh,.ps1,.ps1xml,.ps2,.ps2xml,.psc1,.psc2,.msh,.msh1,.msh2,.mshxml,.msh1xml,.msh2xml,.scf,.lnk,.inf,.reg,.dll,.vxd,.cpl,.cfg,.config,.crt,.cert,.pem,.jks,.p12,.p7b,.key,.der,.csr,.jsb,.mhtml,.mht,.xhtml,.xht");
    System.setProperty("bad.mime.types", "text/html,text/javascript,text/x-javascript,application/x-shellscript,text/scriptlet,application/x-msdownload,application/x-msmetafile");
    System.setProperty("ignore.files", ".DS_Store,Thumbs.db");
    // Setup
    /*
     * Prepare to capture the ResourceResponse argument passed into
     * PostResourcePlugin.process(). We will verify that it contains a non-null ResourceRequest
     * in the verification section of this test.
     */
    argument = ArgumentCaptor.forClass(ResourceResponse.class);
    Resource mockResource = mock(Resource.class);
    mockResourceRequest = mock(ResourceRequest.class);
    when(mockResourceRequest.getAttributeValue()).thenReturn(new URI("myURI"));
    when(mockResourceRequest.getAttributeName()).thenReturn(new String("myName"));
    mockResourceResponse = mock(ResourceResponse.class);
    when(mockResourceResponse.getRequest()).thenReturn(mockResourceRequest);
    when(mockResourceResponse.getResource()).thenReturn(mockResource);
    mockPostResourcePlugin = mock(PostResourcePlugin.class);
    /*
     * We verify (see verification section of test) that PostResourcePlugin.process() receives a
     * ResourceResponse with a non-null ResourceRequest. We assume that it works correctly and
     * returns a ResourceResponse with a non-null ResourceRequest, so we return our
     * mockResouceResponse that contains a non-null ResourceRequest.
     */
    when(mockPostResourcePlugin.process(isA(ResourceResponse.class))).thenReturn(mockResourceResponse);
    List<PostResourcePlugin> mockPostResourcePlugins = new ArrayList<PostResourcePlugin>();
    mockPostResourcePlugins.add(mockPostResourcePlugin);
    eventAdmin = new MockEventProcessor();
    provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
    storageProvider = new MockMemoryStorageProvider();
    ArrayList<PostIngestPlugin> postIngestPlugins = new ArrayList<PostIngestPlugin>();
    postIngestPlugins.add(eventAdmin);
    mockFederationStrategy = mock(FederationStrategy.class);
    Result mockFederationResult = mock(Result.class);
    when(mockFederationResult.getMetacard()).thenReturn(new MetacardImpl());
    QueryRequest mockQueryRequest = mock(QueryRequest.class);
    Query mockQuery = mock(Query.class);
    when(mockQuery.getTimeoutMillis()).thenReturn(1L);
    when(mockQueryRequest.getQuery()).thenReturn(mockQuery);
    QueryResponseImpl queryResponse = new QueryResponseImpl(mockQueryRequest, Collections.singletonList(mockFederationResult), 1);
    when(mockFederationStrategy.federate(anyList(), any())).thenReturn(queryResponse);
    federatedSources = createDefaultFederatedSourceList(true);
    MimeTypeResolver mimeTypeResolver = mock(MimeTypeResolver.class);
    MimeTypeToTransformerMapper mimeTypeToTransformerMapper = mock(MimeTypeToTransformerMapper.class);
    InputTransformer inputTransformer = mock(InputTransformer.class);
    when(inputTransformer.transform(any(InputStream.class))).thenReturn(new MetacardImpl());
    when(mimeTypeToTransformerMapper.findMatches(any(Class.class), any(MimeType.class))).thenReturn(Collections.singletonList(inputTransformer));
    mockRemoteDeleteOperations = mock(RemoteDeleteOperations.class);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setAccessPlugins(new ArrayList<>());
    frameworkProperties.setPolicyPlugins(new ArrayList<>());
    frameworkProperties.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
    frameworkProperties.setPostResource(mockPostResourcePlugins);
    frameworkProperties.setFederationStrategy(mockFederationStrategy);
    frameworkProperties.setFilterBuilder(new GeotoolsFilterBuilder());
    frameworkProperties.setPreIngest(new ArrayList<>());
    frameworkProperties.setPostIngest(postIngestPlugins);
    frameworkProperties.setPreQuery(new ArrayList<>());
    frameworkProperties.setPostQuery(new ArrayList<>());
    frameworkProperties.setPreResource(new ArrayList<>());
    frameworkProperties.setPostResource(new ArrayList<>());
    frameworkProperties.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setMimeTypeMapper(new MimeTypeMapperImpl(Collections.singletonList(mimeTypeResolver)));
    frameworkProperties.setMimeTypeToTransformerMapper(mimeTypeToTransformerMapper);
    List<FederatedSource> federatedSourceList = new ArrayList<>();
    if (federatedSources != null) {
        for (FederatedSource source : federatedSources) {
            federatedSourceList.add(source);
        }
    }
    frameworkProperties.setFederatedSources(federatedSourceList);
    defaultAttributeValueRegistry = new DefaultAttributeValueRegistryImpl();
    frameworkProperties.setDefaultAttributeValueRegistry(defaultAttributeValueRegistry);
    attributeInjector = spy(new AttributeInjectorImpl(new AttributeRegistryImpl()));
    frameworkProperties.setAttributeInjectors(Collections.singletonList(attributeInjector));
    uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    sourceActionRegistry = mock(ActionRegistry.class);
    when(sourceActionRegistry.list(any())).thenReturn(Collections.emptyList());
    final SourcePoller<SourceStatus> mockStatusSourcePoller = mock(SourcePoller.class);
    doAnswer(invocationOnMock -> Optional.of(((Source) invocationOnMock.getArguments()[0]).isAvailable() ? SourceStatus.AVAILABLE : SourceStatus.UNAVAILABLE)).when(mockStatusSourcePoller).getCachedValueForSource(any(Source.class));
    final SourcePoller<Set<ContentType>> mockContentTypesSourcePoller = mock(SourcePoller.class);
    doAnswer(invocationOnMock -> Optional.of(((Source) invocationOnMock.getArguments()[0]).getContentTypes())).when(mockContentTypesSourcePoller).getCachedValueForSource(any(Source.class));
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(mimeTypeToTransformerMapper, uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
    SourceOperations sourceOperations = new SourceOperations(frameworkProperties, sourceActionRegistry, mockStatusSourcePoller, mockContentTypesSourcePoller);
    TransformOperations transformOperations = new TransformOperations(frameworkProperties);
    Historian historian = new Historian();
    historian.setHistoryEnabled(false);
    QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
    queryOperations.setSecurityLogger(mock(SecurityLogger.class));
    queryOperations.setPermissions(new PermissionsImpl());
    OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
    CreateOperations createOperations = new CreateOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
    UpdateOperations updateOperations = new UpdateOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
    deleteOperations = new DeleteOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, opsMetacard);
    ResourceOperations resOps = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity) {

        @Override
        protected ResourceInfo getResourceInfo(ResourceRequest resourceRequest, String site, boolean isEnterprise, StringBuilder federatedSite, Map<String, Serializable> requestProperties, boolean fanoutEnabled) throws ResourceNotSupportedException, ResourceNotFoundException {
            URI uri = null;
            Metacard metacard = new MetacardImpl();
            try {
                uri = new URI("myURI");
            } catch (URISyntaxException e) {
            }
            return new ResourceInfo(metacard, uri);
        }
    };
    updateOperations.setHistorian(historian);
    deleteOperations.setHistorian(historian);
    framework = new CatalogFrameworkImpl(createOperations, updateOperations, deleteOperations, queryOperations, resOps, sourceOperations, transformOperations);
    // Conditionally bind objects if framework properties are setup
    if (!CollectionUtils.isEmpty(frameworkProperties.getCatalogProviders())) {
        sourceOperations.bind(provider);
    }
    sourceOperations.bind(storageProvider);
    resourceFramework = new CatalogFrameworkImpl(createOperations, updateOperations, deleteOperations, queryOperations, resOps, sourceOperations, transformOperations);
    // Conditionally bind objects if framework properties are setup
    if (!CollectionUtils.isEmpty(frameworkProperties.getCatalogProviders())) {
        sourceOperations.bind(provider);
    }
    sourceOperations.bind(storageProvider);
    ThreadContext.bind(mock(Subject.class));
}
Also used : OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) Query(ddf.catalog.operation.Query) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InputTransformer(ddf.catalog.transform.InputTransformer) ActionRegistry(ddf.action.ActionRegistry) RemoteDeleteOperations(ddf.catalog.impl.operations.RemoteDeleteOperations) Result(ddf.catalog.data.Result) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) HashSet(java.util.HashSet) DefaultAttributeValueRegistryImpl(ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl) SourceOperations(ddf.catalog.impl.operations.SourceOperations) FederationStrategy(ddf.catalog.federation.FederationStrategy) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) Resource(ddf.catalog.resource.Resource) MimeTypeMapperImpl(ddf.mime.mapper.MimeTypeMapperImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) ResourceResponse(ddf.catalog.operation.ResourceResponse) UpdateOperations(ddf.catalog.impl.operations.UpdateOperations) ResourceRequest(ddf.catalog.operation.ResourceRequest) Map(java.util.Map) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) PostResourcePlugin(ddf.catalog.plugin.PostResourcePlugin) Set(java.util.Set) HashSet(java.util.HashSet) AttributeRegistryImpl(ddf.catalog.data.impl.AttributeRegistryImpl) RemoteDeleteOperations(ddf.catalog.impl.operations.RemoteDeleteOperations) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MimeType(javax.activation.MimeType) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) FederatedSource(ddf.catalog.source.FederatedSource) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) MimeTypeResolver(ddf.mime.MimeTypeResolver) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Historian(ddf.catalog.history.Historian) QueryRequest(ddf.catalog.operation.QueryRequest) SourceStatus(org.codice.ddf.catalog.sourcepoller.SourceStatus) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TransformOperations(ddf.catalog.impl.operations.TransformOperations) Date(java.util.Date) Subject(ddf.security.Subject) AttributeInjectorImpl(ddf.catalog.data.inject.AttributeInjectorImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) 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) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 17 with FederatedSource

use of ddf.catalog.source.FederatedSource 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());
    }
    expectedNameSet.add(frameworkName);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setFederatedSources(federatedSources);
    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("SourceUnavailable", e);
        fail();
    }
    assert (response != null);
    Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
    // should contain the original federated sites and the framework
    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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) Date(java.util.Date) 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 18 with FederatedSource

use of ddf.catalog.source.FederatedSource in project ddf by codice.

the class CatalogFrameworkImplTest method testGetFederatedSourcesDuplicates.

@Test
public void testGetFederatedSourcesDuplicates() {
    List<FederatedSource> federatedSources = createDefaultFederatedSourceList(true);
    // Duplicate Site
    FederatedSource siteC2 = new MockSource("C", "Site C2", "v1.0", "DDF", null, true, new Date());
    federatedSources.add(siteC2);
    // Expected Sites
    List<FederatedSource> expectedSources = createDefaultFederatedSourceList(true);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setFederatedSources(federatedSources);
    CatalogFrameworkImpl framework = createFramework(frameworkProperties);
    // Returned Sites
    SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
    SourceInfoResponse response = null;
    try {
        response = framework.getSourceInfo(request);
    } catch (SourceUnavailableException e) {
        LOGGER.debug("SourceUnavailable", e);
        fail();
    }
    Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
    // should contain ONLY the original federated sites and the catalog framework's
    // site info (even though it has no local catalog provider configured) - hence,
    // the "+1"
    assertEquals(expectedSources.size(), sourceDescriptors.size());
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) FederatedSource(ddf.catalog.source.FederatedSource) SourceDescriptor(ddf.catalog.source.SourceDescriptor) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Date(java.util.Date) Test(org.junit.Test)

Example 19 with FederatedSource

use of ddf.catalog.source.FederatedSource in project ddf by codice.

the class CatalogFrameworkImplTest method testGetUnavailableFederatedSources.

@Test
public void testGetUnavailableFederatedSources() {
    List<FederatedSource> federatedSources = createDefaultFederatedSourceList(false);
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setFederatedSources(federatedSources);
    frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
    CatalogFrameworkImpl framework = createFramework(frameworkProperties);
    SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
    SourceInfoResponse response = null;
    try {
        response = framework.getSourceInfo(request);
    } catch (SourceUnavailableException e) {
        fail();
    }
    Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
    for (SourceDescriptor descriptor : sourceDescriptors) {
        LOGGER.debug("Descriptor id: {}", descriptor.getSourceId());
        if (StringUtils.isNotBlank(descriptor.getId())) {
            assertFalse(descriptor.isAvailable());
            // No contentTypes should be listed if the source is unavailable
            assertTrue(descriptor.getContentTypes().isEmpty());
        }
    }
    // The "+1" is to account for the CatalogFramework source descriptor.
    // Even if no local catalog provider is configured, the catalog
    // framework's
    // site info is included in the SourceDescriptos list.
    assertEquals(federatedSources.size() + 1, sourceDescriptors.size());
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) FederatedSource(ddf.catalog.source.FederatedSource) SourceDescriptor(ddf.catalog.source.SourceDescriptor) CatalogProvider(ddf.catalog.source.CatalogProvider) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Test(org.junit.Test)

Example 20 with FederatedSource

use of ddf.catalog.source.FederatedSource 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);
    MetacardImpl metacard = new MetacardImpl();
    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.singletonList(federatedSource1));
    props.setResourceReaders(resourceReaders);
    props.setFederationStrategy(strategy);
    props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) URI(java.net.URI) 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)

Aggregations

FederatedSource (ddf.catalog.source.FederatedSource)21 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 HashSet (java.util.HashSet)10 Date (java.util.Date)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)7 HashMap (java.util.HashMap)7 CatalogFramework (ddf.catalog.CatalogFramework)6 Metacard (ddf.catalog.data.Metacard)6 SourceInfoRequest (ddf.catalog.operation.SourceInfoRequest)6 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)6 QueryImpl (ddf.catalog.operation.impl.QueryImpl)6 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)6 CatalogProvider (ddf.catalog.source.CatalogProvider)6 List (java.util.List)6 Set (java.util.Set)6 Result (ddf.catalog.data.Result)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)5 QueryRequest (ddf.catalog.operation.QueryRequest)5