Search in sources :

Example 1 with Count

use of uk.gov.gchq.gaffer.operation.impl.Count in project Gaffer by gchq.

the class WhileScoreResolverTest method shouldGetScoreWithFullyPopulatedOperation.

@Test
public void shouldGetScoreWithFullyPopulatedOperation() {
    // Given
    final Object input = new EntitySeed(2);
    final Count count = mock(Count.class);
    final int repeats = 5;
    final GetElements getElements = mock(GetElements.class);
    final Conditional conditional = mock(Conditional.class);
    given(conditional.getTransform()).willReturn(count);
    final While operation = new While.Builder<>().input(input).conditional(conditional).maxRepeats(repeats).operation(getElements).build();
    final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Count.class, 1);
    opScores.put(GetElements.class, 2);
    final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
    final WhileScoreResolver resolver = new WhileScoreResolver();
    // When
    final int score = resolver.getScore(operation, defaultResolver);
    // Then
    assertEquals(15, score);
}
Also used : GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Count(uk.gov.gchq.gaffer.operation.impl.Count) While(uk.gov.gchq.gaffer.operation.impl.While) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Test(org.junit.jupiter.api.Test)

Example 2 with Count

use of uk.gov.gchq.gaffer.operation.impl.Count in project Gaffer by gchq.

the class AddOperationsToChainTest method shouldAddAllOperationsGivenJson.

@Test
public void shouldAddAllOperationsGivenJson() throws IOException {
    // Given
    final byte[] bytes;
    try (final InputStream inputStream = StreamUtil.openStream(getClass(), ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH)) {
        bytes = IOUtils.toByteArray(inputStream);
    }
    final AddOperationsToChain hook = fromJson(bytes);
    Operation discardOutput = new DiscardOutput();
    Operation splitStore = new SplitStoreFromFile();
    Operation validate = new Validate();
    Operation getAdjacentIds = new GetAdjacentIds();
    Operation count = new Count<>();
    Operation countGroups = new CountGroups();
    Operation getElements = new GetElements();
    Operation getAllElements = new GetAllElements();
    Operation limit = new Limit<>();
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getElements).then(getAllElements).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(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).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) InputStream(java.io.InputStream) 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) 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) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 3 with Count

use of uk.gov.gchq.gaffer.operation.impl.Count in project Gaffer by gchq.

the class AddOperationsToChainTest method shouldAddAllOperationsWithNoAuthsGivenPath.

@Test
public void shouldAddAllOperationsWithNoAuthsGivenPath() throws IOException {
    // 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 countGroups = new CountGroups();
    Operation getElements = new GetElements();
    Operation getAllElements = new GetAllElements();
    Operation limit = new Limit<>();
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getElements).then(getAllElements).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(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).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) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) 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) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 4 with Count

use of uk.gov.gchq.gaffer.operation.impl.Count in project Gaffer by gchq.

the class AddOperationsToChainTest method shouldClearListWhenAddingOperations.

@Test
public void shouldClearListWhenAddingOperations() throws IOException {
    // Given
    final AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
    hook.setBefore(null);
    hook.setAfter(null);
    Operation discardOutput = new DiscardOutput();
    Operation splitStore = new SplitStoreFromFile();
    Operation count = new Count<>();
    Operation getElements = new GetElements();
    final OperationChain opChain = new OperationChain.Builder().first(getElements).build();
    // When
    hook.preExecute(opChain, new Context(new User()));
    // Then
    final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(getElements).then(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) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) 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) Test(org.junit.jupiter.api.Test)

Example 5 with Count

use of uk.gov.gchq.gaffer.operation.impl.Count in project Gaffer by gchq.

the class AddOperationsToChainTest method shouldHandleNestedOperationChain.

@Test
public void shouldHandleNestedOperationChain() 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 countGroups = new CountGroups();
    Operation getElements = new GetElements();
    If ifOp = new If.Builder<>().conditional(new Conditional(new Exists(), new GetElements())).then(new GetElements()).otherwise(new GetAllElements()).build();
    Operation getAllElements = new GetAllElements();
    Operation limit = new Limit<>();
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(new OperationChain.Builder().first(getElements).then(getAllElements).build()).then(ifOp).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((Operation) new OperationChain.Builder().first(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).build()).then(new If.Builder<>().conditional(new Conditional(new Exists(), new OperationChain<>(new CountGroups(), new GetElements()))).then(new OperationChain<>(new CountGroups(), new GetElements())).otherwise(new OperationChain<>(new GetAllElements(), new Limit<>(), new Validate())).build()).then(new 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) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) 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) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) 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