use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds 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.get.GetAdjacentIds in project Gaffer by gchq.
the class IfScoreResolverTest method shouldGetScoreWithOperationChainAsAnOperation.
@Test
public void shouldGetScoreWithOperationChainAsAnOperation() {
// Given
final GetElements getElements = mock(GetElements.class);
final ToMap toMap = mock(ToMap.class);
final Map map = mock(Map.class);
final OperationChain conditionalChain = mock(OperationChain.class);
final List<Operation> conditionalOps = new LinkedList<>();
conditionalOps.add(getElements);
conditionalOps.add(toMap);
conditionalOps.add(map);
given(conditionalChain.getOperations()).willReturn(conditionalOps);
final Conditional conditional = mock(Conditional.class);
given(conditional.getTransform()).willReturn(conditionalChain);
final GetAdjacentIds getAdjacentIds = mock(GetAdjacentIds.class);
final GetAllElements getAllElements = mock(GetAllElements.class);
final If operation = new If.Builder<>().conditional(conditional).then(getAdjacentIds).otherwise(getAllElements).build();
final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(Operation.class, 1);
opScores.put(GetElements.class, 2);
opScores.put(ToMap.class, 2);
opScores.put(Map.class, 3);
opScores.put(GetAdjacentIds.class, 3);
opScores.put(GetAllElements.class, 4);
final IfScoreResolver resolver = new IfScoreResolver();
final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
// When
final int score = resolver.getScore(operation, defaultResolver);
// Then
assertEquals(11, score);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds 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.get.GetAdjacentIds in project Gaffer by gchq.
the class GetAdjacentIdsHandlerTest method shouldDoNothingIfNoSeedsProvided.
@Test
public void shouldDoNothingIfNoSeedsProvided() throws OperationException {
// Given
final GetAdjacentIdsHandler handler = new GetAdjacentIdsHandler();
final GetAdjacentIds getAdjacentIds = new GetAdjacentIds();
final Context context = mock(Context.class);
final HBaseStore store = mock(HBaseStore.class);
// When
final CloseableIterable<? extends EntityId> result = handler.doOperation(getAdjacentIds, context, store);
// Then
assertEquals(0, Iterables.size(result));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class OperationChainTest method shouldBuildOperationChain_AdjEntitySeedsThenElements.
@Test
public void shouldBuildOperationChain_AdjEntitySeedsThenElements() {
// Given
final GetAdjacentIds getAdjacentIds = mock(GetAdjacentIds.class);
final GetElements getEdges = mock(GetElements.class);
// When
final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getEdges).build();
// Then
assertEquals(2, opChain.getOperations().size());
assertSame(getAdjacentIds, opChain.getOperations().get(0));
assertSame(getEdges, opChain.getOperations().get(1));
}
Aggregations