use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class WhileHandlerTest method shouldThrowExceptionWhenPredicateCannotAcceptInputType.
@Test
public void shouldThrowExceptionWhenPredicateCannotAcceptInputType() throws OperationException {
// Given
final Predicate predicate = new IsFalse();
final Object input = new EntitySeed();
final Conditional conditional = new Conditional(predicate);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final While operation = new While.Builder<>().input(input).conditional(conditional).operation(new GetElements()).build();
final WhileHandler handler = new WhileHandler();
// When / Then
try {
handler.doOperation(operation, context, store);
fail("Exception expected");
} catch (final OperationException e) {
assertTrue(e.getMessage().contains("The predicate '" + predicate.getClass().getSimpleName() + "' cannot accept an input of type '" + input.getClass().getSimpleName() + "'"));
}
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class WhileHandlerTest method shouldFailPredicateTestAndNotExecuteDelegateOperation.
@Test
public void shouldFailPredicateTestAndNotExecuteDelegateOperation() throws OperationException {
// Given
final Edge input = new Edge.Builder().group("testEdge").source("src").dest("dest").directed(true).property("count", 3).build();
final Map<Element, Object> transform = new Map.Builder<Element>().first(new ExtractProperty("count")).build();
final Predicate predicate = new IsMoreThan(5);
final Conditional conditional = new Conditional(predicate, transform);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final GetElements getElements = mock(GetElements.class);
final While operation = new While.Builder<>().input(input).maxRepeats(1).conditional(conditional).operation(getElements).build();
final WhileHandler handler = new WhileHandler();
// When
handler.doOperation(operation, context, store);
// Then
verify(store, never()).execute((Output) getElements, context);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class ScoreOperationChainHandlerTest method shouldExecuteScoreChainOperation.
@Test
public void shouldExecuteScoreChainOperation() throws OperationException {
// Given
final ScoreOperationChainHandler operationHandler = new ScoreOperationChainHandler();
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final ScoreOperationChain scoreOperationChain = mock(ScoreOperationChain.class);
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 Integer expectedResult = 2;
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 = operationHandler.doOperation(new ScoreOperationChain.Builder().operationChain(opChain).build(), context, store);
// Then
assertSame(expectedResult, result);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class ScoreOperationChainHandlerTest method shouldExecuteScoreChainOperationForNestedOperationChain.
@Test
public void shouldExecuteScoreChainOperationForNestedOperationChain() throws OperationException {
// Given
final ScoreOperationChainHandler operationHandler = new ScoreOperationChainHandler();
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final ScoreOperationChain scoreOperationChain = mock(ScoreOperationChain.class);
StoreProperties storeProperties = new StoreProperties();
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final Limit op3 = mock(Limit.class);
final OperationChain opChain1 = new OperationChain(Arrays.asList(op1, op2));
final OperationChain opChain = new OperationChain(Arrays.asList(opChain1, op3));
final Integer expectedResult = 3;
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 = operationHandler.doOperation(new ScoreOperationChain.Builder().operationChain(opChain).build(), context, store);
// Then
assertSame(expectedResult, result);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class GetWalksHandlerTest method shouldHandleNullInput.
@Test
public void shouldHandleNullInput() throws Exception {
// Given
final GetElements getElements = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).build()).build();
final GetWalks operation = new GetWalks.Builder().operations(getElements).build();
final GetWalksHandler handler = new GetWalksHandler();
// When
final Iterable<Walk> result = handler.doOperation(operation, null, null);
// Then
assertThat(result).isNull();
}
Aggregations