Search in sources :

Example 36 with GetAdjacentIds

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

Example 37 with GetAdjacentIds

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();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.jupiter.api.Test)

Example 38 with GetAdjacentIds

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();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.jupiter.api.Test)

Example 39 with GetAdjacentIds

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);
}
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) NamedOperationCache(uk.gov.gchq.gaffer.store.operation.handler.named.cache.NamedOperationCache) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Test(org.junit.jupiter.api.Test)

Example 40 with GetAdjacentIds

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);
}
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) NamedOperationCache(uk.gov.gchq.gaffer.store.operation.handler.named.cache.NamedOperationCache) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) 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