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));
}
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));
}
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);
}
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();
}
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();
}
Aggregations