use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ProceduresTest method shouldCallRegisteredProcedure.
@Test
public void shouldCallRegisteredProcedure() throws Throwable {
// Given
procs.register(procedure);
// When
RawIterator<Object[], ProcedureException> result = procs.callProcedure(new BasicContext(), signature.name(), new Object[] { 1337 });
// Then
assertThat(asList(result), contains(equalTo(new Object[] { 1337 })));
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ProceduresTest method shouldMakeContextAvailable.
@Test
public void shouldMakeContextAvailable() throws Throwable {
// Given
Key<String> someKey = key("someKey", String.class);
procs.register(new CallableProcedure.BasicProcedure(signature) {
@Override
public RawIterator<Object[], ProcedureException> apply(Context ctx, Object[] input) throws ProcedureException {
return RawIterator.<Object[], ProcedureException>of(new Object[] { ctx.get(someKey) });
}
});
BasicContext ctx = new BasicContext();
ctx.put(someKey, "hello, world");
// When
RawIterator<Object[], ProcedureException> result = procs.callProcedure(ctx, signature.name(), new Object[0]);
// Then
assertThat(asList(result), contains(equalTo(new Object[] { "hello, world" })));
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldSupportProcedureDeprecation.
@Test
public void shouldSupportProcedureDeprecation() throws Throwable {
// Given
Log log = mock(Log.class);
ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, components, log, ProcedureConfig.DEFAULT);
// When
List<CallableProcedure> procs = procedureCompiler.compileProcedure(ProcedureWithDeprecation.class, Optional.empty(), true);
// Then
verify(log).warn("Use of @Procedure(deprecatedBy) without @Deprecated in badProc");
verifyNoMoreInteractions(log);
for (CallableProcedure proc : procs) {
String name = proc.signature().name().name();
proc.apply(new BasicContext(), new Object[0]);
switch(name) {
case "newProc":
assertFalse("Should not be deprecated", proc.signature().deprecated().isPresent());
break;
case "oldProc":
case "badProc":
assertTrue("Should be deprecated", proc.signature().deprecated().isPresent());
assertThat(proc.signature().deprecated().get(), equalTo("newProc"));
break;
default:
fail("Unexpected procedure: " + name);
}
}
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldIgnoreWhiteListingIfFullAccess.
@Test
public void shouldIgnoreWhiteListingIfFullAccess() throws Throwable {
// Given
ProcedureConfig config = new ProcedureConfig(Config.defaults().with(genericMap(procedure_whitelist.name(), "empty")));
Log log = mock(Log.class);
ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, components, log, config);
// When
CallableProcedure proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, Optional.empty(), true).get(0);
// Then
RawIterator<Object[], ProcedureException> result = proc.apply(new BasicContext(), new Object[0]);
assertEquals(result.next()[0], "Bonnie");
}
use of org.neo4j.kernel.api.proc.BasicContext in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldRunClassWithMultipleProceduresDeclared.
@Test
public void shouldRunClassWithMultipleProceduresDeclared() throws Throwable {
// Given
List<CallableProcedure> compiled = compile(MultiProcedureProcedure.class);
CallableProcedure bananaPeople = compiled.get(0);
CallableProcedure coolPeople = compiled.get(1);
// When
RawIterator<Object[], ProcedureException> coolOut = coolPeople.apply(new BasicContext(), new Object[0]);
RawIterator<Object[], ProcedureException> bananaOut = bananaPeople.apply(new BasicContext(), new Object[0]);
// Then
assertThat(asList(coolOut), contains(new Object[] { "Bonnie" }, new Object[] { "Clyde" }));
assertThat(asList(bananaOut), contains(new Object[] { "Jake", 18L }, new Object[] { "Pontus", 2L }));
}
Aggregations