use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureTest method shouldNotLoadNoneWhiteListedProcedure.
@Test
void shouldNotLoadNoneWhiteListedProcedure() throws Throwable {
// Given
ProcedureConfig config = new ProcedureConfig(Config.defaults(procedure_allowlist, List.of("org.neo4j.procedure.impl.NOTlistCoolPeople")));
Log log = mock(Log.class);
ProcedureCompiler procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, components, log, config);
// When
List<CallableProcedure> proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, null, false);
// Then
verify(log).warn("The procedure 'org.neo4j.procedure.impl.listCoolPeople' is not on the allowlist and won't be loaded.");
assertThat(proc.isEmpty()).isTrue();
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureTest method shouldLoadWhiteListedProcedure.
@Test
void shouldLoadWhiteListedProcedure() throws Throwable {
// Given
ProcedureConfig config = new ProcedureConfig(Config.defaults(procedure_allowlist, List.of("org.neo4j.procedure.impl.listCoolPeople")));
Log log = mock(Log.class);
ProcedureCompiler procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, components, log, config);
// When
CallableProcedure proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, null, false).get(0);
// When
RawIterator<AnyValue[], ProcedureException> result = proc.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
// Then
assertEquals(result.next()[0], stringValue("Bonnie"));
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureTest method shouldAllowOverridingProcedureName.
@Test
void shouldAllowOverridingProcedureName() throws Throwable {
// When
CallableProcedure proc = compile(ProcedureWithOverriddenName.class).get(0);
// Then
assertEquals("org.mystuff.thisisActuallyTheName", proc.signature().name().toString());
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureTest method shouldSupportProcedureDeprecation.
@Test
void shouldSupportProcedureDeprecation() throws Throwable {
// Given
Log log = mock(Log.class);
ProcedureCompiler procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, components, log, ProcedureConfig.DEFAULT);
// When
List<CallableProcedure> procs = procedureCompiler.compileProcedure(ProcedureWithDeprecation.class, null, 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(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
switch(name) {
case "newProc":
assertFalse(proc.signature().deprecated().isPresent(), "Should not be deprecated");
break;
case "oldProc":
case "badProc":
assertTrue(proc.signature().deprecated().isPresent(), "Should be deprecated");
assertThat(proc.signature().deprecated().get()).isEqualTo("newProc");
break;
default:
fail("Unexpected procedure: " + name);
}
}
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureJarLoaderTest method shouldLoadProcedureFromJar.
@Test
void shouldLoadProcedureFromJar() throws Throwable {
// Given
URL jar = createJarFor(ClassWithOneProcedure.class);
// When
List<CallableProcedure> procedures = jarloader.loadProceduresFromDir(parentDir(jar)).procedures();
// Then
List<ProcedureSignature> signatures = procedures.stream().map(CallableProcedure::signature).collect(toList());
assertThat(signatures).containsExactly(procedureSignature("org", "neo4j", "procedure", "impl", "myProcedure").out("someNumber", NTInteger).build());
assertThat(asList(procedures.get(0).apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER))).containsExactly(new AnyValue[] { Values.longValue(1337L) });
}
Aggregations