use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleThrowingProcedure.
@Test
void shouldHandleThrowingProcedure() throws ProcedureException {
// Given
ResourceTracker tracker = mock(ResourceTracker.class);
ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").in("in", NTString).out(singletonList(inputField("name", NTString))).build();
// When
CallableProcedure longMethod = compileProcedure(signature, emptyList(), method("throwingLongStreamMethod"));
// Then
assertThrows(ProcedureException.class, () -> longMethod.apply(ctx, EMPTY, tracker).next());
verify(tracker).registerCloseableResource(any(Stream.class));
verify(tracker).unregisterCloseableResource(any(Stream.class));
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldHandleNonStaticInnerClasses.
@Test
void shouldHandleNonStaticInnerClasses() throws ProcedureException {
// Given
ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").out(singletonList(inputField("name", NTString))).build();
// When
CallableProcedure stringStream = compileProcedure(signature, emptyList(), method(InnerClass.class, "innerStream"));
// Then
RawIterator<AnyValue[], ProcedureException> iterator = stringStream.apply(ctx, EMPTY, RESOURCE_TRACKER);
assertArrayEquals(new AnyValue[] { stringValue("hello") }, iterator.next());
assertFalse(iterator.hasNext());
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureCompilationTest method shouldCallSimpleProcedure.
@Test
void shouldCallSimpleProcedure() throws ProcedureException {
// Given
ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").in("in", NTInteger).out(singletonList(inputField("name", NTInteger))).build();
// When
CallableProcedure longStream = compileProcedure(signature, emptyList(), method("longStream", long.class));
// Then
RawIterator<AnyValue[], ProcedureException> iterator = longStream.apply(ctx, new AnyValue[] { longValue(1337L) }, RESOURCE_TRACKER);
assertArrayEquals(new AnyValue[] { longValue(1337L) }, iterator.next());
assertFalse(iterator.hasNext());
}
use of org.neo4j.kernel.api.procedure.CallableProcedure 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) });
}
use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.
the class ProcedureJarLoaderTest method shouldLoadProcedureFromJarWithMultipleProcedureClasses.
@Test
void shouldLoadProcedureFromJarWithMultipleProcedureClasses() throws Throwable {
// Given
URL jar = createJarFor(ClassWithOneProcedure.class, ClassWithAnotherProcedure.class, ClassWithNoProcedureAtAll.class);
// When
List<CallableProcedure> procedures = jarloader.loadProceduresFromDir(parentDir(jar)).procedures();
// Then
List<ProcedureSignature> signatures = procedures.stream().map(CallableProcedure::signature).collect(toList());
assertThat(signatures).contains(procedureSignature("org", "neo4j", "procedure", "impl", "myOtherProcedure").out("someNumber", NTInteger).build(), procedureSignature("org", "neo4j", "procedure", "impl", "myProcedure").out("someNumber", NTInteger).build());
}
Aggregations