use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleNulls.
@Test
void shouldHandleNulls() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").in("b", NTBoolean).out(NTFloat).build();
// When
CallableUserFunction nullyMethod = compileFunction(signature, emptyList(), method("nullyMethod", Boolean.class));
// Then
assertEquals(Values.NO_VALUE, nullyMethod.apply(ctx, new AnyValue[] { TRUE }));
assertEquals(PI, nullyMethod.apply(ctx, new AnyValue[] { Values.NO_VALUE }));
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleNumberOutput.
@Test
void shouldHandleNumberOutput() throws ProcedureException {
// Given
UserFunctionSignature signature = functionSignature("test", "foo").in("numbers", NTList(NTNumber)).out(NTNumber).build();
// When
CallableUserFunction sumMethod = compileFunction(signature, emptyList(), method("sum", List.class));
// Then
assertEquals(longValue(3), sumMethod.apply(ctx, new AnyValue[] { list(longValue(1), longValue(2)) }));
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ProcedureJarLoaderTest method shouldLoadProcedureWithArgumentFromJar.
@Test
void shouldLoadProcedureWithArgumentFromJar() throws Throwable {
// Given
URL jar = createJarFor(ClassWithProcedureWithArgument.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").in("value", NTInteger).out("someNumber", NTInteger).build());
assertThat(asList(procedures.get(0).apply(prepareContext(), new AnyValue[] { Values.longValue(42) }, EMPTY_RESOURCE_TRACKER))).containsExactly(new AnyValue[] { Values.longValue(42) });
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ResourceInjectionTest method shouldCompileAndRunUnsafeProcedureUnsafeMode.
@Test
void shouldCompileAndRunUnsafeProcedureUnsafeMode() throws Throwable {
// Given
CallableProcedure proc = compiler.compileProcedure(ProcedureWithUnsafeAPI.class, null, true).get(0);
// Then
List<AnyValue[]> out = Iterators.asList(proc.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER));
// Then
assertThat(out.get(0)).isEqualTo(new AnyValue[] { stringValue("Morpheus") });
assertThat(out.get(1)).isEqualTo(new AnyValue[] { stringValue("Trinity") });
assertThat(out.get(2)).isEqualTo(new AnyValue[] { stringValue("Neo") });
assertThat(out.get(3)).isEqualTo(new AnyValue[] { stringValue("Emil") });
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ResourceInjectionTest method shouldCompileAndRunProcedure.
@Test
void shouldCompileAndRunProcedure() throws Throwable {
// Given
CallableProcedure proc = compiler.compileProcedure(ProcedureWithInjectedAPI.class, null, true).get(0);
// Then
List<AnyValue[]> out = Iterators.asList(proc.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER));
// Then
assertThat(out.get(0)).isEqualTo(new AnyValue[] { stringValue("Bonnie") });
assertThat(out.get(1)).isEqualTo(new AnyValue[] { stringValue("Clyde") });
}
Aggregations