Search in sources :

Example 76 with GetElements

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

the class OperationChainLimiterTest method shouldAcceptOperationChainWhenUserHasAuthScoreGreaterThanChainScore.

@Test
public void shouldAcceptOperationChainWhenUserHasAuthScoreGreaterThanChainScore() {
    // Given
    final OperationChainLimiter hook = fromJson(OP_CHAIN_LIMITER_PATH);
    final OperationChain opChain = new OperationChain.Builder().first(new GetElements()).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) 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 77 with GetElements

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

the class OperationChainLimiterTest method shouldRejectOperationChainWhenUserHasAuthScoreLessThanChainScore.

@Test
public void shouldRejectOperationChainWhenUserHasAuthScoreLessThanChainScore() {
    // Given
    final OperationChainLimiter hook = fromJson(OP_CHAIN_LIMITER_PATH);
    final OperationChain opChain = new OperationChain.Builder().first(new GetAdjacentIds()).then(new GetAdjacentIds()).then(new GetAdjacentIds()).then(new GetElements()).then(new GenerateObjects<>()).build();
    final User user = new User.Builder().opAuths("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) 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) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.jupiter.api.Test)

Example 78 with GetElements

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

the class OperationChainLimiterTest method shouldRejectOperationChainWhenUserHasMaxAuthScoreLessThanChainScore.

@Test
public void shouldRejectOperationChainWhenUserHasMaxAuthScoreLessThanChainScore() {
    // Given
    final OperationChainLimiter hook = fromJson(OP_CHAIN_LIMITER_PATH);
    final OperationChain opChain = new OperationChain.Builder().first(new GetAllElements()).then(new GetElements()).then(new GenerateObjects<>()).build();
    final User user = new User.Builder().opAuths("SuperUser", "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) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.jupiter.api.Test)

Example 79 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements 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 80 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements 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)

Aggregations

GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)256 Test (org.junit.jupiter.api.Test)153 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)112 User (uk.gov.gchq.gaffer.user.User)102 Element (uk.gov.gchq.gaffer.data.element.Element)91 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)84 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)83 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)67 Context (uk.gov.gchq.gaffer.store.Context)60 Test (org.junit.Test)56 HashSet (java.util.HashSet)52 Graph (uk.gov.gchq.gaffer.graph.Graph)49 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)46 Entity (uk.gov.gchq.gaffer.data.element.Entity)42 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)38 Operation (uk.gov.gchq.gaffer.operation.Operation)35 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)35 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)34 Edge (uk.gov.gchq.gaffer.data.element.Edge)32 ArrayList (java.util.ArrayList)31