Search in sources :

Example 16 with ProcedureException

use of org.neo4j.kernel.api.exceptions.ProcedureException 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 17 with ProcedureException

use of org.neo4j.kernel.api.exceptions.ProcedureException 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)

Example 18 with ProcedureException

use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class ProceduresTest method shouldCallRegisteredProcedure.

@Test
public void shouldCallRegisteredProcedure() throws Throwable {
    // Given
    procs.register(procedure);
    // When
    RawIterator<Object[], ProcedureException> result = procs.callProcedure(new BasicContext(), signature.name(), new Object[] { 1337 });
    // Then
    assertThat(asList(result), contains(equalTo(new Object[] { 1337 })));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 19 with ProcedureException

use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class ProceduresTest method shouldMakeContextAvailable.

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

        @Override
        public RawIterator<Object[], ProcedureException> apply(Context ctx, Object[] input) throws ProcedureException {
            return RawIterator.<Object[], ProcedureException>of(new Object[] { ctx.get(someKey) });
        }
    });
    BasicContext ctx = new BasicContext();
    ctx.put(someKey, "hello, world");
    // When
    RawIterator<Object[], ProcedureException> result = procs.callProcedure(ctx, signature.name(), new Object[0]);
    // Then
    assertThat(asList(result), contains(equalTo(new Object[] { "hello, world" })));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) Context(org.neo4j.kernel.api.proc.Context) BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) NTString(org.neo4j.kernel.api.proc.Neo4jTypes.NTString) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) RawIterator(org.neo4j.collection.RawIterator) Test(org.junit.Test)

Example 20 with ProcedureException

use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class ReflectiveProcedureTest method shouldIgnoreWhiteListingIfFullAccess.

@Test
public void shouldIgnoreWhiteListingIfFullAccess() throws Throwable {
    // Given
    ProcedureConfig config = new ProcedureConfig(Config.defaults().with(genericMap(procedure_whitelist.name(), "empty")));
    Log log = mock(Log.class);
    ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, components, log, config);
    // When
    CallableProcedure proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, Optional.empty(), true).get(0);
    // Then
    RawIterator<Object[], ProcedureException> result = proc.apply(new BasicContext(), new Object[0]);
    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)

Aggregations

ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)49 Test (org.junit.Test)28 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)14 BasicContext (org.neo4j.kernel.api.proc.BasicContext)10 MethodHandle (java.lang.invoke.MethodHandle)8 ArrayList (java.util.ArrayList)8 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)8 FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)8 QualifiedName (org.neo4j.kernel.api.proc.QualifiedName)8 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)7 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)7 RawIterator (org.neo4j.collection.RawIterator)6 Context (org.neo4j.kernel.api.proc.Context)6 Log (org.neo4j.logging.Log)6 List (java.util.List)5 Statement (org.neo4j.kernel.api.Statement)5 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)5 Procedure (org.neo4j.procedure.Procedure)5 Method (java.lang.reflect.Method)4 Comparator (java.util.Comparator)4