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>`."));
}
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.");
}
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.");
}
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.");
}
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));
}
}
Aggregations