Search in sources :

Example 6 with AnyValue

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

Example 7 with AnyValue

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)) }));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) NTList(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTList) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 8 with AnyValue

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) });
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 9 with AnyValue

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

Example 10 with AnyValue

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