Search in sources :

Example 41 with BasicContext

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

the class ReflectiveUserAggregationFunctionTest method shouldLoadWhiteListedFunction.

@Test
public void shouldLoadWhiteListedFunction() throws Throwable {
    // Given
    procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, new ComponentRegistry(), NullLog.getInstance(), new ProcedureConfig(Config.defaults().with(MapUtil.stringMap(GraphDatabaseSettings.procedure_whitelist.name(), "org.neo4j.kernel.impl.proc.collectCool"))));
    CallableUserAggregationFunction method = compile(SingleAggregationFunction.class).get(0);
    // Expect
    CallableUserAggregationFunction.Aggregator created = method.create(new BasicContext());
    created.update(new Object[] { "Bonnie" });
    assertThat(created.result(), equalTo(Collections.singletonList("Bonnie")));
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 42 with BasicContext

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

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