Search in sources :

Example 6 with Count

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Element(uk.gov.gchq.gaffer.data.element.Element) Store(uk.gov.gchq.gaffer.store.Store) Count(uk.gov.gchq.gaffer.operation.impl.Count) Test(org.junit.jupiter.api.Test)

Example 7 with Count

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));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) Count(uk.gov.gchq.gaffer.operation.impl.Count) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) TestUnmodifiableOperationsImpl(uk.gov.gchq.gaffer.operation.TestUnmodifiableOperationsImpl) Test(org.junit.jupiter.api.Test)

Example 8 with Count

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));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) Count(uk.gov.gchq.gaffer.operation.impl.Count) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 9 with Count

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);
}
Also used : GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Count(uk.gov.gchq.gaffer.operation.impl.Count) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)9 Count (uk.gov.gchq.gaffer.operation.impl.Count)9 Operation (uk.gov.gchq.gaffer.operation.Operation)8 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)7 Context (uk.gov.gchq.gaffer.store.Context)7 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)6 SplitStoreFromFile (uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile)6 User (uk.gov.gchq.gaffer.user.User)6 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)5 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)4 Validate (uk.gov.gchq.gaffer.operation.impl.Validate)4 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)4 If (uk.gov.gchq.gaffer.operation.impl.If)3 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)3 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)3 LinkedHashMap (java.util.LinkedHashMap)2 InputStream (java.io.InputStream)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 TestUnmodifiableOperationsImpl (uk.gov.gchq.gaffer.operation.TestUnmodifiableOperationsImpl)1