use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class NonTransactionalDbmsOperations method procedureCallDbms.
@Override
public RawIterator<Object[], ProcedureException> procedureCallDbms(QualifiedName name, Object[] input, SecurityContext securityContext) throws ProcedureException {
BasicContext ctx = new BasicContext();
ctx.put(Context.SECURITY_CONTEXT, securityContext);
return procedures.callProcedure(ctx, name, input);
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveUserFunctionTest method shouldInjectLogging.
@Test
public void shouldInjectLogging() throws KernelException {
// Given
Log log = spy(Log.class);
components.register(Log.class, (ctx) -> log);
CallableUserFunction function = procedureCompiler.compileFunction(LoggingFunction.class).get(0);
// When
function.apply(new BasicContext(), new Object[0]);
// Then
verify(log).debug("1");
verify(log).info("2");
verify(log).warn("3");
verify(log).error("4");
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveUserFunctionTest method shouldSupportFunctionDeprecation.
@Test
public void shouldSupportFunctionDeprecation() throws Throwable {
// Given
Log log = mock(Log.class);
ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, new ComponentRegistry(), log, ProcedureConfig.DEFAULT);
// When
List<CallableUserFunction> funcs = procedureCompiler.compileFunction(FunctionWithDeprecation.class);
// Then
verify(log).warn("Use of @UserFunction(deprecatedBy) without @Deprecated in org.neo4j.kernel.impl.proc.badFunc");
verifyNoMoreInteractions(log);
for (CallableUserFunction func : funcs) {
String name = func.signature().name().name();
func.apply(new BasicContext(), new Object[0]);
switch(name) {
case "newFunc":
assertFalse("Should not be deprecated", func.signature().deprecated().isPresent());
break;
case "oldFunc":
case "badFunc":
assertTrue("Should be deprecated", func.signature().deprecated().isPresent());
assertThat(func.signature().deprecated().get(), equalTo("newFunc"));
break;
default:
fail("Unexpected function: " + name);
}
}
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ResourceInjectionTest method shouldCompileAndRunUserAggregationFunctions.
@Test
public void shouldCompileAndRunUserAggregationFunctions() throws Throwable {
// Given
CallableUserAggregationFunction proc = compiler.compileAggregationFunction(AggregationFunctionWithInjectedAPI.class).get(0);
// When
proc.create(new BasicContext()).update(new Object[] {});
Object out = proc.create(new BasicContext()).result();
// Then
assertThat(out, equalTo("[Bonnie, Clyde]"));
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeModeFunction.
@Test
public void shouldFailNicelyWhenUnsafeAPISafeModeFunction() throws Throwable {
//When
List<CallableUserFunction> procList = compiler.compileFunction(FunctionWithUnsafeAPI.class);
verify(log).warn("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration.");
assertThat(procList.size(), equalTo(1));
try {
procList.get(0).apply(new BasicContext(), new Object[0]);
fail();
} catch (ProcedureException e) {
assertThat(e.getMessage(), containsString("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration."));
}
}
Aggregations