Search in sources :

Example 1 with BasicContext

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);
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext)

Example 2 with BasicContext

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");
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 3 with BasicContext

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);
        }
    }
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 4 with BasicContext

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]"));
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 5 with BasicContext

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."));
    }
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) 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