Search in sources :

Example 6 with FederatedSource

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

the class CatalogFrameworkImplTest method testDeleteWithStores.

// TODO (DDF-2436) -
@Ignore
@Test
public void testDeleteWithStores() throws Exception {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
    List<CatalogStore> storeList = new ArrayList<>();
    List<FederatedSource> sourceList = new ArrayList<>();
    MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
    storeList.add(store);
    sourceList.add(store);
    CatalogFramework framework = createDummyCatalogFramework(provider, storeList, sourceList, eventAdmin);
    FilterFactory filterFactory = new FilterFactoryImpl();
    Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "*", "*", "?", "/", false);
    List<Metacard> metacards = new ArrayList<>();
    String id = UUID.randomUUID().toString().replaceAll("-", "");
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(id);
    newCard.setAttribute("myKey", "myValue1");
    metacards.add(newCard);
    Map<String, Serializable> reqProps = new HashMap<>();
    HashSet<String> destinations = new HashSet<>();
    destinations.add("mockMemoryProvider");
    destinations.add("catalogStoreId-1");
    framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
    DeleteRequest deleteRequest = new DeleteRequestImpl(Collections.singletonList(id), Metacard.ID, new HashMap<>(), destinations);
    DeleteResponse response = framework.delete(deleteRequest);
    assertThat(response.getDeletedMetacards().size(), is(1));
    QueryResponse queryResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), true));
    assertThat(queryResponse.getResults().size(), is(0));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FilterFactory(org.opengis.filter.FilterFactory) CatalogStore(ddf.catalog.source.CatalogStore) QueryImpl(ddf.catalog.operation.impl.QueryImpl) CatalogFramework(ddf.catalog.CatalogFramework) HashSet(java.util.HashSet) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) Filter(org.opengis.filter.Filter) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with FederatedSource

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

the class CatalogFrameworkImplTest method testFederatedQueryPermissionsNoSubject.

@Test(expected = FederationException.class)
public void testFederatedQueryPermissionsNoSubject() throws Exception {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
    List<CatalogStore> storeList = new ArrayList<>();
    List<FederatedSource> sourceList = new ArrayList<>();
    Map<String, Set<String>> securityAttributes = new HashMap<>();
    securityAttributes.put("role", Collections.singleton("myRole"));
    MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true, securityAttributes);
    storeList.add(store);
    sourceList.add(store);
    CatalogFramework framework = createDummyCatalogFramework(provider, storeList, sourceList, eventAdmin);
    FilterBuilder builder = new GeotoolsFilterBuilder();
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().like().text("someType"));
    QueryRequestImpl request = new QueryRequestImpl(query, Collections.singletonList("catalogStoreId-1"));
    framework.query(request);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) CatalogStore(ddf.catalog.source.CatalogStore) FederatedSource(ddf.catalog.source.FederatedSource) QueryImpl(ddf.catalog.operation.impl.QueryImpl) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CatalogFramework(ddf.catalog.CatalogFramework) Test(org.junit.Test)

Example 8 with FederatedSource

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

the class CatalogFrameworkImplTest method testGetSites.

@Test
public void testGetSites() {
    framework.setId("ddf");
    framework.getSourceOperations().setId("ddf");
    Set<String> ids = new HashSet<String>();
    for (FederatedSource source : federatedSources) {
        ids.add(source.getId());
    }
    ids.add(framework.getId());
    SourceInfoRequest request = new SourceInfoRequestSources(true, ids);
    SourceInfoResponse response = null;
    try {
        response = framework.getSourceInfo(request);
    } catch (SourceUnavailableException e) {
        fail();
    }
    Set<SourceDescriptor> sourceDescriptors = response.getSourceInfo();
    List<String> siteNames = new ArrayList<String>();
    for (SourceDescriptor descriptor : sourceDescriptors) {
        LOGGER.debug("Descriptor id: {}", descriptor.getSourceId());
        siteNames.add(descriptor.getSourceId());
    }
    // add a plus one for now to simulate that the framework is ad
    // assertTrue( sourceDescriptor.containsAll( federatedSources ) );
    // assertTrue( sourceDescriptor.containsAll( expectedSourceSet ) );
    assertEquals(ids.size(), sourceDescriptors.size());
    String[] expectedOrdering = { "A", "B", "C", framework.getId() };
    assertArrayEquals(expectedOrdering, siteNames.toArray(new String[siteNames.size()]));
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceDescriptor(ddf.catalog.source.SourceDescriptor) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FederatedSource(ddf.catalog.source.FederatedSource) SourceInfoRequestSources(ddf.catalog.operation.impl.SourceInfoRequestSources) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with FederatedSource

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

the class FanoutCatalogFrameworkTest method testNullContentTypesInGetSourceInfo.

/**
 * This test is to verify that an NPE will not be thrown if {@code source.getContentTypes} returns
 * null.
 *
 * @throws SourceUnavailableException
 */
@Test
public void testNullContentTypesInGetSourceInfo() throws SourceUnavailableException {
    ArrayList<PostIngestPlugin> postIngestPlugins = new ArrayList<PostIngestPlugin>();
    SourceInfoRequest request = new SourceInfoRequestEnterprise(true);
    List<FederatedSource> fedSources = new ArrayList<FederatedSource>();
    FederatedSource mockFederatedSource = mock(FederatedSource.class);
    when(mockFederatedSource.isAvailable()).thenReturn(true);
    when(mockFederatedSource.getContentTypes()).thenReturn(Collections.emptySet());
    fedSources.add(mockFederatedSource);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setFederationStrategy(new MockFederationStrategy());
    frameworkProperties.setPostIngest(postIngestPlugins);
    List<FederatedSource> sourceList = new ArrayList<>(fedSources);
    frameworkProperties.setFederatedSources(sourceList);
    CatalogFrameworkImpl framework = createCatalogFramework(frameworkProperties);
    // Assert not null simply to prove that we returned an object.
    assertNotNull(framework.getSourceInfo(request));
}
Also used : FederatedSource(ddf.catalog.source.FederatedSource) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) ArrayList(java.util.ArrayList) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) Test(org.junit.Test)

Example 10 with FederatedSource

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

the class CatalogFrameworkImplTest method createDummyCatalogFramework.

private CatalogFramework createDummyCatalogFramework(CatalogProvider provider, Map<String, CatalogStore> stores, Map<String, FederatedSource> sources, MockEventProcessor eventAdmin) {
    SourcePoller mockPoller = mock(SourcePoller.class);
    when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
    FederationStrategy federationStrategy = new FederationStrategy() {

        @Override
        public QueryResponse federate(List<Source> sources, QueryRequest query) throws FederationException {
            List<Result> results = new ArrayList<>();
            for (Source source : sources) {
                try {
                    SourceResponse response = source.query(query);
                    results.addAll(response.getResults());
                } catch (UnsupportedQueryException e) {
                }
            }
            return new QueryResponseImpl(query, results, results.size());
        }
    };
    ArrayList<PostIngestPlugin> postIngestPlugins = new ArrayList<>();
    postIngestPlugins.add(eventAdmin);
    FrameworkProperties frameworkProperties = new FrameworkProperties();
    frameworkProperties.setCatalogProviders(Collections.singletonList(provider));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setCatalogStoresMap(stores);
    frameworkProperties.setSourcePoller(mockPoller);
    frameworkProperties.setPreIngest(new ArrayList<>());
    frameworkProperties.setPostIngest(postIngestPlugins);
    frameworkProperties.setPreQuery(new ArrayList<>());
    frameworkProperties.setPostQuery(new ArrayList<>());
    frameworkProperties.setPolicyPlugins(new ArrayList<>());
    frameworkProperties.setAccessPlugins(new ArrayList<>());
    frameworkProperties.setFederatedSources(sources);
    frameworkProperties.setConnectedSources(new ArrayList<>());
    frameworkProperties.setFederationStrategy(federationStrategy);
    frameworkProperties.setQueryResponsePostProcessor(new QueryResponsePostProcessor(null, null));
    frameworkProperties.setFilterBuilder(new GeotoolsFilterBuilder());
    frameworkProperties.setValidationQueryFactory(new ValidationQueryFactory(new GeotoolsFilterAdapterImpl(), new GeotoolsFilterBuilder()));
    frameworkProperties.setDefaultAttributeValueRegistry(defaultAttributeValueRegistry);
    return createFramework(frameworkProperties);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) FederationStrategy(ddf.catalog.federation.FederationStrategy) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) ValidationQueryFactory(ddf.catalog.cache.solr.impl.ValidationQueryFactory) 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) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)

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