Search in sources :

Example 81 with AnyValue

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 }));
        }
    }
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) Type(java.lang.reflect.Type) AnyValue(org.neo4j.values.AnyValue) Method(java.lang.reflect.Method) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 82 with AnyValue

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]"));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 83 with AnyValue

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");
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 84 with AnyValue

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");
}
Also used : AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 85 with AnyValue

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]"));
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Aggregations

AnyValue (org.neo4j.values.AnyValue)95 Test (org.junit.jupiter.api.Test)58 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)19 ListValue (org.neo4j.values.virtual.ListValue)14 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)11 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)11 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)10 List (java.util.List)9 TextValue (org.neo4j.values.storable.TextValue)9 RawIterator (org.neo4j.collection.RawIterator)8 MapValue (org.neo4j.values.virtual.MapValue)8 Context (org.neo4j.kernel.api.procedure.Context)7 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)7 ArrayList (java.util.ArrayList)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Values.stringValue (org.neo4j.values.storable.Values.stringValue)6 LocalDate (java.time.LocalDate)5 LocalTime (java.time.LocalTime)5 ZonedDateTime (java.time.ZonedDateTime)5 Arrays (java.util.Arrays)5