use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class ResourceInjectionTest method shouldCompileAndRunUserFunctions.
@Test
void shouldCompileAndRunUserFunctions() throws Throwable {
// Given
CallableUserFunction proc = compiler.compileFunction(FunctionWithInjectedAPI.class, false).get(0);
// When
AnyValue out = proc.apply(prepareContext(), new AnyValue[0]);
// Then
assertThat(out).isEqualTo(Values.of("[Bonnie, Clyde]"));
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeModeFunction.
@Test
void shouldFailNicelyWhenUnsafeAPISafeModeFunction() throws Throwable {
// When
List<CallableUserFunction> procList = compiler.compileFunction(FunctionWithUnsafeAPI.class, false);
assertThat(logProvider).forClass(getClass()).forLevel(WARN).containsMessages("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
assertThat(procList.size()).isEqualTo(1);
ProcedureException exception = assertThrows(ProcedureException.class, () -> procList.get(0).apply(prepareContext(), new AnyValue[0]));
assertThat(exception.getMessage()).contains("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
}
use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.
the class ProcedureRegistry method register.
/**
* Register a new function.
*
* @param function the function.
*/
public void register(CallableUserFunction function, boolean overrideCurrentImplementation, boolean builtIn) throws ProcedureException {
UserFunctionSignature signature = function.signature();
QualifiedName name = signature.name();
if (aggregationFunctions.get(name) != null) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register function, because the name `%s` is already in use as an aggregation function.", name);
}
CallableUserFunction oldImplementation = functions.get(name);
if (oldImplementation == null) {
functions.put(name, function, signature.caseInsensitive());
} else {
if (overrideCurrentImplementation) {
functions.put(name, function, signature.caseInsensitive());
} else {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Unable to register function, because the name `%s` is already in use.", name);
}
}
if (builtIn) {
builtInFunctionIds.add(functions.idOf(name));
}
}
Aggregations