use of uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldBeAbleToAddNamedOperationToCache.
private void shouldBeAbleToAddNamedOperationToCache() throws OperationException {
// given
GetAllNamedOperations get = new GetAllNamedOperations.Builder().build();
final Store store = mock(Store.class);
given(store.getProperties()).willReturn(properties);
// when
addNamedOperationHandler.doOperation(add, context, store);
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(add.getOperationName()).operationChain(add.getOperationChainAsString()).creatorId(user.getUserId()).description(add.getDescription()).score(0).parameters(null).build();
List<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
List<NamedOperationDetail> results = Lists.newArrayList(new GetAllNamedOperationsHandler().doOperation(get, context, store));
// then
assertThat(results).hasSize(1).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldAllowUpdatingOfNamedOperationsWithAllowedUsers.
private void shouldAllowUpdatingOfNamedOperationsWithAllowedUsers() throws OperationException {
// given
final Store store = mock(Store.class);
given(store.getProperties()).willReturn(properties);
new AddNamedOperationHandler().doOperation(add, context, store);
AddNamedOperation update = new AddNamedOperation.Builder().name(add.getOperationName()).description("a different operation").operationChain(add.getOperationChainAsString()).overwrite().score(0).build();
GetAllNamedOperations get = new GetAllNamedOperations();
// when
new AddNamedOperationHandler().doOperation(add, context, store);
List<NamedOperationDetail> results = Lists.newArrayList(getAllNamedOperationsHandler.doOperation(get, context, store));
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(update.getOperationName()).operationChain(update.getOperationChainAsString()).description(update.getDescription()).creatorId(user.getUserId()).score(0).parameters(null).build();
ArrayList<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
// then
assertThat(results).hasSameSizeAs(expected).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations in project Gaffer by gchq.
the class NamedOperationCacheIT method shouldAllowUpdatingOfNamedOperations.
private void shouldAllowUpdatingOfNamedOperations() throws OperationException {
// given
final Store store = mock(Store.class);
final StoreProperties storeProps = mock(StoreProperties.class);
given(store.getProperties()).willReturn(storeProps);
new AddNamedOperationHandler().doOperation(add, context, store);
AddNamedOperation update = new AddNamedOperation.Builder().name(add.getOperationName()).description("a different operation").operationChain(add.getOperationChainAsString()).overwrite().score(0).build();
GetAllNamedOperations get = new GetAllNamedOperations();
// when
new AddNamedOperationHandler().doOperation(add, context, store);
List<NamedOperationDetail> results = Lists.newArrayList(getAllNamedOperationsHandler.doOperation(get, context, store));
NamedOperationDetail expectedNamedOp = new NamedOperationDetail.Builder().operationName(update.getOperationName()).operationChain(update.getOperationChainAsString()).description(update.getDescription()).creatorId(user.getUserId()).score(0).parameters(null).build();
ArrayList<NamedOperationDetail> expected = Lists.newArrayList(expectedNamedOp);
// then
assertThat(results).hasSameSizeAs(expected).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations 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.GetAllNamedOperations 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);
}
Aggregations