use of org.neo4j.kernel.api.proc.CallableProcedure in project neo4j by neo4j.
the class Procedures method start.
@Override
public void start() throws Throwable {
ProcedureJarLoader loader = new ProcedureJarLoader(compiler, log);
ProcedureJarLoader.Callables callables = loader.loadProceduresFromDir(pluginDir);
for (CallableProcedure procedure : callables.procedures()) {
register(procedure);
}
for (CallableUserFunction function : callables.functions()) {
register(function);
}
for (CallableUserAggregationFunction function : callables.aggregationFunctions()) {
register(function);
}
// And register built-in procedures
builtin.accept(this);
}
use of org.neo4j.kernel.api.proc.CallableProcedure 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.CallableProcedure 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.CallableProcedure 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."));
}
use of org.neo4j.kernel.api.proc.CallableProcedure 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));
}
Aggregations