Search in sources :

Example 96 with ProcedureException

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

the class ProcedureTest method shouldGiveHelpfulErrorOnProcedureReturningInvalidRecordType.

@Test
void shouldGiveHelpfulErrorOnProcedureReturningInvalidRecordType() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> compile(ProcedureWithInvalidRecordOutput.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 `String`, you could define a record class like:%n" + "public class Output '{'%n" + "    public String 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 97 with ProcedureException

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

the class UserFunctionsTest method shouldNotAllowCallingNonExistingFunction.

@Test
void shouldNotAllowCallingNonExistingFunction() {
    UserFunctionHandle functionHandle = procs.function(signature.name());
    ProcedureException exception = assertThrows(ProcedureException.class, () -> procs.callFunction(prepareContext(), functionHandle != null ? functionHandle.id() : -1, new AnyValue[] { numberValue(1337) }));
    assertThat(exception.getMessage()).isEqualTo("There is no function with the internal id `-1` registered for this database instance.");
}
Also used : UserFunctionHandle(org.neo4j.internal.kernel.api.procs.UserFunctionHandle) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 98 with ProcedureException

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

the class FieldInjectionsTest method shouldNotAllowNonPublicFieldsForInjection.

@Test
void shouldNotAllowNonPublicFieldsForInjection() {
    // Given
    FieldInjections injections = new FieldInjections(new ComponentRegistry());
    ProcedureException exception = assertThrows(ProcedureException.class, () -> injections.setters(ProcedureWithPrivateMemberField.class));
    assertThat(exception.getMessage()).isEqualTo("Field `someState` on `ProcedureWithPrivateMemberField` must be non-final and public.");
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 99 with ProcedureException

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

the class FieldInjectionsTest method shouldNotAllowClassesWithNonInjectedFields.

@Test
void shouldNotAllowClassesWithNonInjectedFields() {
    // Given
    FieldInjections injections = new FieldInjections(new ComponentRegistry());
    ProcedureException exception = assertThrows(ProcedureException.class, () -> injections.setters(ProcedureWithNonInjectedMemberFields.class));
    assertThat(exception.getMessage()).isEqualTo("Field `someState` on `ProcedureWithNonInjectedMemberFields` is not annotated as a @Context and is not static. " + "If you want to store state along with your procedure, please use a static field.");
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 100 with ProcedureException

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

the class TemporalFunction method apply.

@Override
public final AnyValue apply(Context ctx, AnyValue[] input) throws ProcedureException {
    if (input == null || (input.length > 0 && (input[0] == NO_VALUE || input[0] == null))) {
        return NO_VALUE;
    } else if (input.length == 0 || input[0].equals(DEFAULT_TEMPORAL_ARGUMENT_VALUE)) {
        return now(ctx.statementClock(), null, defaultZone);
    } else if (input[0] instanceof TextValue) {
        return parse((TextValue) input[0], defaultZone);
    } else if (input[0] instanceof TemporalValue) {
        return select(input[0], defaultZone);
    } else if (input[0] instanceof MapValue) {
        MapValue map = (MapValue) input[0];
        String timezone = onlyTimezone(map);
        if (timezone != null) {
            return now(ctx.statementClock(), timezone, defaultZone);
        }
        return build(map, defaultZone);
    } else {
        throw new ProcedureException(Status.Procedure.ProcedureCallFailed, "Invalid call signature for " + getClass().getSimpleName() + ": Provided input was " + Arrays.toString(input));
    }
}
Also used : TextValue(org.neo4j.values.storable.TextValue) TemporalValue(org.neo4j.values.storable.TemporalValue) MapValue(org.neo4j.values.virtual.MapValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException)

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