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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations