use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class UserFunctionTest method shouldNotLoadAnyFunctionIfConfigIsEmpty.
@Test
void shouldNotLoadAnyFunctionIfConfigIsEmpty() throws Throwable {
// Given
Log log = spy(Log.class);
procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, new ComponentRegistry(), log, new ProcedureConfig(Config.defaults(GraphDatabaseSettings.procedure_allowlist, List.of(""))));
List<CallableUserFunction> method = compile(SingleReadOnlyFunction.class);
verify(log).warn("The function 'org.neo4j.procedure.impl.listCoolPeople' is not on the allowlist and won't be loaded.");
assertThat(method.size()).isEqualTo(0);
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class UserFunctionTest method shouldGiveHelpfulErrorOnNullMessageException.
@Test
void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable {
// Given
CallableUserFunction proc = compile(FunctionThatThrowsNullMsgExceptionAtInvocation.class).get(0);
// When
ProcedureException exception = assertThrows(ProcedureException.class, () -> proc.apply(prepareContext(), new AnyValue[0]));
assertThat(exception.getMessage()).isEqualTo("Failed to invoke function `org.neo4j.procedure.impl.throwsAtInvocation`: Caused by: java.lang.IndexOutOfBoundsException");
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class UserFunctionTest method shouldSupportFunctionDeprecation.
@Test
void shouldSupportFunctionDeprecation() throws Throwable {
// Given
Log log = mock(Log.class);
ProcedureCompiler procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, new ComponentRegistry(), log, ProcedureConfig.DEFAULT);
// When
List<CallableUserFunction> funcs = procedureCompiler.compileFunction(FunctionWithDeprecation.class, false);
// Then
verify(log).warn("Use of @UserFunction(deprecatedBy) without @Deprecated in org.neo4j.procedure.impl.badFunc");
verifyNoMoreInteractions(log);
for (CallableUserFunction func : funcs) {
String name = func.signature().name().name();
func.apply(prepareContext(), new AnyValue[0]);
switch(name) {
case "newFunc":
assertFalse(func.signature().deprecated().isPresent(), "Should not be deprecated");
break;
case "oldFunc":
case "badFunc":
assertTrue(func.signature().deprecated().isPresent(), "Should be deprecated");
assertThat(func.signature().deprecated().get()).isEqualTo("newFunc");
break;
default:
fail("Unexpected function: " + name);
}
}
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleStrings.
@Test
void shouldHandleStrings() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").in("string", NTString).out(NTString).build();
// When
CallableUserFunction stringMethod = compileFunction(signature, emptyList(), method("testMethod", String.class));
// Then
assertEquals(stringValue("good"), stringMethod.apply(ctx, new AnyValue[] { stringValue("good") }));
assertEquals(NO_VALUE, stringMethod.apply(ctx, new AnyValue[] { NO_VALUE }));
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleAllTypes.
@Test
void shouldHandleAllTypes() throws ProcedureException {
Map<Type, Method> allTypes = typeMaps();
UserFunctionSignature signature = functionSignature("test", "foo").in("in", NTAny).out(NTAny).build();
for (Entry<Type, Method> entry : allTypes.entrySet()) {
CallableUserFunction function = compileFunction(signature, emptyList(), entry.getValue());
Type type = entry.getKey();
if (type.equals(long.class)) {
assertEquals(longValue(1337L), function.apply(ctx, new AnyValue[] { longValue(1337L) }));
} else if (type.equals(double.class)) {
assertEquals(PI, function.apply(ctx, new AnyValue[] { PI }));
} else if (type.equals(boolean.class)) {
assertEquals(TRUE, function.apply(ctx, new AnyValue[] { TRUE }));
} else if (type instanceof Class<?> && AnyValue.class.isAssignableFrom((Class<?>) type)) {
assertEquals(NO_VALUE, function.apply(ctx, new AnyValue[] { null }));
} else {
assertEquals(NO_VALUE, function.apply(ctx, new AnyValue[] { NO_VALUE }));
}
}
}
Aggregations