Search in sources :

Example 91 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class SchemaHidingIT method testOperations.

protected void testOperations(final Graph fullGraph, final Graph filteredGraph, final List<Edge> fullExpectedResults, final List<Edge> filteredExpectedResults) throws OperationException {
    testOperation(fullGraph, filteredGraph, new GetAllElements(), fullExpectedResults, filteredExpectedResults);
    final GetElements getElements = new GetElements.Builder().input(new EntitySeed("source1a"), new EntitySeed("source1b"), new EntitySeed("source2"), new EdgeSeed("source2", "dest2", true)).build();
    testOperation(fullGraph, filteredGraph, getElements, fullExpectedResults, filteredExpectedResults);
}
Also used : Builder(uk.gov.gchq.gaffer.graph.Graph.Builder) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements)

Example 92 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class IfHandlerTest method shouldExecuteCorrectlyWithOperationChainAsThen.

@Test
public void shouldExecuteCorrectlyWithOperationChainAsThen() 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 OperationChain<Object> then = mock(OperationChain.class);
    final GetAllElements otherwise = mock(GetAllElements.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(true);
    // When
    final Object result = handler.doOperation(filter, context, store);
    // Then
    verify(store).execute(then, context);
    verify(store, never()).execute(otherwise, context);
}
Also used : EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 93 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class IfHandlerTest method shouldExecuteThenWithBooleanCondition.

@Test
public void shouldExecuteThenWithBooleanCondition() throws OperationException {
    // Given
    final Object input = Arrays.asList(new EntitySeed("1"), new EntitySeed("2"));
    final GetElements then = mock(GetElements.class);
    final GetAllElements otherwise = mock(GetAllElements.class);
    final If filter = new If.Builder<>().input(input).condition(true).then(then).otherwise(otherwise).build();
    final IfHandler handler = new IfHandler();
    // When
    handler.doOperation(filter, context, store);
    // Then
    verify(store).execute(then, context);
    verify(store, never()).execute(otherwise, context);
}
Also used : EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 94 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class OperationChainHandlerTest method shouldHandleNestedOperationChain.

@Test
public void shouldHandleNestedOperationChain() throws OperationException {
    // Given
    final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
    final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
    final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    final 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 opChain2 = new OperationChain(Arrays.asList(opChain1, op3));
    final Entity entityA = new Entity.Builder().group(TestGroups.ENTITY).vertex("A").build();
    final Entity entityB = new Entity.Builder().group(TestGroups.ENTITY).vertex("B").build();
    given(context.getUser()).willReturn(user);
    given(store.getProperties()).willReturn(storeProperties);
    given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
    given(store.handleOperation(op1, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(new EntitySeed("A"), new EntitySeed("B"))));
    given(store.handleOperation(op2, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(entityA, entityB)));
    given(store.handleOperation(op3, context)).willReturn(entityA);
    // When
    final Object result = opChainHandler.doOperation(opChain2, context, store);
    // Then
    assertSame(entityA, result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) 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) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 95 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class WhileHandlerTest method shouldRepeatWhileConditionIsTrue.

@Test
public void shouldRepeatWhileConditionIsTrue() throws OperationException {
    // Given
    final List<EntitySeed> input = Collections.singletonList(mock(EntitySeed.class));
    final boolean condition = true;
    final int maxRepeats = 3;
    final GetElements delegate = mock(GetElements.class);
    final GetElements delegateClone1 = mock(GetElements.class);
    final GetElements delegateClone2 = mock(GetElements.class);
    final GetElements delegateClone3 = mock(GetElements.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).condition(condition).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) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Store(uk.gov.gchq.gaffer.store.Store) While(uk.gov.gchq.gaffer.operation.impl.While) Test(org.junit.jupiter.api.Test)

Aggregations

EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)284 Test (org.junit.jupiter.api.Test)122 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)122 Element (uk.gov.gchq.gaffer.data.element.Element)102 User (uk.gov.gchq.gaffer.user.User)92 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)90 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)87 HashSet (java.util.HashSet)71 Graph (uk.gov.gchq.gaffer.graph.Graph)69 Entity (uk.gov.gchq.gaffer.data.element.Entity)65 Edge (uk.gov.gchq.gaffer.data.element.Edge)61 Test (org.junit.Test)58 ArrayList (java.util.ArrayList)55 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)46 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)41 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)40 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)38 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)36 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)36 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)35