use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.
the class IfHandlerTest method shouldExecuteOtherwiseOperationWhenConditionNotMet.
@Test
public void shouldExecuteOtherwiseOperationWhenConditionNotMet() throws OperationException {
// Given
final Object input = Arrays.asList(new EntitySeed("1"), new EntitySeed("2"));
final Conditional conditional = mock(Conditional.class);
final Predicate<Object> predicate = mock(Predicate.class);
final GetWalks then = mock(GetWalks.class);
final GetElements otherwise = mock(GetElements.class);
final If filter = new If.Builder<>().input(input).conditional(conditional).then(then).otherwise(otherwise).build();
final IfHandler handler = new IfHandler();
given(conditional.getPredicate()).willReturn(predicate);
given(predicate.test(input)).willReturn(false);
// When
handler.doOperation(filter, context, store);
// Then
verify(predicate).test(input);
verify(store, never()).execute(then, context);
verify(store).execute(otherwise, context);
}
use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.
the class IfHandlerTest method shouldReturnInitialInputForNullOperations.
@Test
public void shouldReturnInitialInputForNullOperations() throws OperationException {
// Given
final Object input = Arrays.asList(new EntitySeed("1"), new EntitySeed("2"));
final Conditional conditional = mock(Conditional.class);
final Predicate<Object> predicate = mock(Predicate.class);
final GetWalks then = null;
final GetElements otherwise = null;
final If filter = new If.Builder<>().input(input).conditional(conditional).then(then).otherwise(otherwise).build();
given(conditional.getPredicate()).willReturn(predicate);
given(predicate.test(input)).willReturn(true);
final IfHandler handler = new IfHandler();
// When
final Object result = handler.doOperation(filter, context, store);
// Then
assertEquals(result, input);
verify(predicate).test(input);
verify(store, never()).execute(then, context);
verify(store, never()).execute(otherwise, context);
}
use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldAddIfOperation.
@Test
public void shouldAddIfOperation() throws SerialisationException {
// Given
final GetWalks getWalks = new GetWalks();
final uk.gov.gchq.gaffer.operation.impl.Map map = new uk.gov.gchq.gaffer.operation.impl.Map();
final ToVertices toVertices = new ToVertices();
final ToSet toSet = new ToSet();
final Exists exists = new Exists();
final Limit limit = new Limit();
final GetAllElements getAllElements = new GetAllElements();
final GetElements getElements = new GetElements();
final Conditional conditional = new Conditional();
conditional.setPredicate(exists);
final If ifOp = new If.Builder<>().conditional(conditional).then(getElements).otherwise(getAllElements).build();
final AddOperationsToChain hook = new AddOperationsToChain();
final Map<String, List<Operation>> after = new HashMap<>();
final List<Operation> afterOps = new LinkedList<>();
afterOps.add(ifOp);
afterOps.add(limit);
after.put("uk.gov.gchq.gaffer.operation.impl.output.ToSet", afterOps);
hook.setAfter(after);
final OperationChain opChain = new OperationChain.Builder().first(getWalks).then(map).then(toVertices).then(toSet).build();
// When
hook.preExecute(opChain, new Context());
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(getWalks).then(map).then(toVertices).then(toSet).then(ifOp).then(limit).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.
the class IfScoreResolverTest method shouldGetScoreWithFullyPopulatedOperation.
@Test
public void shouldGetScoreWithFullyPopulatedOperation() {
// Given
final Count count = mock(Count.class);
final GetAllElements getAllElements = mock(GetAllElements.class);
final GetWalks getWalks = mock(GetWalks.class);
final Conditional conditional = mock(Conditional.class);
given(conditional.getTransform()).willReturn(count);
final If operation = new If.Builder<>().conditional(conditional).then(getWalks).otherwise(getAllElements).build();
final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(Count.class, 1);
opScores.put(GetAllElements.class, 3);
opScores.put(GetWalks.class, 4);
final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
final IfScoreResolver resolver = new IfScoreResolver();
// When
final int score = resolver.getScore(operation, defaultResolver);
// Then
assertEquals(4, score);
}
use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.
the class GetWalksIT method shouldGetPathsWithWhileRepeat.
@Test
public void shouldGetPathsWithWhileRepeat() throws Exception {
// Given
final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
final GetWalks op = new GetWalks.Builder().input(seedA).operations(new While.Builder<>().operation(operation).maxRepeats(2).build()).build();
// When
final Iterable<Walk> results = graph.execute(op, getUser());
// Then
assertThat(getPaths(results)).isEqualTo("AED,ABC");
}
Aggregations