use of uk.gov.gchq.gaffer.operation.impl.Count in project Gaffer by gchq.
the class CountHandlerTest method shouldReturnCount.
@Test
public void shouldReturnCount() throws OperationException {
// Given
final CountHandler handler = new CountHandler();
final Store store = mock(Store.class);
final Count count = mock(Count.class);
final CloseableIterable<Element> elements = CountGroupsHandlerTest.getElements();
final Context context = new Context();
given(count.getInput()).willReturn(elements);
// When
final Long result = handler.doOperation(count, context, store);
// Then
assertEquals(8L, (long) result);
}
use of uk.gov.gchq.gaffer.operation.impl.Count in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldFailQuietlyIfNestedOperationsCannotBeModified.
@Test
public void shouldFailQuietlyIfNestedOperationsCannotBeModified() throws SerialisationException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation validate = new Validate();
Operation getAdjacentIds = new GetAdjacentIds();
Operation count = new Count<>();
Operation getElements = new GetElements();
Operation getAllElements = new GetAllElements();
TestUnmodifiableOperationsImpl nestedUnmodifiableOps = new TestUnmodifiableOperationsImpl(Arrays.asList(getAllElements, getElements));
final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(nestedUnmodifiableOps).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then(nestedUnmodifiableOps).then(count).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.Count in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldHandleIfOperationWithNoConditionalOrOtherwise.
@Test
public void shouldHandleIfOperationWithNoConditionalOrOtherwise() throws SerialisationException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
If ifOp = new If.Builder<>().then(new GetElements()).build();
final OperationChain opChain = new OperationChain.Builder().first(ifOp).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(new If.Builder<>().then(new OperationChain<>(new CountGroups(), new GetElements())).build()).then(new Count()).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.Count in project Gaffer by gchq.
the class IfScoreResolverTest method shouldGetScoreWithFullyPopulatedOperation.
@Test
public void shouldGetScoreWithFullyPopulatedOperation() {
// Given
final Count count = mock(Count.class);
final GetAllElements getAllElements = mock(GetAllElements.class);
final GetWalks getWalks = mock(GetWalks.class);
final Conditional conditional = mock(Conditional.class);
given(conditional.getTransform()).willReturn(count);
final If operation = new If.Builder<>().conditional(conditional).then(getWalks).otherwise(getAllElements).build();
final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
opScores.put(Count.class, 1);
opScores.put(GetAllElements.class, 3);
opScores.put(GetWalks.class, 4);
final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
final IfScoreResolver resolver = new IfScoreResolver();
// When
final int score = resolver.getScore(operation, defaultResolver);
// Then
assertEquals(4, score);
}
Aggregations