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));
}
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));
}
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());
}
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 }));
}
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]);
}
Aggregations