use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class UserFunctionTest method shouldSupportInternalTypes.
@Test
void shouldSupportInternalTypes() throws Throwable {
// Given
CallableUserFunction func = compile(FunctionsWithInternalTypes.class).get(0);
// When
Object out = func.apply(prepareContext(), new AnyValue[] { stringValue("hello") });
// Then
assertThat(out).isEqualTo(longValue(5));
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class UserFunctionTest method shouldRunClassWithMultipleFunctionsDeclared.
@Test
void shouldRunClassWithMultipleFunctionsDeclared() throws Throwable {
// Given
List<CallableUserFunction> compiled = compile(UserFunctionTest.MultiFunction.class);
CallableUserFunction bananaPeople = compiled.get(0);
CallableUserFunction coolPeople = compiled.get(1);
// When
Object coolOut = coolPeople.apply(prepareContext(), new AnyValue[0]);
Object bananaOut = bananaPeople.apply(prepareContext(), new AnyValue[0]);
// Then
assertThat(coolOut).isEqualTo(ValueUtils.of(Arrays.asList("Bonnie", "Clyde")));
assertThat(((MapValue) bananaOut).get("foo")).isEqualTo(ValueUtils.of(Arrays.asList("bar", "baz")));
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class UserFunctionTest method shouldSupportInternalTypesWithNull.
@Test
void shouldSupportInternalTypesWithNull() throws Throwable {
// Given
CallableUserFunction func = compile(FunctionsWithInternalTypes.class).get(1);
// When
Object out = func.apply(prepareContext(), new AnyValue[] { stringValue("hello") });
// Then
assertThat(out).isEqualTo(NO_VALUE);
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class UserFunctionTest method shouldRunSimpleReadOnlyFunction.
@Test
void shouldRunSimpleReadOnlyFunction() throws Throwable {
// Given
CallableUserFunction func = compile(SingleReadOnlyFunction.class).get(0);
// When
Object out = func.apply(prepareContext(), new AnyValue[0]);
// Then
assertThat(out).isEqualTo(ValueUtils.of(Arrays.asList("Bonnie", "Clyde")));
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class UserFunctionTest method shouldInjectLogging.
@Test
void shouldInjectLogging() throws KernelException {
// Given
Log log = spy(Log.class);
components.register(Log.class, ctx -> log);
CallableUserFunction function = procedureCompiler.compileFunction(LoggingFunction.class, false).get(0);
// When
function.apply(prepareContext(), new AnyValue[0]);
// Then
verify(log).debug("1");
verify(log).info("2");
verify(log).warn("3");
verify(log).error("4");
}
Aggregations