Skip to content

Commit

Permalink
Gh-3158: Make use of properties file in Federated Store Tests (#3218)
Browse files Browse the repository at this point in the history
* Use Util method for HashMapCache properties
Also tidy up use of assertions
  • Loading branch information
GCHQDeveloper314 authored May 21, 2024
1 parent f6928b3 commit b83b169
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@
import java.util.Collection;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.ACCUMULO_STORE_SINGLE_USE_PROPERTIES;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.CACHE_SERVICE_CLASS_STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.EDGES;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.ENTITIES;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_ACCUMULO;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_TEST_FEDERATED_STORE;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.getFederatedStorePropertiesWithHashMapCache;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadAccumuloStoreProperties;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.resetForFederatedTests;
import static uk.gov.gchq.gaffer.store.TestTypes.DIRECTED_EITHER;
Expand All @@ -64,10 +63,7 @@ public void setUp() throws Exception {
resetForFederatedTests();

federatedStore = new FederatedStore();

FederatedStoreProperties federatedStoreProperties;
federatedStoreProperties = new FederatedStoreProperties();
federatedStoreProperties.setDefaultCacheServiceClass(CACHE_SERVICE_CLASS_STRING);
FederatedStoreProperties federatedStoreProperties = getFederatedStorePropertiesWithHashMapCache();

federatedStore.initialise(GRAPH_ID_TEST_FEDERATED_STORE, null, federatedStoreProperties);

Expand Down Expand Up @@ -120,17 +116,16 @@ public void shouldNotShowHiddenGraphsInError() throws Exception {

addGraphWith(AUTH_1, schema, blankUser());

final OperationException e = assertThrows(OperationException.class, () -> addGraphWith("nonMatchingAuth", schema, testUser()));

assertThat(e).message()
assertThatThrownBy(() -> addGraphWith("nonMatchingAuth", schema, testUser())).isInstanceOf(OperationException.class)
.message()
.contains("Error adding graph " + GRAPH_ID_ACCUMULO + " to storage due to:")
.contains("User is attempting to overwrite a graph within FederatedStore. GraphId: " + GRAPH_ID_ACCUMULO)
.withFailMessage("error message should not contain details about schema")
.doesNotContain(unusualType)
.doesNotContain(groupEdge)
.doesNotContain(groupEnt);

assertTrue(federatedStore.getGraphs(testUser(), null, mock).isEmpty());
assertThat(federatedStore.getGraphs(testUser(), null, mock)).isEmpty();
}

private void addGraphWith(final String auth, final Schema schema, final User user) throws OperationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@

import static org.assertj.core.api.Assertions.assertThat;
import static uk.gov.gchq.gaffer.commonutil.TestPropertyNames.STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.CACHE_SERVICE_CLASS_STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_A;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_B;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_TEST_FEDERATED_STORE;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GROUP_BASIC_EDGE;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GROUP_BASIC_ENTITY;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.MAP_STORE_SINGLE_USE_PROPERTIES;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.getFederatedStorePropertiesWithHashMapCache;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadStoreProperties;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.resetForFederatedTests;
import static uk.gov.gchq.gaffer.federatedstore.util.FederatedStoreUtil.DEPRECATED_GRAPHIDS_OPTION;
Expand Down Expand Up @@ -74,8 +74,7 @@ public static void tearDownCache() {
@BeforeEach
public void setUp() throws Exception {
resetForFederatedTests();
FederatedStoreProperties federatedStoreProperties = new FederatedStoreProperties();
federatedStoreProperties.setDefaultCacheServiceClass(CACHE_SERVICE_CLASS_STRING);
FederatedStoreProperties federatedStoreProperties = getFederatedStorePropertiesWithHashMapCache();

federatedGraph = new Graph.Builder()
.config(new GraphConfig.Builder()
Expand Down Expand Up @@ -185,5 +184,4 @@ private Schema getSchema() {
.type(DIRECTED_EITHER, BOOLEAN_TYPE)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.ACCUMULO_STORE_SINGLE_USE_PROPERTIES;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.CACHE_SERVICE_CLASS_STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_A;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_ACCUMULO;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_B;
Expand All @@ -49,11 +48,11 @@
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.contextTestUser;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.entityBasic;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.entityBasicDefinition;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.getFederatedStorePropertiesWithHashMapCache;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadAccumuloStoreProperties;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.resetForFederatedTests;

public class FederatedStoreGraphLibraryTest {

public static final String SCHEMA_1 = "schema1";
private FederatedStore federatedStore;

Expand All @@ -78,9 +77,7 @@ public void setUp() throws Exception {
library.add(GRAPH_ID_B, build, properties.clone());

federatedStore = new FederatedStore();

FederatedStoreProperties fedProperties = new FederatedStoreProperties();
fedProperties.setDefaultCacheServiceClass(CACHE_SERVICE_CLASS_STRING);
FederatedStoreProperties fedProperties = getFederatedStorePropertiesWithHashMapCache();

federatedStore.initialise(GRAPH_ID_TEST_FEDERATED_STORE, null, fedProperties);
federatedStore.setGraphLibrary(library);
Expand Down Expand Up @@ -159,5 +156,4 @@ public void shouldAddGraphWithGraphFromLibrary() throws Exception {
assertThat(allElements)
.size().isEqualTo(1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,24 @@
import uk.gov.gchq.gaffer.federatedstore.operation.AddGraph;
import uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds;
import uk.gov.gchq.gaffer.store.Context;
import uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary;
import uk.gov.gchq.gaffer.store.schema.Schema;

import static java.util.Objects.isNull;
import static org.assertj.core.api.Assertions.assertThat;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.ACCUMULO_STORE_SINGLE_USE_PROPERTIES;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.CACHE_SERVICE_CLASS_STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_ACCUMULO;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_TEST_FEDERATED_STORE;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.contextBlankUser;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.contextTestUser;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.getFederatedStorePropertiesWithHashMapCache;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadAccumuloStoreProperties;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.resetForFederatedTests;

public class FederatedStorePublicAccessTest {

private static final Context BLANK_USER_CONTEXT = contextBlankUser();
private static final Context TEST_USER_CONTEXT = contextTestUser();
private static final AccumuloProperties PROPERTIES = loadAccumuloStoreProperties(ACCUMULO_STORE_SINGLE_USE_PROPERTIES);
private FederatedStore store;
private FederatedStoreProperties federatedStoreProperties;
private HashMapGraphLibrary library;

private static void getAllGraphsIdsIsEmpty(FederatedStore store, final boolean isEmpty) throws uk.gov.gchq.gaffer.operation.OperationException {
Iterable<String> results = (Iterable<String>) store.execute(new GetAllGraphIds(), BLANK_USER_CONTEXT);
Expand All @@ -62,10 +58,7 @@ private static void getAllGraphsIdsIsEmpty(FederatedStore store, final boolean i
@BeforeEach
public void setUp() throws Exception {
resetForFederatedTests();

federatedStoreProperties = new FederatedStoreProperties();
federatedStoreProperties.setDefaultCacheServiceClass(CACHE_SERVICE_CLASS_STRING);

federatedStoreProperties = getFederatedStorePropertiesWithHashMapCache();
store = new FederatedStore();
}

Expand Down Expand Up @@ -128,7 +121,6 @@ private AddGraph addGraph(final Boolean isPublic) {
.storeProperties(PROPERTIES.clone())
.schema(new Schema.Builder().build());

return (isNull(isPublic)) ? builder.build() : builder.isPublic(isPublic).build();
return (isPublic == null) ? builder.build() : builder.isPublic(isPublic).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
import static org.assertj.core.api.Assertions.assertThat;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.ACCUMULO_STORE_SINGLE_USE_PROPERTIES;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.BASIC_VERTEX;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.CACHE_SERVICE_CLASS_STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_A;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_B;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_TEST_FEDERATED_STORE;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GROUP_BASIC_ENTITY;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.INTEGER;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.PROPERTY_1;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.getFederatedStorePropertiesWithHashMapCache;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadAccumuloStoreProperties;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.resetForFederatedTests;
import static uk.gov.gchq.gaffer.store.TestTypes.INTEGER_TYPE;
Expand All @@ -68,8 +68,7 @@ public static void tearDownCache() {
@BeforeEach
public void setUp() throws Exception {
resetForFederatedTests();
FederatedStoreProperties federatedStoreProperties = new FederatedStoreProperties();
federatedStoreProperties.setDefaultCacheServiceClass(CACHE_SERVICE_CLASS_STRING);
FederatedStoreProperties federatedStoreProperties = getFederatedStorePropertiesWithHashMapCache();

federatedGraph = new Graph.Builder()
.config(new GraphConfig.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static uk.gov.gchq.gaffer.federatedstore.FederatedGraphStorage.GRAPH_IDS_NOT_VISIBLE;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.ACCUMULO_STORE_SINGLE_USE_PROPERTIES;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.CACHE_SERVICE_CLASS_STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_ACCUMULO;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GRAPH_ID_TEST_FEDERATED_STORE;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GROUP_BASIC_ENTITY;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.PROPERTY_1;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.contextBlankUser;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.entityBasic;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.getFederatedStorePropertiesWithHashMapCache;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadAccumuloStoreProperties;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.resetForFederatedTests;
import static uk.gov.gchq.gaffer.federatedstore.util.FederatedStoreUtil.getFederatedOperation;
Expand All @@ -70,8 +70,7 @@ public void setUp() throws Exception {

federatedStore = new FederatedStore();

FederatedStoreProperties fedProps = new FederatedStoreProperties();
fedProps.setDefaultCacheServiceClass(CACHE_SERVICE_CLASS_STRING);
FederatedStoreProperties fedProps = getFederatedStorePropertiesWithHashMapCache();

federatedStore.initialise(GRAPH_ID_TEST_FEDERATED_STORE, null, fedProps);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static uk.gov.gchq.gaffer.federatedstore.FederatedGraphStorage.USER_IS_ATTEMPTING_TO_OVERWRITE;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.SCHEMA_EDGE_BASIC_JSON;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.getFederatedStorePropertiesWithHashMapCache;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadSchemaFromJson;
import static uk.gov.gchq.gaffer.store.StoreProperties.OPERATION_DECLARATIONS_JSON;
import static uk.gov.gchq.gaffer.user.StoreUser.authUser;
Expand All @@ -82,8 +83,7 @@ public class FederatedAddGraphHandlerTest {
public void setUp() throws Exception {
CacheServiceLoader.shutdown();
this.store = new FederatedStore();
federatedStoreProperties = new FederatedStoreProperties();
federatedStoreProperties.setDefaultCacheServiceClass(CACHE_SERVICE_CLASS_STRING);
federatedStoreProperties = getFederatedStorePropertiesWithHashMapCache();

testUser = testUser();
authUser = authUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static uk.gov.gchq.gaffer.federatedstore.FederatedGraphStorage.USER_IS_ATTEMPTING_TO_OVERWRITE;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.CACHE_SERVICE_CLASS_STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.SCHEMA_EDGE_BASIC_JSON;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.getFederatedStorePropertiesWithHashMapCache;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.loadSchemaFromJson;
import static uk.gov.gchq.gaffer.user.StoreUser.authUser;
import static uk.gov.gchq.gaffer.user.StoreUser.blankUser;
Expand All @@ -79,8 +79,7 @@ public class FederatedAddGraphWithHooksHandlerTest {
public void setUp() throws Exception {
CacheServiceLoader.shutdown();
this.store = new FederatedStore();
federatedStoreProperties = new FederatedStoreProperties();
federatedStoreProperties.setDefaultCacheServiceClass(CACHE_SERVICE_CLASS_STRING);
federatedStoreProperties = getFederatedStorePropertiesWithHashMapCache();

testUser = testUser();
authUser = authUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import java.util.Collection;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.ACCUMULO_STORE_SINGLE_USE_PROPERTIES;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.CACHE_SERVICE_CLASS_STRING;
import static uk.gov.gchq.gaffer.federatedstore.FederatedStoreTestUtil.GROUP_BASIC_ENTITY;
Expand Down Expand Up @@ -78,7 +76,7 @@ public void shouldRemoveGraphForOwningUser() throws Exception {
.properties(PROPERTIES)
.build());

assertEquals(1, store.getGraphs(testUser, null, new RemoveGraph()).size());
assertThat(store.getGraphs(testUser, null, new RemoveGraph())).hasSize(1);

new FederatedRemoveGraphHandler().doOperation(
new RemoveGraph.Builder()
Expand All @@ -90,7 +88,6 @@ public void shouldRemoveGraphForOwningUser() throws Exception {
Collection<GraphSerialisable> graphs = store.getGraphs(testUser, null, new RemoveGraph());

assertThat(graphs).isEmpty();

}

@Test
Expand All @@ -104,7 +101,7 @@ public void shouldNotRemoveGraphForNonOwningUser() throws Exception {
.properties(PROPERTIES)
.build());

assertEquals(1, store.getGraphs(testUser, null, new RemoveGraph()).size());
assertThat(store.getGraphs(testUser, null, new RemoveGraph())).hasSize(1);

final Boolean removed = new FederatedRemoveGraphHandler().doOperation(
new RemoveGraph.Builder()
Expand All @@ -116,15 +113,15 @@ public void shouldNotRemoveGraphForNonOwningUser() throws Exception {
Collection<GraphSerialisable> graphs = store.getGraphs(testUser, null, new RemoveGraph());

assertThat(graphs).hasSize(1);
assertFalse(removed);
assertThat(removed).isFalse();
}

@Test
public void shouldReturnFalseWhenNoGraphWasRemoved() throws Exception {
FederatedStore store = new FederatedStore();
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, getFederatedStorePropertiesWithHashMapCache());

assertEquals(0, store.getGraphs(testUser, null, new RemoveGraph()).size());
assertThat(store.getGraphs(testUser, null, new RemoveGraph())).hasSize(0);

final Boolean removed = new FederatedRemoveGraphHandler().doOperation(
new RemoveGraph.Builder()
Expand All @@ -136,8 +133,7 @@ public void shouldReturnFalseWhenNoGraphWasRemoved() throws Exception {
Collection<GraphSerialisable> graphs = store.getGraphs(testUser, null, new RemoveGraph());

assertThat(graphs).hasSize(0);
assertFalse(removed);

assertThat(removed).isFalse();
}

@Test
Expand All @@ -159,7 +155,7 @@ public void shouldNotRemoveGraphConfiguredWithNoAccessWritePredicate() throws Ex
.properties(PROPERTIES)
.build());

assertEquals(1, store.getGraphs(testUser, null, new RemoveGraph()).size());
assertThat(store.getGraphs(testUser, null, new RemoveGraph())).hasSize(1);

new FederatedRemoveGraphHandler().doOperation(
new RemoveGraph.Builder()
Expand Down Expand Up @@ -270,8 +266,7 @@ public void shouldRemoveGraphAndCache() throws Exception {
public void shouldRemoveGraphAndCacheWhenUsingMultipleServices() throws Exception {
// Create and initialise a new Federated Store with the default cache service class store property configured
FederatedStore store = new FederatedStore();
final FederatedStoreProperties federatedStoreProperties = new FederatedStoreProperties();
federatedStoreProperties.setDefaultCacheServiceClass(CACHE_SERVICE_CLASS_STRING);
final FederatedStoreProperties federatedStoreProperties = getFederatedStorePropertiesWithHashMapCache();
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);

final String cacheNameSuffix = "removeThisCache";
Expand Down
Loading

0 comments on commit b83b169

Please sign in to comment.