use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class ScoreOperationChainHandlerTest method shouldCorrectlyResolveScoreForNullListOfOperations.
@Test
public void shouldCorrectlyResolveScoreForNullListOfOperations() throws OperationException {
// Given
final ScoreOperationChainHandler handler = new ScoreOperationChainHandler();
final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
handler.setScoreResolvers(resolvers);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final ScoreOperationChain scoreOperationChain = mock(ScoreOperationChain.class);
final StoreProperties properties = mock(StoreProperties.class);
final List<? extends Operation> opList = null;
final OperationChain opChain = new OperationChain(opList);
given(scoreOperationChain.getOperationChain()).willReturn(opChain);
given(context.getUser()).willReturn(user);
Set<String> opAuths = new HashSet<>();
opAuths.add("TEST_USER");
given(user.getOpAuths()).willReturn(opAuths);
given(store.getProperties()).willReturn(properties);
// When
final Object result = handler.doOperation(new ScoreOperationChain.Builder().operationChain(opChain).build(), context, store);
// Then
assertEquals(0, result);
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class ScoreOperationChainHandlerTest method shouldExecuteScoreOperationChainContainingNamedOperation.
@Test
public void shouldExecuteScoreOperationChainContainingNamedOperation() throws OperationException {
// Given
final ScoreOperationChainHandler handler = new ScoreOperationChainHandler();
final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
final ScoreResolver scoreResolver = mock(NamedOperationScoreResolver.class);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final ScoreOperationChain scoreOperationChain = mock(ScoreOperationChain.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final Limit op3 = mock(Limit.class);
final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(Operation.class, 1);
opScores.put(GetAdjacentIds.class, 2);
opScores.put(GetElements.class, 1);
opScores.put(Limit.class, 1);
handler.setOpScores(opScores);
final String opName = "basicOp";
final NamedOperation<Iterable<? extends Element>, Iterable<? extends Element>> namedOp = mock(NamedOperation.class);
namedOp.setOperationName(opName);
resolvers.put(namedOp.getClass(), scoreResolver);
handler.setScoreResolvers(resolvers);
given(scoreResolver.getScore(eq(namedOp), any())).willReturn(3);
final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2, op3, namedOp));
given(context.getUser()).willReturn(user);
Set<String> opAuths = new HashSet<>();
opAuths.add("TEST_USER");
given(user.getOpAuths()).willReturn(opAuths);
given(scoreOperationChain.getOperationChain()).willReturn(opChain);
given(store.getProperties()).willReturn(storeProperties);
// When
final Object result = handler.doOperation(new ScoreOperationChain.Builder().operationChain(opChain).build(), context, store);
// Then
assertEquals(7, result);
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class ScoreOperationChainHandlerTest method shouldCorrectlyResolveScoreForNestedOperationWithNullOperationList.
@Test
public void shouldCorrectlyResolveScoreForNestedOperationWithNullOperationList() throws OperationException {
// Given
final ScoreOperationChainHandler handler = new ScoreOperationChainHandler();
final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
final ScoreResolver scoreResolver = mock(NamedOperationScoreResolver.class);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final ScoreOperationChain scoreOperationChain = mock(ScoreOperationChain.class);
final StoreProperties properties = mock(StoreProperties.class);
final GetAllElements op1 = mock(GetAllElements.class);
final Transform op2 = mock(Transform.class);
final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(GetAllElements.class, 2);
opScores.put(Transform.class, 1);
handler.setOpScores(opScores);
final String opName = "namedOp";
final NamedOperation<Iterable<? extends Element>, Iterable<? extends Element>> namedOp = mock(NamedOperation.class);
namedOp.setOperationName(opName);
resolvers.put(namedOp.getClass(), scoreResolver);
handler.setScoreResolvers(resolvers);
given(scoreResolver.getScore(eq(namedOp), any())).willReturn(3);
final List<? extends Operation> opList = null;
final OperationChain nestedOpChain = new OperationChain(opList);
final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2, nestedOpChain, namedOp));
given(scoreOperationChain.getOperationChain()).willReturn(opChain);
given(context.getUser()).willReturn(user);
Set<String> opAuths = new HashSet<>();
opAuths.add("TEST_USER");
given(user.getOpAuths()).willReturn(opAuths);
given(store.getProperties()).willReturn(properties);
// When
final Object result = handler.doOperation(new ScoreOperationChain.Builder().operationChain(opChain).build(), context, store);
// Then
assertEquals(6, result);
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class ScoreOperationChainHandlerTest method shouldCorrectlyExecuteScoreOperationChainWhenNamedOperationScoreIsNull.
@Test
public void shouldCorrectlyExecuteScoreOperationChainWhenNamedOperationScoreIsNull() throws OperationException {
// Given
final ScoreOperationChainHandler handler = new ScoreOperationChainHandler();
final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
final ScoreResolver scoreResolver = mock(NamedOperationScoreResolver.class);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final ScoreOperationChain scoreOperationChain = mock(ScoreOperationChain.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final Limit op3 = mock(Limit.class);
final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(GetAdjacentIds.class, 3);
opScores.put(GetElements.class, 2);
opScores.put(Limit.class, 1);
handler.setOpScores(opScores);
final String opName = "basicOp";
final NamedOperation<Iterable<? extends Element>, Iterable<? extends Element>> namedOp = mock(NamedOperation.class);
namedOp.setOperationName(opName);
resolvers.put(namedOp.getClass(), scoreResolver);
handler.setScoreResolvers(resolvers);
given(scoreResolver.getScore(eq(namedOp), any())).willReturn(null);
final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2, op3, namedOp));
given(context.getUser()).willReturn(user);
Set<String> opAuths = new HashSet<>();
opAuths.add("TEST_USER");
given(user.getOpAuths()).willReturn(opAuths);
given(scoreOperationChain.getOperationChain()).willReturn(opChain);
given(store.getProperties()).willReturn(storeProperties);
// When
final Object result = handler.doOperation(new ScoreOperationChain.Builder().operationChain(opChain).build(), context, store);
// Then
assertEquals(7, result);
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GetTraitsHandlerTest method shouldHaveAllTraitsForSupported.
@Test
public void shouldHaveAllTraitsForSupported() throws Exception {
// Given
store.initialise(STORE_ID, new Schema(), new StoreProperties());
// When
Set<StoreTrait> traits = store.execute(new GetTraits.Builder().currentTraits(false).build(), new Context(testUser()));
// Then
assertEquals(expectedTraits, traits);
}
Aggregations