use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.
the class IfScoreResolverTest method shouldGetScoreForNestedOperations.
@Test
public void shouldGetScoreForNestedOperations() {
// Given
final Map map = mock(Map.class);
final Conditional conditional = mock(Conditional.class);
given(conditional.getTransform()).willReturn(map);
final GetWalks getWalks = mock(GetWalks.class);
given(getWalks.getOperations()).willReturn(Collections.singletonList(new OperationChain<>(new GetAdjacentIds(), new GetAdjacentIds())));
final GetAllElements getAllElements = new GetAllElements();
final If operation = new If.Builder<>().conditional(conditional).then(getWalks).otherwise(getAllElements).build();
final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(Operation.class, 1);
opScores.put(Map.class, 3);
opScores.put(GetAdjacentIds.class, 2);
opScores.put(GetAllElements.class, 3);
final IfScoreResolver resolver = new IfScoreResolver();
final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
// When
final int score = resolver.getScore(operation, defaultResolver);
// Then
assertEquals(7, score);
}
use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.
the class DefaultScoreResolverTest method shouldGetScoreForNestedOperations.
@Test
public void shouldGetScoreForNestedOperations() {
// Given
final GetElements getElements = mock(GetElements.class);
final GetWalks getWalks = mock(GetWalks.class);
final GetAdjacentIds getAdjacentIds = mock(GetAdjacentIds.class);
given(getWalks.getOperations()).willReturn(Collections.singletonList(new OperationChain<>(getAdjacentIds, getAdjacentIds)));
final Limit limit = mock(Limit.class);
final List<Operation> opList = Arrays.asList(getElements, getWalks, 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, 2);
opScores.put(Limit.class, 1);
final DefaultScoreResolver resolver = new DefaultScoreResolver(opScores);
// When
final int score = resolver.getScore(opChain);
// Then
assertEquals(7, score);
}
use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldAddAllOperationsToGetWalksOperation.
@Test
public void shouldAddAllOperationsToGetWalksOperation() throws SerialisationException {
// Given
final AddOperationsToChain hook = new AddOperationsToChain();
final java.util.Map<String, List<Operation>> after = new HashMap<>();
after.put(GetElements.class.getName(), Lists.newArrayList(new Limit()));
hook.setAfter(after);
hook.setEnd(Lists.newArrayList(new Limit()));
final GetElements getElements = new GetElements();
final Limit limit = new Limit();
final OperationChain getWalksOperations = new OperationChain.Builder().first(getElements).build();
final GetWalks getWalks = new GetWalks.Builder().operations(getWalksOperations).build();
final OperationChain opChain = new OperationChain.Builder().first(getWalks).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final GetWalks expectedGetWalks = new GetWalks.Builder().operations(new OperationChain(getElements, limit)).build();
final OperationChain expectedOpChain = new OperationChain.Builder().first(expectedGetWalks).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 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();
}
use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.
the class GetWalksIT method shouldGetPathsWithEntities.
@Test
public void shouldGetPathsWithEntities() throws Exception {
// Given
final GetElements getEntities = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
final GetElements getElements = new GetElements.Builder().directedType(DirectedType.DIRECTED).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build()).build();
final GetWalks op = new GetWalks.Builder().input(seedA).operations(getElements, getElements, getEntities).build();
// When
final List<Walk> results = Lists.newArrayList(graph.execute(op, getUser()));
// Then
assertThat(getPaths(results)).isEqualTo("AED,ABC");
results.forEach(r -> r.getEntities().forEach(l -> {
assertThat(l).isNotEmpty();
}));
}
Aggregations