use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeMode.
@Test
public void shouldFailNicelyWhenUnsafeAPISafeMode() throws Throwable {
//When
List<CallableProcedure> procList = compiler.compileProcedure(ProcedureWithUnsafeAPI.class, Optional.empty(), false);
verify(log).warn("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration.");
assertThat(procList.size(), equalTo(1));
try {
procList.get(0).apply(new BasicContext(), new Object[0]);
fail();
} catch (ProcedureException e) {
assertThat(e.getMessage(), containsString("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration."));
}
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class UserFunctionsTest method shouldMakeContextAvailable.
@Test
public void shouldMakeContextAvailable() throws Throwable {
// Given
Key<String> someKey = key("someKey", String.class);
procs.register(new CallableUserFunction.BasicUserFunction(signature) {
@Override
public Object apply(Context ctx, Object[] input) throws ProcedureException {
return ctx.get(someKey);
}
});
BasicContext ctx = new BasicContext();
ctx.put(someKey, "hello, world");
// When
Object result = procs.callFunction(ctx, signature.name(), new Object[0]);
// Then
assertThat(result, equalTo("hello, world"));
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class UserFunctionsTest method shouldNotAllowCallingNonExistingFunction.
@Test
public void shouldNotAllowCallingNonExistingFunction() throws Throwable {
// Expect
exception.expect(ProcedureException.class);
exception.expectMessage("There is no function with the name `org.myproc` registered for this " + "database instance. Please ensure you've spelled the " + "function name correctly and that the function is properly deployed.");
// When
procs.callFunction(new BasicContext(), signature.name(), new Object[] { 1337 });
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldLoadWhiteListedProcedure.
@Test
public void shouldLoadWhiteListedProcedure() throws Throwable {
// Given
ProcedureConfig config = new ProcedureConfig(Config.defaults().with(genericMap(procedure_whitelist.name(), "org.neo4j.kernel.impl.proc.listCoolPeople")));
Log log = mock(Log.class);
ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, components, log, config);
// When
CallableProcedure proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, Optional.empty(), false).get(0);
// When
RawIterator<Object[], ProcedureException> result = proc.apply(new BasicContext(), new Object[0]);
// Then
assertEquals(result.next()[0], "Bonnie");
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveProcedureWithArgumentsTest method shouldRunSimpleProcedure.
@Test
public void shouldRunSimpleProcedure() throws Throwable {
// Given
CallableProcedure procedure = compile(ClassWithProcedureWithSimpleArgs.class).get(0);
// When
RawIterator<Object[], ProcedureException> out = procedure.apply(new BasicContext(), new Object[] { "Pontus", 35L });
// Then
List<Object[]> collect = asList(out);
assertThat(collect.get(0)[0], equalTo("Pontus is 35 years old."));
}
Aggregations