use of ddf.catalog.source.CatalogStore in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateWithStores.
// TODO (DDF-2436) -
@Ignore
@Test
public void testUpdateWithStores() 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();
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));
MetacardImpl updateCard = new MetacardImpl();
updateCard.setId(id);
updateCard.setAttribute("myKey", "myValue2");
List<Entry<Serializable, Metacard>> updates = new ArrayList<>();
updates.add(new SimpleEntry<>(id, updateCard));
destinations.remove("mockMemoryProvider");
framework.update(new UpdateRequestImpl(updates, Metacard.ID, new HashMap<>(), destinations));
assertThat(provider.hasReceivedUpdateByIdentifier(), is(false));
assertThat(store.hasReceivedUpdateByIdentifier(), is(true));
QueryResponse storeResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), destinations));
assertThat(storeResponse.getResults().size(), is(1));
assertThat(storeResponse.getResults().get(0).getMetacard().getAttribute("myKey").getValue(), equalTo("myValue2"));
destinations.clear();
QueryResponse providerResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), destinations));
assertThat(providerResponse.getResults().size(), is(1));
assertThat(providerResponse.getResults().get(0).getMetacard().getAttribute("myKey").getValue(), equalTo("myValue1"));
}
use of ddf.catalog.source.CatalogStore in project ddf by codice.
the class CatalogFrameworkImplTest method testCreateWithStores.
@Test
public void testCreateWithStores() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
List<CatalogStore> stores = new ArrayList<>();
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
stores.add(store);
CatalogFramework framework = createDummyCatalogFramework(provider, stores, null, eventAdmin);
List<Metacard> metacards = new ArrayList<>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
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");
CreateResponse response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(0, provider.size());
assertEquals(response.getCreatedMetacards().size(), store.size());
assertEquals(1, store.size());
assertFalse(eventAdmin.wasEventPosted());
// ==== test writing to store and local ====
destinations.add("mockMemoryProvider");
newCard.setId(null);
reqProps = new HashMap<>();
response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(1, provider.size());
assertEquals(response.getCreatedMetacards().size(), provider.size());
assertEquals(2, store.size());
assertTrue(eventAdmin.wasEventPosted());
// ==== test writing to local when no destination ====
destinations.clear();
newCard.setId(null);
reqProps = new HashMap<>();
response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(2, provider.size());
assertEquals(response.getCreatedMetacards().size(), 1);
assertEquals(2, store.size());
}
use of ddf.catalog.source.CatalogStore 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));
}
use of ddf.catalog.source.CatalogStore 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);
}
use of ddf.catalog.source.CatalogStore in project ddf by codice.
the class RemoteDeleteOperationsTest method testNonEmptyStoreAvailableExpectsDeleteResponse.
@Test
public void testNonEmptyStoreAvailableExpectsDeleteResponse() throws Exception {
when(opsCatStoreSupport.isCatalogStoreRequest(deleteRequest)).thenReturn(true);
remoteDeleteOperations.setOpsCatStoreSupport(opsCatStoreSupport);
CatalogStore catalogStoreMock = mock(CatalogStore.class);
ArrayList<CatalogStore> stores = new ArrayList<>();
stores.add(catalogStoreMock);
when(opsCatStoreSupport.getCatalogStoresForRequest(any(), any())).thenReturn(stores);
when(catalogStoreMock.isAvailable()).thenReturn(true);
when(catalogStoreMock.delete(any())).thenReturn(deleteResponse);
DeleteResponse resultDeleteResponse = remoteDeleteOperations.performRemoteDelete(deleteRequest, deleteResponse);
assertEqualMetacards("Assert return of identical deleteResponse", resultDeleteResponse.getDeletedMetacards(), deleteResponse.getDeletedMetacards());
verify(opsCatStoreSupport).isCatalogStoreRequest(deleteRequest);
verify(opsCatStoreSupport).getCatalogStoresForRequest(any(), any());
verify(catalogStoreMock).isAvailable();
verify(catalogStoreMock).delete(any());
}
Aggregations