Search in sources :

Example 21 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext 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 22 with BasicContext

use of org.neo4j.kernel.api.proc.BasicContext 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 23 with BasicContext

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

the class ReflectiveProcedureTest method shouldSupportProcedureDeprecation.

@Test
public void shouldSupportProcedureDeprecation() throws Throwable {
    // Given
    Log log = mock(Log.class);
    ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, components, log, ProcedureConfig.DEFAULT);
    // When
    List<CallableProcedure> procs = procedureCompiler.compileProcedure(ProcedureWithDeprecation.class, Optional.empty(), true);
    // Then
    verify(log).warn("Use of @Procedure(deprecatedBy) without @Deprecated in badProc");
    verifyNoMoreInteractions(log);
    for (CallableProcedure proc : procs) {
        String name = proc.signature().name().name();
        proc.apply(new BasicContext(), new Object[0]);
        switch(name) {
            case "newProc":
                assertFalse("Should not be deprecated", proc.signature().deprecated().isPresent());
                break;
            case "oldProc":
            case "badProc":
                assertTrue("Should be deprecated", proc.signature().deprecated().isPresent());
                assertThat(proc.signature().deprecated().get(), equalTo("newProc"));
                break;
            default:
                fail("Unexpected procedure: " + name);
        }
    }
}
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 24 with BasicContext

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

Example 25 with BasicContext

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

the class ReflectiveProcedureTest method shouldRunClassWithMultipleProceduresDeclared.

@Test
public void shouldRunClassWithMultipleProceduresDeclared() throws Throwable {
    // Given
    List<CallableProcedure> compiled = compile(MultiProcedureProcedure.class);
    CallableProcedure bananaPeople = compiled.get(0);
    CallableProcedure coolPeople = compiled.get(1);
    // When
    RawIterator<Object[], ProcedureException> coolOut = coolPeople.apply(new BasicContext(), new Object[0]);
    RawIterator<Object[], ProcedureException> bananaOut = bananaPeople.apply(new BasicContext(), new Object[0]);
    // Then
    assertThat(asList(coolOut), contains(new Object[] { "Bonnie" }, new Object[] { "Clyde" }));
    assertThat(asList(bananaOut), contains(new Object[] { "Jake", 18L }, new Object[] { "Pontus", 2L }));
}
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