Search in sources :

Example 16 with CallableProcedure

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

the class ProcedureTest method shouldRunClassWithMultipleProceduresDeclared.

@Test
void shouldRunClassWithMultipleProceduresDeclared() throws Throwable {
    // Given
    List<CallableProcedure> compiled = compile(MultiProcedureProcedure.class);
    CallableProcedure bananaPeople = compiled.get(0);
    CallableProcedure coolPeople = compiled.get(1);
    // When
    RawIterator<AnyValue[], ProcedureException> coolOut = coolPeople.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
    RawIterator<AnyValue[], ProcedureException> bananaOut = bananaPeople.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
    // Then
    assertThat(asList(coolOut)).containsExactly(new AnyValue[] { stringValue("Bonnie") }, new AnyValue[] { stringValue("Clyde") });
    assertThat(asList(bananaOut)).containsExactly(new AnyValue[] { stringValue("Jake"), longValue(18L) }, new AnyValue[] { stringValue("Pontus"), longValue(2L) });
}
Also used : CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 17 with CallableProcedure

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

the class ProcedureTest method shouldAllowVoidOutput.

@Test
void shouldAllowVoidOutput() throws Throwable {
    // When
    CallableProcedure proc = compile(ProcedureWithVoidOutput.class).get(0);
    // Then
    assertEquals(0, proc.signature().outputSignature().size());
    assertFalse(proc.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER).hasNext());
}
Also used : CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) Test(org.junit.jupiter.api.Test)

Example 18 with CallableProcedure

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

the class ProcedureTest method shouldRunProcedureWithInternalTypes.

@Test
void shouldRunProcedureWithInternalTypes() throws Throwable {
    // Given
    CallableProcedure proc = compile(InternalTypes.class).get(0);
    // When
    RawIterator<AnyValue[], ProcedureException> out = proc.apply(prepareContext(), new AnyValue[] { longValue(42), stringValue("hello"), Values.TRUE }, EMPTY_RESOURCE_TRACKER);
    // Then
    assertThat(out.next()).isEqualTo(new AnyValue[] { longValue(42), stringValue("hello"), Values.TRUE });
    assertFalse(out.hasNext());
}
Also used : CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 19 with CallableProcedure

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

the class ProcedureTest method shouldInjectLogging.

@Test
void shouldInjectLogging() throws KernelException {
    // Given
    Log log = spy(Log.class);
    components.register(Log.class, ctx -> log);
    CallableProcedure procedure = procedureCompiler.compileProcedure(LoggingProcedure.class, null, true).get(0);
    // When
    procedure.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
    // Then
    verify(log).debug("1");
    verify(log).info("2");
    verify(log).warn("3");
    verify(log).error("4");
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) Test(org.junit.jupiter.api.Test)

Example 20 with CallableProcedure

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

the class ProcedureTest method shouldRunSimpleReadOnlyProcedure.

@Test
void shouldRunSimpleReadOnlyProcedure() throws Throwable {
    // Given
    CallableProcedure proc = compile(SingleReadOnlyProcedure.class).get(0);
    // When
    RawIterator<AnyValue[], ProcedureException> out = proc.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
    // Then
    assertThat(asList(out)).containsExactly(new AnyValue[] { stringValue("Bonnie") }, new AnyValue[] { stringValue("Clyde") });
}
Also used : 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