Search in sources :

Example 16 with GetAdjacentIds

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Store(uk.gov.gchq.gaffer.store.Store) While(uk.gov.gchq.gaffer.operation.impl.While) Test(org.junit.jupiter.api.Test)

Example 17 with GetAdjacentIds

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ScoreOperationChain(uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ScoreOperationChain(uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 18 with GetAdjacentIds

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ScoreOperationChain(uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ScoreOperationChain(uk.gov.gchq.gaffer.operation.impl.ScoreOperationChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 19 with GetAdjacentIds

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());
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 20 with GetAdjacentIds

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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Graph(uk.gov.gchq.gaffer.graph.Graph) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)57 Test (org.junit.jupiter.api.Test)53 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)32 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)32 User (uk.gov.gchq.gaffer.user.User)32 Context (uk.gov.gchq.gaffer.store.Context)25 Operation (uk.gov.gchq.gaffer.operation.Operation)20 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)19 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)13 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)12 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)12 HashSet (java.util.HashSet)11 LinkedHashMap (java.util.LinkedHashMap)11 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)11 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)9 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)9 Graph (uk.gov.gchq.gaffer.graph.Graph)8 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)8 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)7 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)6