use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class OperationChainHandlerTest method shouldHandleOperationChain.
@Test
public void shouldHandleOperationChain() throws OperationException {
// Given
final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2));
final Entity expectedResult = new Entity(TestGroups.ENTITY);
given(context.getUser()).willReturn(user);
given(store.getProperties()).willReturn(storeProperties);
given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
given(store.handleOperation(op1, context)).willReturn(new WrappedCloseableIterable<>(Collections.singletonList(new EntitySeed())));
given(store.handleOperation(op2, context)).willReturn(expectedResult);
// When
final Object result = opChainHandler.doOperation(opChain, context, store);
// Then
assertSame(expectedResult, result);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class ScoreOperationChainHandlerTest method shouldResolveScoreOperationChainWithMultipleScoreResolvers.
@Test
public void shouldResolveScoreOperationChainWithMultipleScoreResolvers() throws OperationException {
// Given
final ScoreOperationChainHandler handler = new ScoreOperationChainHandler();
final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
final ScoreResolver scoreResolver = mock(NamedOperationScoreResolver.class);
final ScoreResolver scoreResolver1 = mock(DefaultScoreResolver.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 = mock(StoreProperties.class);
final GetAdjacentIds op1 = new GetAdjacentIds();
final AddElements op2 = new AddElements();
final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(GetAdjacentIds.class, 2);
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);
resolvers.put(op2.getClass(), scoreResolver1);
handler.setScoreResolvers(resolvers);
given(scoreResolver.getScore(eq(namedOp), any())).willReturn(3);
given(scoreResolver1.getScore(eq(op2), any())).willReturn(5);
final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2, 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(10, result);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class ValidateOperationChainHandlerTest method shouldValidateOperationChain.
@Test
public void shouldValidateOperationChain() throws OperationException {
// Given
final AddElements addElements = new AddElements();
final GetAdjacentIds getAdj = new GetAdjacentIds();
final GetElements getElements = new GetElements();
final DiscardOutput discardOutput = new DiscardOutput();
OperationChain chain = new OperationChain.Builder().first(addElements).then(getAdj).then(getElements).then(discardOutput).build();
ValidateOperationChain validateOperationChain = new ValidateOperationChain.Builder().operationChain(chain).build();
given(store.getOperationChainValidator()).willReturn(new OperationChainValidator(new ViewValidator()));
ValidateOperationChainHandler handler = new ValidateOperationChainHandler();
// When
ValidationResult result = handler.doOperation(validateOperationChain, context, store);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldFailQuietlyIfNestedOperationsCannotBeModified.
@Test
public void shouldFailQuietlyIfNestedOperationsCannotBeModified() throws SerialisationException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation validate = new Validate();
Operation getAdjacentIds = new GetAdjacentIds();
Operation count = new Count<>();
Operation getElements = new GetElements();
Operation getAllElements = new GetAllElements();
TestUnmodifiableOperationsImpl nestedUnmodifiableOps = new TestUnmodifiableOperationsImpl(Arrays.asList(getAllElements, getElements));
final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(nestedUnmodifiableOps).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then(nestedUnmodifiableOps).then(count).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class DefaultScoreResolverTest method shouldGetScoreForOperationChain.
@Test
public void shouldGetScoreForOperationChain() {
// Given
final GetAdjacentIds getAdjacentIds = mock(GetAdjacentIds.class);
final GetElements getElements = mock(GetElements.class);
final Limit limit = mock(Limit.class);
final List<Operation> opList = Arrays.asList(getAdjacentIds, getElements, limit);
final OperationChain opChain = mock(OperationChain.class);
given(opChain.getOperations()).willReturn(opList);
final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(Operation.class, 1);
opScores.put(GetElements.class, 2);
opScores.put(GetAdjacentIds.class, 3);
opScores.put(Limit.class, 1);
final DefaultScoreResolver resolver = new DefaultScoreResolver(opScores);
// When
final int score = resolver.getScore(opChain);
// Then
assertEquals(6, score);
}
Aggregations