use of org.neo4j.internal.kernel.api.procs.UserFunctionSignature 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.internal.kernel.api.procs.UserFunctionSignature 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) }));
}
use of org.neo4j.internal.kernel.api.procs.UserFunctionSignature in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleNulls.
@Test
void shouldHandleNulls() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").in("b", NTBoolean).out(NTFloat).build();
// When
CallableUserFunction nullyMethod = compileFunction(signature, emptyList(), method("nullyMethod", Boolean.class));
// Then
assertEquals(Values.NO_VALUE, nullyMethod.apply(ctx, new AnyValue[] { TRUE }));
assertEquals(PI, nullyMethod.apply(ctx, new AnyValue[] { Values.NO_VALUE }));
}
use of org.neo4j.internal.kernel.api.procs.UserFunctionSignature 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)) }));
}
use of org.neo4j.internal.kernel.api.procs.UserFunctionSignature in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldExposeUserFunctionSignatureOnAggregations.
@Test
void shouldExposeUserFunctionSignatureOnAggregations() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").in("in", NTInteger).out(NTInteger).build();
// When
CallableUserAggregationFunction adder = compileAggregation(signature, emptyList(), method("createAdder"), method(Adder.class, "update", long.class), method(Adder.class, "result"));
// Then
assertEquals(adder.signature(), signature);
}
Aggregations