Search in sources :

Example 11 with CatalogStore

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

the class CatalogFrameworkImplTest method testFederatedQueryPermissions.

@Test
public void testFederatedQueryPermissions() throws Exception {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
    Map<String, CatalogStore> storeMap = new HashMap<>();
    Map<String, FederatedSource> sourceMap = new HashMap<>();
    Map<String, Set<String>> securityAttributes = new HashMap<>();
    securityAttributes.put("role", Collections.singleton("myRole"));
    MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true, securityAttributes);
    storeMap.put(store.getId(), store);
    sourceMap.put(store.getId(), store);
    CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, sourceMap, eventAdmin);
    List<Metacard> metacards = new ArrayList<>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    newCard.setContentTypeName("someType");
    metacards.add(newCard);
    Map<String, Serializable> reqProps = new HashMap<>();
    HashSet<String> destinations = new HashSet<>();
    //==== test writing to store and not local ====
    destinations.add("catalogStoreId-1");
    framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Subject subject = mock(Subject.class);
    when(subject.isPermitted(any(KeyValueCollectionPermission.class))).thenReturn(true);
    HashMap<String, Serializable> properties = new HashMap<>();
    properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().like().text("someType"));
    QueryRequestImpl request = new QueryRequestImpl(query, false, Collections.singletonList("catalogStoreId-1"), properties);
    QueryResponse response = framework.query(request);
    assertThat(response.getResults().size(), is(1));
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) CatalogStore(ddf.catalog.source.CatalogStore) 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) CatalogFramework(ddf.catalog.CatalogFramework) HashSet(java.util.HashSet) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Subject(ddf.security.Subject) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Test(org.junit.Test)

Example 12 with CatalogStore

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

the class RemoteDeleteOperationsTest method testNonEmptyStoreAvailableExpectsCaughtIngestException.

@Test
public void testNonEmptyStoreAvailableExpectsCaughtIngestException() throws Exception {
    when(opsCatStoreSupport.isCatalogStoreRequest(deleteRequest)).thenReturn(true);
    remoteDeleteOperations.setOpsCatStoreSupport(opsCatStoreSupport);
    CatalogStore catalogStoreMock = mock(CatalogStore.class);
    ArrayList<CatalogStore> stores = new ArrayList<>();
    stores.add(catalogStoreMock);
    IngestException ingestException = new IngestException();
    when(opsCatStoreSupport.getCatalogStoresForRequest(any(), any())).thenReturn(stores);
    when(catalogStoreMock.isAvailable()).thenReturn(true);
    when(catalogStoreMock.delete(any())).thenThrow(ingestException);
    DeleteResponse resultDeleteResponse = remoteDeleteOperations.performRemoteDelete(deleteRequest, deleteResponse);
    assertThat("Assert caught IngestException", resultDeleteResponse.getProcessingErrors().size() >= 1);
    verify(opsCatStoreSupport).isCatalogStoreRequest(deleteRequest);
    verify(opsCatStoreSupport).getCatalogStoresForRequest(any(), any());
    verify(catalogStoreMock).isAvailable();
    verify(catalogStoreMock).delete(any());
}
Also used : CatalogStore(ddf.catalog.source.CatalogStore) DeleteResponse(ddf.catalog.operation.DeleteResponse) ArrayList(java.util.ArrayList) IngestException(ddf.catalog.source.IngestException) Test(org.junit.Test)

Aggregations

CatalogStore (ddf.catalog.source.CatalogStore)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 Test (org.junit.Test)9 Serializable (java.io.Serializable)8 CatalogFramework (ddf.catalog.CatalogFramework)6 Date (java.util.Date)6 Matchers.anyString (org.mockito.Matchers.anyString)6 Metacard (ddf.catalog.data.Metacard)5 DeleteResponse (ddf.catalog.operation.DeleteResponse)5 QueryImpl (ddf.catalog.operation.impl.QueryImpl)5 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)5 FederatedSource (ddf.catalog.source.FederatedSource)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)4 IngestException (ddf.catalog.source.IngestException)4 FilterBuilder (ddf.catalog.filter.FilterBuilder)3 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)3 ProcessingDetails (ddf.catalog.operation.ProcessingDetails)3