use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureJarLoaderTest method shouldLoadProcedureFromJarWithSpacesInFilename.
@Test
void shouldLoadProcedureFromJarWithSpacesInFilename() throws Throwable {
// Given
URL jar = new JarBuilder().createJarFor(testDirectory.createFile(new Random().nextInt() + " some spaces in filename.jar"), 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) });
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureWithArgumentsTest method shouldRunGenericProcedure.
@Test
void shouldRunGenericProcedure() throws Throwable {
// Given
CallableProcedure procedure = compile(ClassWithProcedureWithGenericArgs.class).get(0);
// When
RawIterator<AnyValue[], ProcedureException> out = procedure.apply(prepareContext(), new AnyValue[] { VirtualValues.list(stringValue("Roland"), stringValue("Eddie"), stringValue("Susan"), stringValue("Jake")), VirtualValues.list(longValue(1000L), longValue(23L), longValue(29L), longValue(12L)) }, EMPTY_RESOURCE_TRACKER);
// Then
List<AnyValue[]> collect = asList(out);
assertThat(collect.get(0)[0]).isEqualTo(stringValue("Roland is 1000 years old."));
assertThat(collect.get(1)[0]).isEqualTo(stringValue("Eddie is 23 years old."));
assertThat(collect.get(2)[0]).isEqualTo(stringValue("Susan is 29 years old."));
assertThat(collect.get(3)[0]).isEqualTo(stringValue("Jake is 12 years old."));
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldExposeProcedureSignature.
@Test
void shouldExposeProcedureSignature() throws ProcedureException {
// Given
ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").in("in", NTInteger).out(singletonList(inputField("name", NTInteger))).build();
// When
CallableProcedure longStream = compileProcedure(signature, emptyList(), method("longStream", long.class));
// Then
assertEquals(signature, longStream.signature());
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldCallVoidProcedure.
@Test
void shouldCallVoidProcedure() throws ProcedureException, NoSuchFieldException {
// Given
ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").build();
// When
FieldSetter setter = createSetter(InnerClass.class, "transaction", Context::internalTransaction);
CallableProcedure voidMethod = compileProcedure(signature, singletonList(setter), method(InnerClass.class, "voidMethod"));
// Then
RawIterator<AnyValue[], ProcedureException> iterator = voidMethod.apply(ctx, EMPTY, RESOURCE_TRACKER);
assertFalse(iterator.hasNext());
verify(TRANSACTION).traversalDescription();
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeMode.
@Test
void shouldFailNicelyWhenUnsafeAPISafeMode() throws Throwable {
// When
List<CallableProcedure> procList = compiler.compileProcedure(ProcedureWithUnsafeAPI.class, null, false);
assertThat(logProvider).forClass(getClass()).forLevel(WARN).containsMessages("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
assertThat(procList.size()).isEqualTo(1);
ProcedureException exception = assertThrows(ProcedureException.class, () -> procList.get(0).apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER));
assertThat(exception.getMessage()).contains("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
}
Aggregations