use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleAllTypes.
@Test
void shouldHandleAllTypes() throws ProcedureException {
Map<Type, Method> allTypes = typeMaps();
UserFunctionSignature signature = functionSignature("test", "foo").in("in", NTAny).out(NTAny).build();
for (Entry<Type, Method> entry : allTypes.entrySet()) {
CallableUserFunction function = compileFunction(signature, emptyList(), entry.getValue());
Type type = entry.getKey();
if (type.equals(long.class)) {
assertEquals(longValue(1337L), function.apply(ctx, new AnyValue[] { longValue(1337L) }));
} else if (type.equals(double.class)) {
assertEquals(PI, function.apply(ctx, new AnyValue[] { PI }));
} else if (type.equals(boolean.class)) {
assertEquals(TRUE, function.apply(ctx, new AnyValue[] { TRUE }));
} else if (type instanceof Class<?> && AnyValue.class.isAssignableFrom((Class<?>) type)) {
assertEquals(NO_VALUE, function.apply(ctx, new AnyValue[] { null }));
} else {
assertEquals(NO_VALUE, function.apply(ctx, new AnyValue[] { NO_VALUE }));
}
}
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ResourceInjectionTest method shouldCompileAndRunUserFunctions.
@Test
void shouldCompileAndRunUserFunctions() throws Throwable {
// Given
CallableUserFunction proc = compiler.compileFunction(FunctionWithInjectedAPI.class, false).get(0);
// When
AnyValue out = proc.apply(prepareContext(), new AnyValue[0]);
// Then
assertThat(out).isEqualTo(Values.of("[Bonnie, Clyde]"));
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeModeFunction.
@Test
void shouldFailNicelyWhenUnsafeAPISafeModeFunction() throws Throwable {
// When
List<CallableUserFunction> procList = compiler.compileFunction(FunctionWithUnsafeAPI.class, 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]));
assertThat(exception.getMessage()).contains("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
}
use of org.neo4j.values.AnyValue 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");
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ResourceInjectionTest method shouldCompileAndRunUserAggregationFunctions.
@Test
void shouldCompileAndRunUserAggregationFunctions() throws Throwable {
// Given
CallableUserAggregationFunction proc = compiler.compileAggregationFunction(AggregationFunctionWithInjectedAPI.class).get(0);
// When
proc.create(prepareContext()).update(new AnyValue[] {});
AnyValue out = proc.create(prepareContext()).result();
// Then
assertThat(out).isEqualTo(stringValue("[Bonnie, Clyde]"));
}
Aggregations