Search in sources :

Example 11 with TypeSubTypeValue

use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.

the class TypeSubTypeValueToTupleTest method shouldConvertTypeSubTypeValueToTuple.

@Test
public void shouldConvertTypeSubTypeValueToTuple() {
    // Given
    final TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue("type", "subType", "value");
    final TypeSubTypeValueToTuple function = getInstance();
    // When
    final Tuple<String> result = function.apply(typeSubTypeValue);
    // Then
    assertEquals("type", result.get("type"));
    assertEquals("value", result.get("value"));
}
Also used : TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue) ToString(uk.gov.gchq.koryphe.impl.function.ToString) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest) Test(org.junit.jupiter.api.Test)

Example 12 with TypeSubTypeValue

use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.

the class GetElementsTest method shouldDeserialiseOperationWithVerticesAndIds.

@Test
public void shouldDeserialiseOperationWithVerticesAndIds() throws SerialisationException {
    // Given
    final String json = String.format("{\"class\":\"uk.gov.gchq.gaffer.operation.impl.get.GetElements\"," + "\"input\":[" + "1," + "{\"class\":\"uk.gov.gchq.gaffer.types.TypeSubTypeValue\",\"type\":\"t\",\"subType\":\"s\",\"value\":\"v\"}," + "{\"vertex\":{\"java.lang.Long\":2},\"class\":\"uk.gov.gchq.gaffer.operation.data.EntitySeed\"}" + "]}");
    // When
    final GetElements deserialisedOp = JSONSerialiser.deserialise(json, GetElements.class);
    // Then
    assertEquals(Lists.newArrayList(new EntitySeed(1), new EntitySeed(new TypeSubTypeValue("t", "s", "v")), new EntitySeed(2L)), Lists.newArrayList(deserialisedOp.getInput()));
}
Also used : TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 13 with TypeSubTypeValue

use of uk.gov.gchq.gaffer.types.TypeSubTypeValue 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)

Example 14 with TypeSubTypeValue

use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.

the class TypeSubTypeValueSerialiser method deserialise.

@Override
public TypeSubTypeValue deserialise(final byte[] bytes) throws SerialisationException {
    int lastDelimiter = 0;
    TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue();
    for (int i = 0; i < bytes.length; i++) {
        if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) {
            if (i > 0) {
                try {
                    typeSubTypeValue.setType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8));
                } catch (final UnsupportedEncodingException e) {
                    throw new SerialisationException("Failed to deserialise the Type from TypeSubTypeValue Object", e);
                }
            }
            lastDelimiter = i + 1;
            break;
        }
    }
    for (int i = lastDelimiter; i < bytes.length; i++) {
        if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) {
            if (i > lastDelimiter) {
                try {
                    typeSubTypeValue.setSubType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8));
                } catch (final UnsupportedEncodingException e) {
                    throw new SerialisationException("Failed to deserialise the SubType from TypeSubTypeValue Object", e);
                }
            }
            lastDelimiter = i + 1;
            break;
        }
    }
    if (bytes.length > lastDelimiter) {
        try {
            typeSubTypeValue.setValue(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, bytes.length), CommonConstants.UTF_8));
        } catch (final UnsupportedEncodingException e) {
            throw new SerialisationException("Failed to deserialise the Value from TypeSubTypeValue Object", e);
        }
    }
    return typeSubTypeValue;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 15 with TypeSubTypeValue

use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.

the class GetElementsTest method shouldDeserialiseOperationWithVertices.

@Test
public void shouldDeserialiseOperationWithVertices() throws SerialisationException {
    // Given
    final String json = "{\"class\":\"uk.gov.gchq.gaffer.operation.impl.get.GetElements\"," + "\"input\":[" + "1," + "{\"class\":\"uk.gov.gchq.gaffer.types.TypeSubTypeValue\",\"type\":\"t\",\"subType\":\"s\",\"value\":\"v\"}," + "[\"java.lang.Long\",2]" + "]}";
    // When
    final GetElements deserialisedOp = JSONSerialiser.deserialise(json, GetElements.class);
    // Then
    assertEquals(Lists.newArrayList(new EntitySeed(1), new EntitySeed(new TypeSubTypeValue("t", "s", "v")), new EntitySeed(2L)), Lists.newArrayList(deserialisedOp.getInput()));
}
Also used : TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Aggregations

TypeSubTypeValue (uk.gov.gchq.gaffer.types.TypeSubTypeValue)21 Test (org.junit.jupiter.api.Test)18 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)6 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 FunctionComposite (uk.gov.gchq.koryphe.function.FunctionComposite)2 ToString (uk.gov.gchq.koryphe.impl.function.ToString)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Pair (uk.gov.gchq.gaffer.commonutil.pair.Pair)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 CallMethod (uk.gov.gchq.koryphe.impl.function.CallMethod)1 DivideBy (uk.gov.gchq.koryphe.impl.function.DivideBy)1 FirstItem (uk.gov.gchq.koryphe.impl.function.FirstItem)1 Length (uk.gov.gchq.koryphe.impl.function.Length)1 ToInteger (uk.gov.gchq.koryphe.impl.function.ToInteger)1 ToLong (uk.gov.gchq.koryphe.impl.function.ToLong)1 TupleAdaptedFunctionComposite (uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunctionComposite)1