Search in sources :

Example 11 with AddNamedOperation

use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.

the class AddNamedOperationHandlerTest method shouldNotAllowForNonRecursiveNamedOperationsToBeNested.

@Test
public void shouldNotAllowForNonRecursiveNamedOperationsToBeNested() throws OperationException {
    OperationChain child = new OperationChain.Builder().first(new AddElements()).build();
    addNamedOperation.setOperationChain(child);
    addNamedOperation.setOperationName("child");
    handler.doOperation(addNamedOperation, context, store);
    OperationChain parent = new OperationChain.Builder().first(new NamedOperation.Builder().name("child").build()).then(new GetElements()).build();
    addNamedOperation.setOperationChain(parent);
    addNamedOperation.setOperationName("parent");
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(addNamedOperation, context, store));
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Test(org.junit.jupiter.api.Test)

Example 12 with AddNamedOperation

use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.

the class GetAllNamedOperationsHandlerTest method shouldReturnNamedOperationWithNoInputType.

@Test
public void shouldReturnNamedOperationWithNoInputType() throws Exception {
    // Given
    AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().name(expectedOperationDetailWithoutInputType.getOperationName()).description(expectedOperationDetailWithoutInputType.getDescription()).operationChain(expectedOperationDetailWithoutInputType.getOperationChainWithDefaultParams()).build();
    addNamedOperationHandler.doOperation(addNamedOperation, context, store);
    // When
    CloseableIterable<NamedOperationDetail> allNamedOperationsList = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store);
    // Then
    assertEquals(1, Iterables.size(allNamedOperationsList));
    assertTrue(Iterables.contains(allNamedOperationsList, expectedOperationDetailWithoutInputType));
}
Also used : GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) Test(org.junit.jupiter.api.Test)

Example 13 with AddNamedOperation

use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.

the class OperationServiceIT method shouldReturnNamedOpDetailWithLabelWhenLabelIsAddedToNamedOp.

@Test
public void shouldReturnNamedOpDetailWithLabelWhenLabelIsAddedToNamedOp() throws Exception {
    // Given
    final AddNamedOperation namedOperation = new AddNamedOperation.Builder().name("My Operation With Label").labels(Arrays.asList("test label")).operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}").build();
    client.executeOperation(namedOperation);
    // When
    final Response response = client.executeOperation(new GetAllNamedOperations());
    final List<NamedOperationDetail> namedOperationDetails = response.readEntity(new GenericType<List<NamedOperationDetail>>() {
    });
    // Then
    final NamedOperationDetail expected = new NamedOperationDetail.Builder().operationName("My Operation With Label").labels(Arrays.asList("test label")).operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}").inputType("uk.gov.gchq.gaffer.data.element.Element[]").creatorId("UNKNOWN").parameters(null).build();
    assertThat(namedOperationDetails.iterator().next()).isEqualTo(expected);
}
Also used : Response(javax.ws.rs.core.Response) GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedOperationDetail(uk.gov.gchq.gaffer.named.operation.NamedOperationDetail) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 14 with AddNamedOperation

use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.

the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveWriteAuthForAddNamedOperation.

@Test
public void shouldRejectOperationChainWhenUserDoesntHaveWriteAuthForAddNamedOperation() {
    // Given
    final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
    final AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().operationChain("{\"operations\":[{\"class\": \"uk.gov.gchq.gaffer.operation.impl.get.AddElements\", \"options\": {\"optionKey\": \"${testParameter}\"}}]}").description("Test Named Operation").name("Test").overwrite(false).parameter("testParameter", new ParameterDetail.Builder().description("the seed").defaultValue("seed1").valueClass(String.class).required(false).build()).score(2).build();
    final OperationChain opChain = new OperationChain.Builder().first(addNamedOperation).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) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.jupiter.api.Test)

Example 15 with AddNamedOperation

use of uk.gov.gchq.gaffer.named.operation.AddNamedOperation in project Gaffer by gchq.

the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveAllOpAuthsForAddNamedOperation.

@Test
public void shouldRejectOperationChainWhenUserDoesntHaveAllOpAuthsForAddNamedOperation() {
    // Given
    final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
    final AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().operationChain("{\"operations\":[{\"class\": \"uk.gov.gchq.gaffer.operation.impl.get.GetAllElements\", \"options\": {\"optionKey\": \"${testParameter}\"}}]}").description("Test Named Operation").name("Test").overwrite(false).parameter("testParameter", new ParameterDetail.Builder().description("the seed").defaultValue("seed1").valueClass(String.class).required(false).build()).score(2).build();
    final OperationChain opChain = new OperationChain.Builder().first(addNamedOperation).build();
    final User user = new User.Builder().opAuths("SuperUser", "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) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) UnauthorisedException(uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException) Test(org.junit.jupiter.api.Test)

Aggregations

AddNamedOperation (uk.gov.gchq.gaffer.named.operation.AddNamedOperation)25 Test (org.junit.jupiter.api.Test)10 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)10 NamedOperationDetail (uk.gov.gchq.gaffer.named.operation.NamedOperationDetail)9 GetAllNamedOperations (uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations)8 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)7 Test (org.junit.Test)5 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)5 Context (uk.gov.gchq.gaffer.store.Context)5 User (uk.gov.gchq.gaffer.user.User)5 ExtendedNamedOperation (uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation)4 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)4 UnauthorisedException (uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException)3 ParameterDetail (uk.gov.gchq.gaffer.named.operation.ParameterDetail)3 OperationException (uk.gov.gchq.gaffer.operation.OperationException)3 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2