use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class WhileTest method shouldShallowCloneOperation.
@Test
@Override
public void shouldShallowCloneOperation() {
// Given
final EntitySeed input = new EntitySeed("E");
final Predicate predicate = new Exists();
final Operation delegate = new GetAdjacentIds();
final int maxRepeats = 5;
final While operation = new While.Builder<>().input(input).maxRepeats(maxRepeats).conditional(predicate).operation(delegate).build();
// When
final While clone = operation.shallowClone();
// Then
assertNotSame(operation, clone);
assertEquals(input, clone.getInput());
assertEquals(maxRepeats, clone.getMaxRepeats());
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveAllOpAuthsForAllOperations.
@Test
public void shouldRejectOperationChainWhenUserDoesntHaveAllOpAuthsForAllOperations() {
// Given
final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
final OperationChain opChain = new OperationChain.Builder().first(// Requires SuperUser
new GetAdjacentIds()).build();
final User user = new User.Builder().opAuths("WriteUser", "ReadUser", "User").build();
// When/Then
assertThatExceptionOfType(UnauthorisedException.class).isThrownBy(() -> hook.preExecute(opChain, new Context(user))).extracting("message").isNotNull();
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveAllowedAuth.
@Test
public void shouldRejectOperationChainWhenUserDoesntHaveAllowedAuth() throws OperationException {
// Given
final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetElements()).build();
final User user = new User.Builder().opAuths("unknownAuth").build();
// When/Then
assertThatExceptionOfType(UnauthorisedException.class).isThrownBy(() -> hook.preExecute(opChain, new Context(user))).extracting("message").isNotNull();
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class NamedOperationResolverTest method shouldResolveNamedOperation.
@Test
public void shouldResolveNamedOperation() throws CacheOperationFailedException {
// Given
final String opName = "opName";
final NamedOperationCache cache = mock(NamedOperationCache.class);
final NamedOperationResolver resolver = new NamedOperationResolver(cache);
final User user = mock(User.class);
final NamedOperationDetail extendedNamedOperation = mock(NamedOperationDetail.class);
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final OperationChain namedOperationOpChain = new OperationChain(Arrays.asList(op1, op2));
final Iterable<?> input = mock(CloseableIterable.class);
final Map<String, Object> params = null;
given(op1.getInput()).willReturn(null);
given(cache.getNamedOperation(opName, user)).willReturn(extendedNamedOperation);
given(extendedNamedOperation.getOperationChain(params)).willReturn(namedOperationOpChain);
final OperationChain<Object> opChain = new OperationChain.Builder().first(new NamedOperation.Builder<>().name(opName).input(input).build()).build();
// When
resolver.preExecute(opChain, new Context(user));
// Then
assertEquals(namedOperationOpChain.getOperations(), opChain.getOperations());
verify(op1).setInput((Iterable) input);
verify(op2, never()).setInput((Iterable) input);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.
the class NamedOperationResolverTest method shouldResolveNestedNamedOperation.
@Test
public void shouldResolveNestedNamedOperation() throws OperationException, CacheOperationFailedException {
// Given
final String opName = "opName";
final NamedOperationCache cache = mock(NamedOperationCache.class);
final NamedOperationResolver resolver = new NamedOperationResolver(cache);
final User user = mock(User.class);
final NamedOperationDetail extendedNamedOperation = mock(NamedOperationDetail.class);
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final OperationChain namedOperationOpChain = new OperationChain(Arrays.asList(op1, op2));
final Iterable<?> input = mock(CloseableIterable.class);
final Map<String, Object> params = null;
given(op1.getInput()).willReturn(null);
given(cache.getNamedOperation(opName, user)).willReturn(extendedNamedOperation);
given(extendedNamedOperation.getOperationChain(params)).willReturn(namedOperationOpChain);
final OperationChain<Object> opChain = new OperationChain.Builder().first(new OperationChain.Builder().first(new NamedOperation.Builder<>().name(opName).input(input).build()).build()).build();
// When
resolver.preExecute(opChain, new Context(user));
// Then
assertEquals(1, opChain.getOperations().size());
final OperationChain<?> nestedOpChain = (OperationChain<?>) opChain.getOperations().get(0);
assertEquals(namedOperationOpChain.getOperations(), nestedOpChain.getOperations());
verify(op1).setInput((Iterable) input);
verify(op2, never()).setInput((Iterable) input);
}
Aggregations