Search in sources :

Example 16 with BasicContext

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

the class ReflectiveUserFunctionTest method shouldRunSimpleReadOnlyFunction.

@Test
public void shouldRunSimpleReadOnlyFunction() throws Throwable {
    // Given
    CallableUserFunction func = compile(SingleReadOnlyFunction.class).get(0);
    // When
    Object out = func.apply(new BasicContext(), new Object[0]);
    // Then
    assertThat(out, equalTo(Arrays.asList("Bonnie", "Clyde")));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 17 with BasicContext

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

the class ReflectiveUserFunctionTest method shouldRunClassWithMultipleFunctionsDeclared.

@Test
public void shouldRunClassWithMultipleFunctionsDeclared() throws Throwable {
    // Given
    List<CallableUserFunction> compiled = compile(ReflectiveUserFunctionTest.MultiFunction.class);
    CallableUserFunction bananaPeople = compiled.get(0);
    CallableUserFunction coolPeople = compiled.get(1);
    // When
    Object coolOut = coolPeople.apply(new BasicContext(), new Object[0]);
    Object bananaOut = bananaPeople.apply(new BasicContext(), new Object[0]);
    // Then
    assertThat(coolOut, equalTo(Arrays.asList("Bonnie", "Clyde")));
    assertThat(((Map) bananaOut).get("foo"), equalTo(Arrays.asList("bar", "baz")));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 18 with BasicContext

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

the class ProcedureJarLoaderTest method shouldLoadUnsafeAllowedProcedureFromJar.

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

Example 19 with BasicContext

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

the class ProcedureJarLoaderTest method shouldLoadProcedureWithArgumentFromJar.

@Test
public void shouldLoadProcedureWithArgumentFromJar() throws Throwable {
    // Given
    URL jar = createJarFor(ClassWithProcedureWithArgument.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").in("value", NTInteger).out("someNumber", NTInteger).build()));
    assertThat(asList(procedures.get(0).apply(new BasicContext(), new Object[] { 42L })), contains(IsEqual.equalTo(new Object[] { 42L })));
}
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)

Example 20 with BasicContext

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

the class ProceduresTest method shouldNotAllowCallingNonExistingProcedure.

@Test
public void shouldNotAllowCallingNonExistingProcedure() throws Throwable {
    // Expect
    exception.expect(ProcedureException.class);
    exception.expectMessage("There is no procedure with the name `org.myproc` registered for this " + "database instance. Please ensure you've spelled the " + "procedure name correctly and that the procedure is properly deployed.");
    // When
    procs.callProcedure(new BasicContext(), signature.name(), new Object[] { 1337 });
}
Also used : 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