Search in sources :

Example 56 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class UserFunctionTest method shouldGiveHelpfulErrorOnConstructorThatRequiresArgument.

@Test
void shouldGiveHelpfulErrorOnConstructorThatRequiresArgument() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> compile(WeirdConstructorFunction.class));
    assertThat(exception.getMessage()).isEqualTo("Unable to find a usable public no-argument constructor in the class `WeirdConstructorFunction`. Please add a " + "valid, public constructor, recompile the class and try again.");
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 57 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class UserFunctionTest method shouldGiveHelpfulErrorOnFunctionReturningInvalidType.

@Test
void shouldGiveHelpfulErrorOnFunctionReturningInvalidType() {
    // When
    ProcedureException exception = assertThrows(ProcedureException.class, () -> compile(FunctionWithInvalidOutput.class));
    assertThat(exception.getMessage()).isEqualTo(String.format("Don't know how to map `char[]` to the Neo4j Type System.%n" + "Please refer to to the documentation for full details.%n" + "For your reference, known types are: [boolean, byte[], double, java.lang.Boolean, " + "java.lang.Double, java.lang.Long, java.lang.Number, java.lang.Object, " + "java.lang.String, java.time.LocalDate, java.time.LocalDateTime, " + "java.time.LocalTime, java.time.OffsetTime, java.time.ZonedDateTime, " + "java.time.temporal.TemporalAmount, java.util.List, java.util.Map, long]"));
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 58 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.

the class ProcedureTest method shouldGiveHelpfulErrorOnContextAnnotatedStaticField.

@Test
void shouldGiveHelpfulErrorOnContextAnnotatedStaticField() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> compile(ProcedureWithStaticContextAnnotatedField.class));
    assertThat(exception.getMessage()).isEqualTo(String.format("The field `gdb` in the class named `ProcedureWithStaticContextAnnotatedField` is annotated as a @Context field,%n" + "but it is static. @Context fields must be public, non-final and non-static,%n" + "because they are reset each time a procedure is invoked."));
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 59 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException 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 60 with ProcedureException

use of org.neo4j.internal.kernel.api.exceptions.ProcedureException 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)

Aggregations

ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)124 Test (org.junit.jupiter.api.Test)95 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)21 AnyValue (org.neo4j.values.AnyValue)19 QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)14 KernelException (org.neo4j.exceptions.KernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)9 Arrays (java.util.Arrays)8 List (java.util.List)8 RawIterator (org.neo4j.collection.RawIterator)8 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)8 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)8 Collectors (java.util.stream.Collectors)7 ProcedureSignature (org.neo4j.internal.kernel.api.procs.ProcedureSignature)7 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)7 Method (java.lang.reflect.Method)6 ArrayList (java.util.ArrayList)6 FieldSignature (org.neo4j.internal.kernel.api.procs.FieldSignature)6 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)6