Search in sources :

Example 21 with CallableProcedure

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

the class ReflectiveProcedureTest method shouldNotLoadNoneWhiteListedProcedure.

@Test
public void shouldNotLoadNoneWhiteListedProcedure() throws Throwable {
    // Given
    ProcedureConfig config = new ProcedureConfig(Config.defaults().with(genericMap(procedure_whitelist.name(), "org.neo4j.kernel.impl.proc.NOTlistCoolPeople")));
    Log log = mock(Log.class);
    ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, components, log, config);
    // When
    List<CallableProcedure> proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, Optional.empty(), false);
    // Then
    verify(log).warn("The procedure 'org.neo4j.kernel.impl.proc.listCoolPeople' is not on the whitelist and won't be loaded.");
    assertThat(proc.isEmpty(), is(true));
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) Test(org.junit.Test)

Example 22 with CallableProcedure

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

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

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

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

the class ProcedureJarLoaderTest method shouldLoadProcedureFromJar.

@Test
public void shouldLoadProcedureFromJar() throws Throwable {
    // Given
    URL jar = createJarFor(ClassWithOneProcedure.class);
    // When
    List<CallableProcedure> procedures = jarloader.loadProcedures(jar).procedures();
    // Then
    List<ProcedureSignature> signatures = procedures.stream().map(CallableProcedure::signature).collect(toList());
    assertThat(signatures, contains(procedureSignature("org", "neo4j", "kernel", "impl", "proc", "myProcedure").out("someNumber", NTInteger).build()));
    assertThat(asList(procedures.get(0).apply(new BasicContext(), new Object[0])), contains(IsEqual.equalTo(new Object[] { 1337L })));
}
Also used : ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) URL(java.net.URL) Test(org.junit.Test)

Aggregations

CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)26 Test (org.junit.Test)22 BasicContext (org.neo4j.kernel.api.proc.BasicContext)15 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)10 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)7 Log (org.neo4j.logging.Log)7 NullLog (org.neo4j.logging.NullLog)6 URL (java.net.URL)4 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)3 MethodHandle (java.lang.invoke.MethodHandle)2 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)2 CallableUserAggregationFunction (org.neo4j.kernel.api.proc.CallableUserAggregationFunction)2 FailedLoadProcedure (org.neo4j.kernel.api.proc.FailedLoadProcedure)2 FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)2 QualifiedName (org.neo4j.kernel.api.proc.QualifiedName)2 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)2 OutputMapper (org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper)2 Mode (org.neo4j.procedure.Mode)2 Procedure (org.neo4j.procedure.Procedure)2 MethodHandles (java.lang.invoke.MethodHandles)1