use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class ScoreOperationChainHandlerTest method shouldCorrectlyExecuteScoreOperationChainWhenNamedOperationScoreIsNull.
@Test
public void shouldCorrectlyExecuteScoreOperationChainWhenNamedOperationScoreIsNull() throws OperationException {
// Given
final ScoreOperationChainHandler handler = new ScoreOperationChainHandler();
final Map<Class<? extends Operation>, ScoreResolver> resolvers = new HashMap<>();
final ScoreResolver scoreResolver = mock(NamedOperationScoreResolver.class);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final ScoreOperationChain scoreOperationChain = mock(ScoreOperationChain.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final Limit op3 = mock(Limit.class);
final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(GetAdjacentIds.class, 3);
opScores.put(GetElements.class, 2);
opScores.put(Limit.class, 1);
handler.setOpScores(opScores);
final String opName = "basicOp";
final NamedOperation<Iterable<? extends Element>, Iterable<? extends Element>> namedOp = mock(NamedOperation.class);
namedOp.setOperationName(opName);
resolvers.put(namedOp.getClass(), scoreResolver);
handler.setScoreResolvers(resolvers);
given(scoreResolver.getScore(eq(namedOp), any())).willReturn(null);
final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2, op3, namedOp));
given(context.getUser()).willReturn(user);
Set<String> opAuths = new HashSet<>();
opAuths.add("TEST_USER");
given(user.getOpAuths()).willReturn(opAuths);
given(scoreOperationChain.getOperationChain()).willReturn(opChain);
given(store.getProperties()).willReturn(storeProperties);
// When
final Object result = handler.doOperation(new ScoreOperationChain.Builder().operationChain(opChain).build(), context, store);
// Then
assertEquals(7, result);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class GraphHooksIT method shouldResolveNamedViewWithinNamedOperation.
@Test
public void shouldResolveNamedViewWithinNamedOperation() throws OperationException {
// Given
final Edge edge1 = getEdges().get(new EdgeSeed(SOURCE_1, DEST_1, false)).emptyClone();
edge1.putProperty(TestPropertyNames.INT, 100);
final Edge edge2 = edge1.emptyClone();
edge2.putProperty(TestPropertyNames.INT, 101);
graph.execute(new AddElements.Builder().input(edge1, edge2).build(), getUser());
final AddNamedView addNamedView = new AddNamedView.Builder().name("Test View").view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsIn(Arrays.asList((Object) 100))).build()).build()).build()).overwrite(true).build();
graph.execute(addNamedView, getUser());
final AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().operationChain(new OperationChain.Builder().first(new GetAllElements.Builder().view(new NamedView.Builder().name("Test View").build()).build()).build()).description("named operation GetAllElements test query").name("GetAllElements test").labels(Arrays.asList("label 1", "Label 2")).overwrite(true).build();
graph.execute(addNamedOperation, getUser());
final NamedOperation<EntityId, CloseableIterable<? extends Element>> operation = new NamedOperation.Builder<EntityId, CloseableIterable<? extends Element>>().name("GetAllElements test").input(new EntitySeed("10")).build();
// When
final CloseableIterable<? extends Element> results = graph.execute(operation, getUser());
// Then
final List<Element> resultList = Lists.newArrayList(results);
assertThat(resultList).hasSize(1).contains((Element) edge1);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class AddNamedOperationHandlerTest method shouldNotAllowUpdateToNamedOperationIfItCausesRecursion.
@Test
public void shouldNotAllowUpdateToNamedOperationIfItCausesRecursion() throws OperationException {
String innocentOpName = "innocent";
OperationChain innocent = new OperationChain.Builder().first(new GetElements<>()).build();
addNamedOperation.setOperationName(innocentOpName);
addNamedOperation.setOperationChain(innocent);
handler.doOperation(addNamedOperation, context, store);
OperationChain parent = new OperationChain.Builder().first(new NamedOperation(innocentOpName, "call down to currently innocent named op")).build();
addNamedOperation.setOperationChain(parent);
addNamedOperation.setOperationName(OPERATION_NAME);
handler.doOperation(addNamedOperation, context, store);
OperationChain recursive = new OperationChain.Builder().first(new NamedOperation(OPERATION_NAME, "")).build();
addNamedOperation.setOperationName(innocentOpName);
addNamedOperation.setOperationChain(recursive);
addNamedOperation.setOverwriteFlag(true);
exception.expect(OperationException.class);
handler.doOperation(addNamedOperation, context, store);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class NamedOperationJCSCacheTest method shouldReturnSetOfNamedOperationsThatAUserCanExecute.
@Test
public void shouldReturnSetOfNamedOperationsThatAUserCanExecute() throws CacheOperationFailedException {
cache.addNamedOperation(standard, false, standardUser);
ExtendedNamedOperation alt = alternative;
alt.setOperationName("alt");
cache.addNamedOperation(alt, false, advancedUser);
Set<NamedOperation> actual = Sets.newHashSet(cache.getAllNamedOperations(standardUser, true));
assert (actual.contains(standard.getBasic()));
assert (actual.contains(alt.getBasic()));
assert (actual.size() == 2);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperation in project Gaffer by gchq.
the class NamedOperationJCSCacheTest method shouldNotReturnANamedOperationThatAUserCannotExecute.
@Test
public void shouldNotReturnANamedOperationThatAUserCannotExecute() throws CacheOperationFailedException {
cache.addNamedOperation(standard, false, standardUser);
ExtendedNamedOperation noReadAccess = new ExtendedNamedOperation.Builder().creatorId(advancedUser.getUserId()).description("an operation that a standard user cannot execute").operationName("test").readers(writers).writers(writers).operationChain(standardOpChain).build();
cache.addNamedOperation(noReadAccess, false, advancedUser);
Set<NamedOperation> actual = Sets.newHashSet(cache.getAllNamedOperations(standardUser, true));
assert (actual.contains(standard.getBasic()));
assert (actual.size() == 1);
}
Aggregations