Search in sources :

Example 51 with ProcedureException

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

the class ProcedureOutputSignatureCompilerTest method shouldGiveHelpfulErrorOnUnmappable.

@Test
void shouldGiveHelpfulErrorOnUnmappable() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> signatures(UnmappableRecord.class));
    assertThat(exception.getMessage()).startsWith("Field `wat` in record `UnmappableRecord` cannot be converted to a Neo4j type: " + "Don't know how to map `org.neo4j.procedure.impl.ProcedureOutputSignatureCompilerTest$UnmappableRecord`");
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 52 with ProcedureException

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

the class ProcedureOutputSignatureCompilerTest method shouldWarnAgainstStdLibraryClassesSinceTheseIndicateUserError.

@Test
void shouldWarnAgainstStdLibraryClassesSinceTheseIndicateUserError() {
    // Impl note: We may want to change this behavior and actually allow procedures to return `Long` etc,
    // with a default column name. So Stream<Long> would become records like (out: Long)
    // Drawback of that is that it'd cause cognitive dissonance, it's not obvious what's a record
    // and what is a primitive value..
    ProcedureException exception = assertThrows(ProcedureException.class, () -> signatures(Long.class));
    assertThat(exception.getMessage()).isEqualTo(String.format("Procedures must return a Stream of records, where a record is a concrete class%n" + "that you define, with public non-final fields defining the fields in the record.%n" + "If you''d like your procedure to return `Long`, you could define a record class like:%n" + "public class Output '{'%n" + "    public Long out;%n" + "'}'%n%n" + "And then define your procedure as returning `Stream<Output>`."));
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 53 with ProcedureException

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

the class ProcedureTest method shouldGiveHelpfulErrorOnConstructorThatRequiresArgument.

@Test
void shouldGiveHelpfulErrorOnConstructorThatRequiresArgument() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> compile(WeirdConstructorProcedure.class));
    assertThat(exception.getMessage()).isEqualTo("Unable to find a usable public no-argument constructor in the class `WeirdConstructorProcedure`. 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 54 with ProcedureException

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

the class UserFunctionTest method shouldGiveHelpfulErrorOnNoPublicConstructor.

@Test
void shouldGiveHelpfulErrorOnNoPublicConstructor() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> compile(PrivateConstructorFunction.class));
    assertThat(exception.getMessage()).isEqualTo("Unable to find a usable public no-argument constructor in the class `PrivateConstructorFunction`. 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 55 with ProcedureException

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

the class UserFunctionTest method shouldGiveHelpfulErrorOnContextAnnotatedStaticField.

@Test
void shouldGiveHelpfulErrorOnContextAnnotatedStaticField() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> compile(FunctionWithStaticContextAnnotatedField.class));
    assertThat(exception.getMessage()).isEqualTo(String.format("The field `gdb` in the class named `FunctionWithStaticContextAnnotatedField` 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)

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