use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class WhileHandlerTest method shouldRepeatDelegateOperationUntilMaxRepeatsReached.
@Test
public void shouldRepeatDelegateOperationUntilMaxRepeatsReached() throws OperationException {
// Given
final List<EntitySeed> input = Collections.singletonList(mock(EntitySeed.class));
final int maxRepeats = 3;
final GetAdjacentIds delegate = mock(GetAdjacentIds.class);
final GetAdjacentIds delegateClone1 = mock(GetAdjacentIds.class);
final GetAdjacentIds delegateClone2 = mock(GetAdjacentIds.class);
final GetAdjacentIds delegateClone3 = mock(GetAdjacentIds.class);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
given(delegate.shallowClone()).willReturn(delegateClone1, delegateClone2, delegateClone3);
final CloseableIterable result1 = mock(CloseableIterable.class);
final CloseableIterable result2 = mock(CloseableIterable.class);
final CloseableIterable result3 = mock(CloseableIterable.class);
given(store.execute(delegateClone1, context)).willReturn(result1);
given(store.execute(delegateClone2, context)).willReturn(result2);
given(store.execute(delegateClone3, context)).willReturn(result3);
final While operation = new While.Builder<>().input(input).maxRepeats(maxRepeats).operation(delegate).build();
final WhileHandler handler = new WhileHandler();
// When
final Object result = handler.doOperation(operation, context, store);
// Then
verify(delegateClone1, times(1)).getInput();
verify(delegateClone2, times(1)).getInput();
verify(delegateClone3, times(1)).getInput();
verify(store).execute((Output) delegateClone1, context);
verify(store).execute((Output) delegateClone2, context);
verify(store).execute((Output) delegateClone3, context);
assertSame(result3, result);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds 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.GetAdjacentIds 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.GetAdjacentIds in project Gaffer by gchq.
the class WhileTest method builderShouldCreatePopulatedOperation.
@Test
@Override
public void builderShouldCreatePopulatedOperation() {
// Given
final While operation = new While.Builder<>().input(new EntitySeed(1)).maxRepeats(10).condition(true).operation(new GetAdjacentIds()).build();
// When / Then
assertThat(operation.getInput()).isNotNull();
assertTrue(operation.getOperation() instanceof GetAdjacentIds);
assertTrue(operation.isCondition());
assertEquals(10, operation.getMaxRepeats());
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class GetAdjacentIdsTest method shouldGetAdjacentIdsWhenThereAreNone.
@Test
public void shouldGetAdjacentIdsWhenThereAreNone() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(GetAllElementsHandlerTest.getElements()).build();
graph.execute(addElements, new User());
// When
final GetAdjacentIds getAdjacentIds = new GetAdjacentIds.Builder().input(new EntitySeed("NOT_PRESENT")).build();
final CloseableIterable<? extends EntityId> results = graph.execute(getAdjacentIds, new User());
// Then
final Set<EntityId> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
assertEquals(Collections.emptySet(), resultsSet);
}
Aggregations