Search in sources :

Example 31 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure 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 32 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.

the class ProcedureWithArgumentsTest method shouldRunGenericProcedure.

@Test
void shouldRunGenericProcedure() throws Throwable {
    // Given
    CallableProcedure procedure = compile(ClassWithProcedureWithGenericArgs.class).get(0);
    // When
    RawIterator<AnyValue[], ProcedureException> out = procedure.apply(prepareContext(), new AnyValue[] { VirtualValues.list(stringValue("Roland"), stringValue("Eddie"), stringValue("Susan"), stringValue("Jake")), VirtualValues.list(longValue(1000L), longValue(23L), longValue(29L), longValue(12L)) }, EMPTY_RESOURCE_TRACKER);
    // Then
    List<AnyValue[]> collect = asList(out);
    assertThat(collect.get(0)[0]).isEqualTo(stringValue("Roland is 1000 years old."));
    assertThat(collect.get(1)[0]).isEqualTo(stringValue("Eddie is 23 years old."));
    assertThat(collect.get(2)[0]).isEqualTo(stringValue("Susan is 29 years old."));
    assertThat(collect.get(3)[0]).isEqualTo(stringValue("Jake is 12 years old."));
}
Also used : CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 33 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.

the class ProcedureCompilationTest method shouldExposeProcedureSignature.

@Test
void shouldExposeProcedureSignature() 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
    assertEquals(signature, longStream.signature());
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) Test(org.junit.jupiter.api.Test)

Example 34 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.

the class ProcedureCompilationTest method shouldCallVoidProcedure.

@Test
void shouldCallVoidProcedure() throws ProcedureException, NoSuchFieldException {
    // Given
    ProcedureSignature signature = ProcedureSignature.procedureSignature("test", "foo").build();
    // When
    FieldSetter setter = createSetter(InnerClass.class, "transaction", Context::internalTransaction);
    CallableProcedure voidMethod = compileProcedure(signature, singletonList(setter), method(InnerClass.class, "voidMethod"));
    // Then
    RawIterator<AnyValue[], ProcedureException> iterator = voidMethod.apply(ctx, EMPTY, RESOURCE_TRACKER);
    assertFalse(iterator.hasNext());
    verify(TRANSACTION).traversalDescription();
}
Also used : ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) Context(org.neo4j.kernel.api.procedure.Context) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 35 with CallableProcedure

use of org.neo4j.kernel.api.procedure.CallableProcedure in project neo4j by neo4j.

the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeMode.

@Test
void shouldFailNicelyWhenUnsafeAPISafeMode() throws Throwable {
    // When
    List<CallableProcedure> procList = compiler.compileProcedure(ProcedureWithUnsafeAPI.class, null, false);
    assertThat(logProvider).forClass(getClass()).forLevel(WARN).containsMessages("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
    assertThat(procList.size()).isEqualTo(1);
    ProcedureException exception = assertThrows(ProcedureException.class, () -> procList.get(0).apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER));
    assertThat(exception.getMessage()).contains("org.neo4j.procedure.impl.listCoolPeople", "unavailable");
}
Also used : AnyValue(org.neo4j.values.AnyValue) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Aggregations

CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)35 Test (org.junit.jupiter.api.Test)29 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)16 ProcedureSignature (org.neo4j.internal.kernel.api.procs.ProcedureSignature)13 Log (org.neo4j.logging.Log)7 AnyValue (org.neo4j.values.AnyValue)7 NullLog (org.neo4j.logging.NullLog)6 URL (java.net.URL)4 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)2 QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)2 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)2 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)2 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)2 FailedLoadProcedure (org.neo4j.kernel.api.procedure.FailedLoadProcedure)2 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)2 Mode (org.neo4j.procedure.Mode)2 Procedure (org.neo4j.procedure.Procedure)2 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 Modifier.isPublic (java.lang.reflect.Modifier.isPublic)1