use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldCallSimpleMethod.
@Test
void shouldCallSimpleMethod() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").out(NTInteger).build();
// When
CallableUserFunction longMethod = compileFunction(signature, emptyList(), method("longMethod"));
// Then
assertEquals(longMethod.apply(ctx, EMPTY), longValue(1337L));
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction 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) }));
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleThrowingUDF.
@Test
void shouldHandleThrowingUDF() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").out(NTInteger).build();
// When
CallableUserFunction longMethod = compileFunction(signature, emptyList(), method("throwingLongMethod"));
// Then
assertThrows(ProcedureException.class, () -> longMethod.apply(ctx, EMPTY));
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleByteArrays.
@Test
void shouldHandleByteArrays() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").in("bytes", NTByteArray).out(NTByteArray).build();
// When
CallableUserFunction bytesMethod = compileFunction(signature, emptyList(), method("testMethod", byte[].class));
// Then
assertEquals(byteArray(new byte[] { 1, 2, 3 }), bytesMethod.apply(ctx, new AnyValue[] { byteArray(new byte[] { 1, 2, 3 }) }));
assertEquals(byteArray(new byte[] { 1, 2, 3 }), bytesMethod.apply(ctx, new AnyValue[] { list(byteValue((byte) 1), byteValue((byte) 2), byteValue((byte) 3)) }));
assertEquals(NO_VALUE, bytesMethod.apply(ctx, new AnyValue[] { NO_VALUE }));
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldCallMethodWithParameters.
@Test
void shouldCallMethodWithParameters() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").in("l", NTInteger).in("d", NTFloat).in("b", NTBoolean).out(NTString).build();
// When
CallableUserFunction concatMethod = compileFunction(signature, emptyList(), method("concat", long.class, Double.class, boolean.class));
// Then
assertEquals(stringValue("421.1true"), concatMethod.apply(ctx, new AnyValue[] { longValue(42), doubleValue(1.1), booleanValue(true) }));
}
Aggregations