Search in sources :

Example 1 with NTString

use of org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString in project neo4j by neo4j.

the class ListConverterTest method shouldHandleEmptyListWithSpaces.

@Test
void shouldHandleEmptyListWithSpaces() {
    // Given
    ListConverter converter = new ListConverter(String.class, NTString, expressionEvaluator());
    String listString = " [  ]   ";
    // When
    DefaultParameterValue converted = converter.apply(listString);
    // Then
    assertThat(converted).isEqualTo(ntList(emptyList(), NTString));
}
Also used : DefaultParameterValue(org.neo4j.internal.kernel.api.procs.DefaultParameterValue) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) Test(org.junit.jupiter.api.Test)

Example 2 with NTString

use of org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString in project neo4j by neo4j.

the class ListConverterTest method shouldHandleEmptyList.

@Test
void shouldHandleEmptyList() {
    // Given
    ListConverter converter = new ListConverter(String.class, NTString, expressionEvaluator());
    String listString = "[]";
    // When
    DefaultParameterValue converted = converter.apply(listString);
    // Then
    assertThat(converted).isEqualTo(ntList(emptyList(), NTString));
}
Also used : DefaultParameterValue(org.neo4j.internal.kernel.api.procs.DefaultParameterValue) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) Test(org.junit.jupiter.api.Test)

Example 3 with NTString

use of org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString in project neo4j by neo4j.

the class ProcedureCompilationTest method aggregationShouldAccessContext.

@Test
void aggregationShouldAccessContext() throws ProcedureException, NoSuchFieldException {
    // Given
    UserFunctionSignature signature = functionSignature("test", "foo").in("in", NTString).out(NTString).build();
    FieldSetter setter = createSetter(InnerClass.class, "thread", Context::thread);
    String threadName = Thread.currentThread().getName();
    UserAggregator aggregator = compileAggregation(signature, singletonList(setter), method(InnerClass.class, "create"), method(InnerClass.Aggregator.class, "update", String.class), method(InnerClass.Aggregator.class, "result")).create(ctx);
    // When
    aggregator.update(new AnyValue[] { stringValue("1:") });
    aggregator.update(new AnyValue[] { stringValue("2:") });
    aggregator.update(new AnyValue[] { stringValue("3:") });
    // Then
    assertEquals(stringValue(format("1: %s, 2: %s, 3: %s", threadName, threadName, threadName)), aggregator.result());
}
Also used : Context(org.neo4j.kernel.api.procedure.Context) UserAggregator(org.neo4j.internal.kernel.api.procs.UserAggregator) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Test(org.junit.jupiter.api.Test)

Example 4 with NTString

use of org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString 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)

Example 5 with NTString

use of org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString in project neo4j by neo4j.

the class ProcedureCompilationTest method procedureShouldAccessContext.

@Test
void procedureShouldAccessContext() throws ProcedureException, NoSuchFieldException {
    // Given
    ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").in("in", NTString).out(singletonList(inputField("name", NTString))).build();
    FieldSetter setter1 = createSetter(InnerClass.class, "transaction", Context::internalTransaction);
    FieldSetter setter2 = createSetter(InnerClass.class, "thread", Context::thread);
    Method stringStream = method(InnerClass.class, "stringStream");
    // Then
    String threadName = Thread.currentThread().getName();
    assertEquals(stringValue("NULL AND NULL"), compileProcedure(signature, emptyList(), stringStream).apply(ctx, EMPTY, RESOURCE_TRACKER).next()[0]);
    assertEquals(stringValue("I'm transaction AND NULL"), compileProcedure(signature, singletonList(setter1), stringStream).apply(ctx, EMPTY, RESOURCE_TRACKER).next()[0]);
    assertEquals(stringValue("NULL AND " + threadName), compileProcedure(signature, singletonList(setter2), stringStream).apply(ctx, EMPTY, RESOURCE_TRACKER).next()[0]);
    assertEquals(stringValue("I'm transaction AND " + threadName), compileProcedure(signature, asList(setter1, setter2), stringStream).apply(ctx, EMPTY, RESOURCE_TRACKER).next()[0]);
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) Context(org.neo4j.kernel.api.procedure.Context) Method(java.lang.reflect.Method) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 NTString (org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString)8 DefaultParameterValue (org.neo4j.internal.kernel.api.procs.DefaultParameterValue)5 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)2 Context (org.neo4j.kernel.api.procedure.Context)2 Method (java.lang.reflect.Method)1 ProcedureSignature (org.neo4j.internal.kernel.api.procs.ProcedureSignature)1 UserAggregator (org.neo4j.internal.kernel.api.procs.UserAggregator)1 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)1 AnyValue (org.neo4j.values.AnyValue)1