Search in sources :

Example 36 with BasicContext

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

the class ResourceInjectionTest method shouldCompileAndRunProcedure.

@Test
public void shouldCompileAndRunProcedure() throws Throwable {
    // Given
    CallableProcedure proc = compiler.compileProcedure(ProcedureWithInjectedAPI.class, Optional.empty(), true).get(0);
    // Then
    List<Object[]> out = Iterators.asList(proc.apply(new BasicContext(), new Object[0]));
    // Then
    assertThat(out.get(0), equalTo(new Object[] { "Bonnie" }));
    assertThat(out.get(1), equalTo(new Object[] { "Clyde" }));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) Test(org.junit.Test)

Example 37 with BasicContext

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

the class ResourceInjectionTest method shouldCompileAndRunUnsafeProcedureUnsafeMode.

@Test
public void shouldCompileAndRunUnsafeProcedureUnsafeMode() throws Throwable {
    // Given
    CallableProcedure proc = compiler.compileProcedure(ProcedureWithUnsafeAPI.class, Optional.empty(), true).get(0);
    // Then
    List<Object[]> out = Iterators.asList(proc.apply(new BasicContext(), new Object[0]));
    // Then
    assertThat(out.get(0), equalTo(new Object[] { "Morpheus" }));
    assertThat(out.get(1), equalTo(new Object[] { "Trinity" }));
    assertThat(out.get(2), equalTo(new Object[] { "Neo" }));
    assertThat(out.get(3), equalTo(new Object[] { "Emil" }));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) Test(org.junit.Test)

Example 38 with BasicContext

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

the class UserFunctionsTest method shouldCallRegisteredFunction.

@Test
public void shouldCallRegisteredFunction() throws Throwable {
    // Given
    procs.register(function);
    // When
    Object result = procs.callFunction(new BasicContext(), signature.name(), new Object[] { 1337 });
    // Then
    assertThat(result, equalTo(new Object[] { 1337 }));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 39 with BasicContext

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

the class ReflectiveProcedureWithArgumentsTest method shouldRunGenericProcedure.

@Test
public void shouldRunGenericProcedure() throws Throwable {
    // Given
    CallableProcedure procedure = compile(ClassWithProcedureWithGenericArgs.class).get(0);
    // When
    RawIterator<Object[], ProcedureException> out = procedure.apply(new BasicContext(), new Object[] { Arrays.asList("Roland", "Eddie", "Susan", "Jake"), Arrays.asList(1000L, 23L, 29L, 12L) });
    // Then
    List<Object[]> collect = asList(out);
    assertThat(collect.get(0)[0], equalTo("Roland is 1000 years old."));
    assertThat(collect.get(1)[0], equalTo("Eddie is 23 years old."));
    assertThat(collect.get(2)[0], equalTo("Susan is 29 years old."));
    assertThat(collect.get(3)[0], equalTo("Jake is 12 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 40 with BasicContext

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

the class ReflectiveUserAggregationFunctionTest method shouldInjectLogging.

@Test
public void shouldInjectLogging() throws KernelException {
    // Given
    Log log = spy(Log.class);
    components.register(Log.class, (ctx) -> log);
    CallableUserAggregationFunction function = procedureCompiler.compileAggregationFunction(LoggingFunction.class).get(0);
    // When
    CallableUserAggregationFunction.Aggregator aggregator = function.create(new BasicContext());
    aggregator.update(new Object[] {});
    aggregator.result();
    // Then
    verify(log).debug("1");
    verify(log).info("2");
    verify(log).warn("3");
    verify(log).error("4");
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) 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