Search in sources :

Example 41 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.

the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveAnyOpAuths.

@Test
public void shouldRejectOperationChainWhenUserDoesntHaveAnyOpAuths() 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();
    // 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 42 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.

the class OperationChainLimiterTest method shouldAcceptOperationChainWhenUserHasAuthScoreEqualToChainScore.

@Test
public void shouldAcceptOperationChainWhenUserHasAuthScoreEqualToChainScore() {
    // Given
    final OperationChainLimiter hook = fromJson(OP_CHAIN_LIMITER_PATH);
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetElements()).then(new GenerateObjects<>()).build();
    final User user = new User.Builder().opAuths("User").build();
    // When
    hook.preExecute(opChain, new Context(user));
// Then - no exceptions
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) 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) Test(org.junit.jupiter.api.Test)

Example 43 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.

the class OperationChainLimiterTest method shouldAcceptOperationChainWhenUserHasMaxAuthScoreGreaterThanChainScore.

@Test
public void shouldAcceptOperationChainWhenUserHasMaxAuthScoreGreaterThanChainScore() {
    // Given
    final OperationChainLimiter hook = fromJson(OP_CHAIN_LIMITER_PATH);
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetAdjacentIds()).then(new GetElements()).then(new GenerateObjects<>()).build();
    final User user = new User.Builder().opAuths("SuperUser", "User").build();
    // When
    hook.preExecute(opChain, new Context(user));
// Then - no exceptions
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) 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) Test(org.junit.jupiter.api.Test)

Example 44 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.

the class AddNamedOperationTest method shouldGetOperationsWhenNoDefaultParameter.

@Test
public void shouldGetOperationsWhenNoDefaultParameter() {
    // Given
    final AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().operationChain("{\"operations\":[{\"class\": \"uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds\", \"input\": [{\"vertex\": \"${testParameter}\", \"class\": \"uk.gov.gchq.gaffer.operation.data.EntitySeed\"}]}]}").description("Test Named Operation").name("Test").labels(asList("Test label")).overwrite(false).readAccessRoles(USER).writeAccessRoles(USER).parameter("testParameter", new ParameterDetail.Builder().description("the seed").valueClass(String.class).required(false).build()).score(2).build();
    // When
    Collection<Operation> operations = addNamedOperation.getOperations();
    // Then
    assertEquals(Collections.singletonList(GetAdjacentIds.class), operations.stream().map(o -> o.getClass()).collect(Collectors.toList()));
    final GetAdjacentIds nestedOp = (GetAdjacentIds) operations.iterator().next();
    final List<? extends EntityId> input = Lists.newArrayList(nestedOp.getInput());
    assertEquals(Collections.singletonList(new EntitySeed(null)), input);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 45 with GetAdjacentIds

use of uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds in project Gaffer by gchq.

the class AddNamedOperationTest method shouldGetOperationsWithDefaultParameters.

@Test
public void shouldGetOperationsWithDefaultParameters() {
    // Given
    final AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().operationChain("{\"operations\":[{\"class\": \"uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds\", \"input\": [{\"vertex\": \"${testParameter}\", \"class\": \"uk.gov.gchq.gaffer.operation.data.EntitySeed\"}]}]}").description("Test Named Operation").name("Test").labels(asList("Test label")).overwrite(false).readAccessRoles(USER).writeAccessRoles(USER).parameter("testParameter", new ParameterDetail.Builder().description("the seed").defaultValue("seed1").valueClass(String.class).required(false).build()).score(2).build();
    // When
    Collection<Operation> operations = addNamedOperation.getOperations();
    // Then
    assertEquals(Collections.singletonList(GetAdjacentIds.class), operations.stream().map(o -> o.getClass()).collect(Collectors.toList()));
    final GetAdjacentIds nestedOp = (GetAdjacentIds) operations.iterator().next();
    final List<? extends EntityId> input = Lists.newArrayList(nestedOp.getInput());
    assertEquals(Collections.singletonList(new EntitySeed("seed1")), input);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) 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