Search in sources :

Example 16 with CallableUserFunction

use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.

the class UserFunctionTest method shouldSupportInternalTypes.

@Test
void shouldSupportInternalTypes() throws Throwable {
    // Given
    CallableUserFunction func = compile(FunctionsWithInternalTypes.class).get(0);
    // When
    Object out = func.apply(prepareContext(), new AnyValue[] { stringValue("hello") });
    // Then
    assertThat(out).isEqualTo(longValue(5));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) Test(org.junit.jupiter.api.Test)

Example 17 with CallableUserFunction

use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.

the class UserFunctionTest method shouldRunClassWithMultipleFunctionsDeclared.

@Test
void shouldRunClassWithMultipleFunctionsDeclared() throws Throwable {
    // Given
    List<CallableUserFunction> compiled = compile(UserFunctionTest.MultiFunction.class);
    CallableUserFunction bananaPeople = compiled.get(0);
    CallableUserFunction coolPeople = compiled.get(1);
    // When
    Object coolOut = coolPeople.apply(prepareContext(), new AnyValue[0]);
    Object bananaOut = bananaPeople.apply(prepareContext(), new AnyValue[0]);
    // Then
    assertThat(coolOut).isEqualTo(ValueUtils.of(Arrays.asList("Bonnie", "Clyde")));
    assertThat(((MapValue) bananaOut).get("foo")).isEqualTo(ValueUtils.of(Arrays.asList("bar", "baz")));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Example 18 with CallableUserFunction

use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.

the class UserFunctionTest method shouldSupportInternalTypesWithNull.

@Test
void shouldSupportInternalTypesWithNull() throws Throwable {
    // Given
    CallableUserFunction func = compile(FunctionsWithInternalTypes.class).get(1);
    // When
    Object out = func.apply(prepareContext(), new AnyValue[] { stringValue("hello") });
    // Then
    assertThat(out).isEqualTo(NO_VALUE);
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) Test(org.junit.jupiter.api.Test)

Example 19 with CallableUserFunction

use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.

the class UserFunctionTest method shouldRunSimpleReadOnlyFunction.

@Test
void shouldRunSimpleReadOnlyFunction() throws Throwable {
    // Given
    CallableUserFunction func = compile(SingleReadOnlyFunction.class).get(0);
    // When
    Object out = func.apply(prepareContext(), new AnyValue[0]);
    // Then
    assertThat(out).isEqualTo(ValueUtils.of(Arrays.asList("Bonnie", "Clyde")));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) Test(org.junit.jupiter.api.Test)

Example 20 with CallableUserFunction

use of org.neo4j.kernel.api.procedure.CallableUserFunction in project neo4j by neo4j.

the class UserFunctionTest method shouldInjectLogging.

@Test
void shouldInjectLogging() throws KernelException {
    // Given
    Log log = spy(Log.class);
    components.register(Log.class, ctx -> log);
    CallableUserFunction function = procedureCompiler.compileFunction(LoggingFunction.class, false).get(0);
    // When
    function.apply(prepareContext(), new AnyValue[0]);
    // Then
    verify(log).debug("1");
    verify(log).info("2");
    verify(log).warn("3");
    verify(log).error("4");
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Test(org.junit.jupiter.api.Test)

Aggregations

CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)28 Test (org.junit.jupiter.api.Test)23 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)14 AnyValue (org.neo4j.values.AnyValue)10 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)5 Log (org.neo4j.logging.Log)5 NullLog (org.neo4j.logging.NullLog)4 Collections.emptyList (java.util.Collections.emptyList)3 List (java.util.List)3 Method (java.lang.reflect.Method)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)2 NTList (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList)2 QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)2 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)2 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)2 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)2 FailedLoadFunction (org.neo4j.kernel.api.procedure.FailedLoadFunction)2 UserFunction (org.neo4j.procedure.UserFunction)2