Search in sources :

Example 6 with BasicContext

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

the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeMode.

@Test
public void shouldFailNicelyWhenUnsafeAPISafeMode() throws Throwable {
    //When
    List<CallableProcedure> procList = compiler.compileProcedure(ProcedureWithUnsafeAPI.class, Optional.empty(), false);
    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 : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 7 with BasicContext

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

the class UserFunctionsTest method shouldMakeContextAvailable.

@Test
public void shouldMakeContextAvailable() throws Throwable {
    // Given
    Key<String> someKey = key("someKey", String.class);
    procs.register(new CallableUserFunction.BasicUserFunction(signature) {

        @Override
        public Object apply(Context ctx, Object[] input) throws ProcedureException {
            return ctx.get(someKey);
        }
    });
    BasicContext ctx = new BasicContext();
    ctx.put(someKey, "hello, world");
    // When
    Object result = procs.callFunction(ctx, signature.name(), new Object[0]);
    // Then
    assertThat(result, equalTo("hello, world"));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) Context(org.neo4j.kernel.api.proc.Context) 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)

Example 8 with BasicContext

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

the class UserFunctionsTest method shouldNotAllowCallingNonExistingFunction.

@Test
public void shouldNotAllowCallingNonExistingFunction() throws Throwable {
    // Expect
    exception.expect(ProcedureException.class);
    exception.expectMessage("There is no function with the name `org.myproc` registered for this " + "database instance. Please ensure you've spelled the " + "function name correctly and that the function is properly deployed.");
    // When
    procs.callFunction(new BasicContext(), signature.name(), new Object[] { 1337 });
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 9 with BasicContext

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

the class ReflectiveProcedureTest method shouldLoadWhiteListedProcedure.

@Test
public void shouldLoadWhiteListedProcedure() throws Throwable {
    // Given
    ProcedureConfig config = new ProcedureConfig(Config.defaults().with(genericMap(procedure_whitelist.name(), "org.neo4j.kernel.impl.proc.listCoolPeople")));
    Log log = mock(Log.class);
    ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, components, log, config);
    // When
    CallableProcedure proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, Optional.empty(), false).get(0);
    // When
    RawIterator<Object[], ProcedureException> result = proc.apply(new BasicContext(), new Object[0]);
    // Then
    assertEquals(result.next()[0], "Bonnie");
}
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) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 10 with BasicContext

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

the class ReflectiveProcedureWithArgumentsTest method shouldRunSimpleProcedure.

@Test
public void shouldRunSimpleProcedure() throws Throwable {
    // Given
    CallableProcedure procedure = compile(ClassWithProcedureWithSimpleArgs.class).get(0);
    // When
    RawIterator<Object[], ProcedureException> out = procedure.apply(new BasicContext(), new Object[] { "Pontus", 35L });
    // Then
    List<Object[]> collect = asList(out);
    assertThat(collect.get(0)[0], equalTo("Pontus is 35 years old."));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) 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