GetAllNamedOperationsHandler implements OutputOperationHandler<GetAllNamedOperations, CloseableIterable<NamedOperationDetail>> { @Override public CloseableIterable<NamedOperationDetail> doOperation(final GetAllNamedOperations operation, final Context context, final Store store) throws OperationException { final CloseableIterable<NamedOperationDetail> ops = cache.getAllNamedOperations(context.getUser(), store.getProperties().getAdminAuth()); return new WrappedCloseableIterable<>(IterableUtil.map(ops, new AddInputType())); } GetAllNamedOperationsHandler();  GetAllNamedOperationsHandler(final NamedOperationCache cache); @Override CloseableIterable<NamedOperationDetail> doOperation(final GetAllNamedOperations operation, final Context context, final Store store);  }
@Test public void shouldReturnLabelWhenNamedOperationHasLabel() throws Exception { final AddNamedOperation addNamedOperationWithLabel = 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(); addNamedOperationHandler.doOperation(addNamedOperationWithLabel, context, store); final CloseableIterable<NamedOperationDetail> allNamedOperations = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store); assertEquals(Arrays.asList("test label"), allNamedOperations.iterator().next().getLabels()); }
@Test public void shouldReturnNullLabelWhenLabelIsNullFromAddNamedOperationRequest() throws Exception { final AddNamedOperation addNamedOperationWithNullLabel = new AddNamedOperation.Builder() .name("My Operation With Label") .labels(null) .operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}") .build(); addNamedOperationHandler.doOperation(addNamedOperationWithNullLabel, context, store); final CloseableIterable<NamedOperationDetail> allNamedOperations = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store); assertEquals(null, allNamedOperations.iterator().next().getLabels()); }
@Test public void shouldReturnNamedOperationWithInputType() throws Exception { AddNamedOperation addNamedOperation = new AddNamedOperation.Builder() .name(expectedOperationDetailWithInputType.getOperationName()) .description(expectedOperationDetailWithInputType.getDescription()) .operationChain(expectedOperationDetailWithInputType.getOperationChainWithDefaultParams()) .build(); addNamedOperationHandler.doOperation(addNamedOperation, context, store); CloseableIterable<NamedOperationDetail> allNamedOperationsList = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store); assertEquals(1, Iterables.size(allNamedOperationsList)); assertTrue(Iterables.contains(allNamedOperationsList, expectedOperationDetailWithInputType)); }
@Test public void shouldReturnNamedOperationWithNoInputType() throws Exception { AddNamedOperation addNamedOperation = new AddNamedOperation.Builder() .name(expectedOperationDetailWithoutInputType.getOperationName()) .description(expectedOperationDetailWithoutInputType.getDescription()) .operationChain(expectedOperationDetailWithoutInputType.getOperationChainWithDefaultParams()) .build(); addNamedOperationHandler.doOperation(addNamedOperation, context, store); CloseableIterable<NamedOperationDetail> allNamedOperationsList = getAllNamedOperationsHandler.doOperation(new GetAllNamedOperations(), context, store); assertEquals(1, Iterables.size(allNamedOperationsList)); assertTrue(Iterables.contains(allNamedOperationsList, expectedOperationDetailWithoutInputType)); }