Search in sources :

Example 1 with NTList

use of org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList in project neo4j by neo4j.

the class ProcedureCompilationTest method shouldCallMethodWithCompositeParameters.

@Test
void shouldCallMethodWithCompositeParameters() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("l", NTList(NTAny)).out(NTString).build();
    // When
    CallableUserFunction concatMethod = compileFunction(signature, emptyList(), method("concat", List.class));
    // Then
    assertEquals(stringValue("421.1true"), concatMethod.apply(ctx, new AnyValue[] { list(longValue(42), doubleValue(1.1), TRUE) }));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) NTList(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 2 with NTList

use of org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList in project neo4j by neo4j.

the class ProcedureCompilationTest method shouldHandleNumberOutput.

@Test
void shouldHandleNumberOutput() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("numbers", NTList(NTNumber)).out(NTNumber).build();
    // When
    CallableUserFunction sumMethod = compileFunction(signature, emptyList(), method("sum", List.class));
    // Then
    assertEquals(longValue(3), sumMethod.apply(ctx, new AnyValue[] { list(longValue(1), longValue(2)) }));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) NTList(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 3 with NTList

use of org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList in project neo4j by neo4j.

the class ListConverterTest method shouldHandleNestedLists.

@SuppressWarnings("unchecked")
@Test
void shouldHandleNestedLists() {
    // Given
    ParameterizedType type = mock(ParameterizedType.class);
    when(type.getActualTypeArguments()).thenReturn(new Type[] { Object.class });
    ListConverter converter = new ListConverter(type, NTList(NTAny), expressionEvaluator());
    String mapString = "[42, [42, 1337]]";
    // When
    DefaultParameterValue converted = converter.apply(mapString);
    // Then
    List<Object> list = (List<Object>) converted.value();
    assertThat(list.get(0)).isEqualTo(42L);
    assertThat(list.get(1)).isEqualTo(asList(42L, 1337L));
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) DefaultParameterValue(org.neo4j.internal.kernel.api.procs.DefaultParameterValue) Collections.emptyList(java.util.Collections.emptyList) DefaultParameterValue.ntList(org.neo4j.internal.kernel.api.procs.DefaultParameterValue.ntList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) NTList(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) Test(org.junit.jupiter.api.Test)

Aggregations

Arrays.asList (java.util.Arrays.asList)3 Collections.emptyList (java.util.Collections.emptyList)3 Collections.singletonList (java.util.Collections.singletonList)3 List (java.util.List)3 Test (org.junit.jupiter.api.Test)3 NTList (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList)3 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)2 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)2 AnyValue (org.neo4j.values.AnyValue)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 DefaultParameterValue (org.neo4j.internal.kernel.api.procs.DefaultParameterValue)1 DefaultParameterValue.ntList (org.neo4j.internal.kernel.api.procs.DefaultParameterValue.ntList)1 NTString (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString)1