Search in sources :

Example 1 with DivideBy

use of uk.gov.gchq.koryphe.impl.function.DivideBy in project Gaffer by gchq.

the class FunctionAuthoriserTest method shouldNotAllowGetElementsOperationWithUnauthorisedFunctionsInTheView.

@Test
public void shouldNotAllowGetElementsOperationWithUnauthorisedFunctionsInTheView() {
    final OperationChain<CloseableIterable<? extends Element>> viewOperation = new OperationChain.Builder().first(new GetElements.Builder().view(new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().transformFunctions(Lists.newArrayList(new TupleAdaptedFunction(new String[] { "input" }, new DivideBy(6), new String[] { "output" }))).build()).build()).build()).build();
    FunctionAuthoriser functionAuthoriser = new FunctionAuthoriser();
    // When
    functionAuthoriser.setUnauthorisedFunctions(Lists.newArrayList(DivideBy.class));
    // Then
    assertThatExceptionOfType(UnauthorisedException.class).isThrownBy(() -> functionAuthoriser.preExecute(viewOperation, new Context())).withMessage("Operation chain contained an unauthorised function: uk.gov.gchq.koryphe.impl.function.DivideBy");
}
Also used : DivideBy(uk.gov.gchq.koryphe.impl.function.DivideBy) Context(uk.gov.gchq.gaffer.store.Context) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) TupleAdaptedFunction(uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction) ToString(uk.gov.gchq.koryphe.impl.function.ToString) Test(org.junit.jupiter.api.Test)

Example 2 with DivideBy

use of uk.gov.gchq.koryphe.impl.function.DivideBy in project Gaffer by gchq.

the class KeyFunctionMatchTest method shouldThrowExceptionFromFunctionIfInputIsInvalid.

@Test
public void shouldThrowExceptionFromFunctionIfInputIsInvalid() {
    // given
    // Performing a FirstItem on null should throw IllegalArgumentException
    List<Long> testList = Lists.newArrayList(100L, 200L, 300L, null);
    // when
    KeyFunctionMatch match = new KeyFunctionMatch.Builder().firstKeyFunction(new FunctionComposite(Lists.newArrayList(new CallMethod("getValue"), new ToInteger()))).secondKeyFunction(new FunctionComposite(Lists.newArrayList(new ToInteger(), new DivideBy(10), new FirstItem<>()))).build();
    // then
    try {
        match.init(testList);
    } catch (final IllegalArgumentException e) {
        // copied from docs of FirstItem
        assertEquals("Input cannot be null", e.getMessage());
    }
}
Also used : DivideBy(uk.gov.gchq.koryphe.impl.function.DivideBy) ToInteger(uk.gov.gchq.koryphe.impl.function.ToInteger) ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) FirstItem(uk.gov.gchq.koryphe.impl.function.FirstItem) FunctionComposite(uk.gov.gchq.koryphe.function.FunctionComposite) CallMethod(uk.gov.gchq.koryphe.impl.function.CallMethod) Test(org.junit.jupiter.api.Test)

Example 3 with DivideBy

use of uk.gov.gchq.koryphe.impl.function.DivideBy in project gaffer-doc by gchq.

the class DivideByExample method divideBy2.

public void divideBy2() {
    // ---------------------------------------------------------
    final DivideBy function = new DivideBy(2);
    // ---------------------------------------------------------
    runExample(function, null, 6, 5, null, 6.1);
}
Also used : DivideBy(uk.gov.gchq.koryphe.impl.function.DivideBy)

Example 4 with DivideBy

use of uk.gov.gchq.koryphe.impl.function.DivideBy in project Gaffer by gchq.

the class KeyFunctionMatchTest method shouldJsonSerialiseAndDeserialiseWithKeyFunctions.

@Test
public void shouldJsonSerialiseAndDeserialiseWithKeyFunctions() throws SerialisationException {
    // given
    KeyFunctionMatch match = new KeyFunctionMatch.Builder().firstKeyFunction(new FunctionComposite(Lists.newArrayList(new DivideBy(20), new FirstItem()))).secondKeyFunction(new ExtractProperty("count")).build();
    // when / then
    String expected = "{\n" + "  \"class\" : \"uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch\",\n" + "  \"firstKeyFunction\" : {\n" + "    \"class\" : \"uk.gov.gchq.koryphe.function.FunctionComposite\",\n" + "    \"functions\" : [ {\n" + "      \"class\" : \"uk.gov.gchq.koryphe.impl.function.DivideBy\",\n" + "      \"by\" : 20\n" + "    }, {\n" + "      \"class\" : \"uk.gov.gchq.koryphe.impl.function.FirstItem\"\n" + "    } ]\n" + "  },\n" + "  \"secondKeyFunction\" : {\n" + "    \"class\" : \"uk.gov.gchq.gaffer.data.element.function.ExtractProperty\",\n" + "    \"name\" : \"count\"\n" + "  }\n" + "}";
    assertEquals(expected, new String(JSONSerialiser.serialise(match, true)));
    assertEquals(match, JSONSerialiser.deserialise(expected, KeyFunctionMatch.class));
}
Also used : DivideBy(uk.gov.gchq.koryphe.impl.function.DivideBy) FirstItem(uk.gov.gchq.koryphe.impl.function.FirstItem) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) FunctionComposite(uk.gov.gchq.koryphe.function.FunctionComposite) Test(org.junit.jupiter.api.Test)

Example 5 with DivideBy

use of uk.gov.gchq.koryphe.impl.function.DivideBy in project Gaffer by gchq.

the class KeyFunctionMatchTest method shouldMatchObjectsBasedOnKeyFunctions.

@Test
public void shouldMatchObjectsBasedOnKeyFunctions() {
    // given
    TypeSubTypeValue testValue = new TypeSubTypeValue("myType", "mySubType", "30");
    List<Long> testList = Lists.newArrayList(100L, 200L, 300L, 400L);
    // when
    KeyFunctionMatch match = new KeyFunctionMatch.Builder().firstKeyFunction(new FunctionComposite(Lists.newArrayList(new CallMethod("getValue"), new ToInteger()))).secondKeyFunction(new FunctionComposite(Lists.newArrayList(new ToInteger(), new DivideBy(10), new FirstItem<>()))).build();
    match.init(testList);
    // then
    List<Long> expected = Lists.newArrayList(300L);
    assertEquals(expected, match.matching(testValue));
}
Also used : DivideBy(uk.gov.gchq.koryphe.impl.function.DivideBy) TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue) ToInteger(uk.gov.gchq.koryphe.impl.function.ToInteger) ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) FirstItem(uk.gov.gchq.koryphe.impl.function.FirstItem) FunctionComposite(uk.gov.gchq.koryphe.function.FunctionComposite) CallMethod(uk.gov.gchq.koryphe.impl.function.CallMethod) Test(org.junit.jupiter.api.Test)

Aggregations

DivideBy (uk.gov.gchq.koryphe.impl.function.DivideBy)5 Test (org.junit.jupiter.api.Test)4 FunctionComposite (uk.gov.gchq.koryphe.function.FunctionComposite)3 FirstItem (uk.gov.gchq.koryphe.impl.function.FirstItem)3 CallMethod (uk.gov.gchq.koryphe.impl.function.CallMethod)2 ToInteger (uk.gov.gchq.koryphe.impl.function.ToInteger)2 ToLong (uk.gov.gchq.koryphe.impl.function.ToLong)2 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 ExtractProperty (uk.gov.gchq.gaffer.data.element.function.ExtractProperty)1 Context (uk.gov.gchq.gaffer.store.Context)1 TypeSubTypeValue (uk.gov.gchq.gaffer.types.TypeSubTypeValue)1 ToString (uk.gov.gchq.koryphe.impl.function.ToString)1 TupleAdaptedFunction (uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction)1