Search in sources :

Example 31 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.

the class BuiltInProceduresTest method call.

private List<Object[]> call(String name, Object... args) throws ProcedureException {
    BasicContext ctx = new BasicContext();
    ctx.put(KERNEL_TRANSACTION, tx);
    ctx.put(DEPENDENCY_RESOLVER, resolver);
    ctx.put(GRAPHDATABASEAPI, graphDatabaseAPI);
    when(graphDatabaseAPI.getDependencyResolver()).thenReturn(resolver);
    when(resolver.resolveDependency(Procedures.class)).thenReturn(procs);
    return Iterators.asList(procs.callProcedure(ctx, ProcedureSignature.procedureName(name.split("\\.")), args));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext)

Example 32 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.

the class ReflectiveProcedureTest method shouldGiveHelpfulErrorOnNullMessageException.

@Test
public void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable {
    // Given
    CallableProcedure proc = compile(ProcedureThatThrowsNullMsgExceptionAtInvocation.class).get(0);
    // Expect
    exception.expect(ProcedureException.class);
    exception.expectMessage("Failed to invoke procedure `org.neo4j.kernel.impl.proc.throwsAtInvocation`: " + "Caused by: java.lang.IndexOutOfBoundsException");
    // When
    proc.apply(new BasicContext(), new Object[0]);
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) Test(org.junit.Test)

Example 33 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.

the class ReflectiveProcedureTest method shouldInjectLogging.

@Test
public void shouldInjectLogging() throws KernelException {
    // Given
    Log log = spy(Log.class);
    components.register(Log.class, (ctx) -> log);
    CallableProcedure procedure = procedureCompiler.compileProcedure(LoggingProcedure.class, Optional.empty(), true).get(0);
    // When
    procedure.apply(new BasicContext(), new Object[0]);
    // Then
    verify(log).debug("1");
    verify(log).info("2");
    verify(log).warn("3");
    verify(log).error("4");
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) Test(org.junit.Test)

Example 34 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.

the class ReflectiveUserFunctionTest method shouldGiveHelpfulErrorOnNullMessageException.

@Test
public void shouldGiveHelpfulErrorOnNullMessageException() throws Throwable {
    // Given
    CallableUserFunction proc = compile(FunctionThatThrowsNullMsgExceptionAtInvocation.class).get(0);
    // Expect
    exception.expect(ProcedureException.class);
    exception.expectMessage("Failed to invoke function `org.neo4j.kernel.impl.proc.throwsAtInvocation`: " + "Caused by: java.lang.IndexOutOfBoundsException");
    // When
    proc.apply(new BasicContext(), new Object[0]);
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 35 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.

the class ResourceInjectionTest method shouldCompileAndRunUserFunctions.

@Test
public void shouldCompileAndRunUserFunctions() throws Throwable {
    // Given
    CallableUserFunction proc = compiler.compileFunction(FunctionWithInjectedAPI.class).get(0);
    // When
    Object out = proc.apply(new BasicContext(), new Object[0]);
    // Then
    assertThat(out, equalTo("[Bonnie, Clyde]"));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Aggregations

BasicContext (org.neo4j.kernel.api.proc.BasicContext)42 Test (org.junit.Test)36 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)16 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)12 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)10 Log (org.neo4j.logging.Log)8 NullLog (org.neo4j.logging.NullLog)8 CallableUserAggregationFunction (org.neo4j.kernel.api.proc.CallableUserAggregationFunction)7 URL (java.net.URL)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)3 RawIterator (org.neo4j.collection.RawIterator)2 Context (org.neo4j.kernel.api.proc.Context)2 NTString (org.neo4j.kernel.api.proc.Neo4jTypes.NTString)1 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)1 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)1