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")));
}
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")));
}
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));
}
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 })));
}
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 });
}
Aggregations