Search in sources :

Example 76 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class BoltResponseMessageTest method shouldSerializeNode.

@Test
void shouldSerializeNode() throws Throwable {
    NodeValue nodeValue = nodeValue(12L, stringArray("User", "Banana"), VirtualValues.map(new String[] { "name", "age" }, new AnyValue[] { stringValue("Bob"), intValue(14) }));
    assertThat(serialized(nodeValue)).isEqualTo("B1 71 91 B3 4E 0C 92 84 55 73 65 72 86 42 61 6E" + lineSeparator() + "61 6E 61 A2 84 6E 61 6D 65 83 42 6F 62 83 61 67" + lineSeparator() + "65 0E");
}
Also used : NodeValue(org.neo4j.values.virtual.NodeValue) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Example 77 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class BoltResponseMessageTest method shouldHandleCommonMessages.

@Test
void shouldHandleCommonMessages() throws Throwable {
    assertSerializes(new RecordMessage(new AnyValue[] { longValue(1L), stringValue("b"), longValue(2L) }));
    assertSerializes(new SuccessMessage(VirtualValues.EMPTY_MAP));
    assertSerializes(new FailureMessage(Status.General.UnknownError, "Err"));
    assertSerializes(IGNORED_MESSAGE);
}
Also used : SuccessMessage(org.neo4j.bolt.v3.messaging.response.SuccessMessage) AnyValue(org.neo4j.values.AnyValue) FailureMessage(org.neo4j.bolt.v3.messaging.response.FailureMessage) RecordMessage(org.neo4j.bolt.v3.messaging.response.RecordMessage) Test(org.junit.jupiter.api.Test)

Example 78 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class ProcedureJarLoaderTest method shouldLoadProcedureFromJar.

@Test
void shouldLoadProcedureFromJar() throws Throwable {
    // Given
    URL jar = createJarFor(ClassWithOneProcedure.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").out("someNumber", NTInteger).build());
    assertThat(asList(procedures.get(0).apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER))).containsExactly(new AnyValue[] { Values.longValue(1337L) });
}
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 79 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class ProcedureJarLoaderTest method shouldLoadProcedureFromJarWithSpacesInFilename.

@Test
void shouldLoadProcedureFromJarWithSpacesInFilename() throws Throwable {
    // Given
    URL jar = new JarBuilder().createJarFor(testDirectory.createFile(new Random().nextInt() + " some spaces in filename.jar"), ClassWithOneProcedure.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").out("someNumber", NTInteger).build());
    assertThat(asList(procedures.get(0).apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER))).containsExactly(new AnyValue[] { Values.longValue(1337L) });
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) Random(java.util.Random) AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) JarBuilder(org.neo4j.test.jar.JarBuilder) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 80 with AnyValue

use of org.neo4j.values.AnyValue in project neo4j by neo4j.

the class ProcedureCompilationTest method shouldHandleStrings.

@Test
void shouldHandleStrings() throws ProcedureException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("string", NTString).out(NTString).build();
    // When
    CallableUserFunction stringMethod = compileFunction(signature, emptyList(), method("testMethod", String.class));
    // Then
    assertEquals(stringValue("good"), stringMethod.apply(ctx, new AnyValue[] { stringValue("good") }));
    assertEquals(NO_VALUE, stringMethod.apply(ctx, new AnyValue[] { NO_VALUE }));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) 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