Search in sources :

Example 91 with ProcedureException

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

the class ProceduresTest method shouldCallRegisteredProcedure.

@Test
void shouldCallRegisteredProcedure() throws Throwable {
    // Given
    procs.register(procedure);
    ProcedureHandle procHandle = procs.procedure(signature.name());
    // When
    RawIterator<AnyValue[], ProcedureException> result = procs.callProcedure(buildContext(dependencyResolver, valueMapper).context(), procHandle.id(), new AnyValue[] { longValue(1337) }, EMPTY_RESOURCE_TRACKER);
    // Then
    assertThat(asList(result)).contains(new AnyValue[] { longValue(1337) });
}
Also used : ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 92 with ProcedureException

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

the class UserFunctionsTest method shouldMakeContextAvailable.

@Test
void shouldMakeContextAvailable() throws Throwable {
    // Given
    procs.register(new CallableUserFunction.BasicUserFunction(signature) {

        @Override
        public AnyValue apply(Context ctx, AnyValue[] input) throws ProcedureException {
            return Values.stringValue(ctx.thread().getName());
        }
    });
    Context ctx = prepareContext();
    int functionId = procs.function(signature.name()).id();
    // When
    Object result = procs.callFunction(ctx, functionId, new AnyValue[0]);
    // Then
    assertThat(result).isEqualTo(Values.stringValue(Thread.currentThread().getName()));
}
Also used : BasicContext.buildContext(org.neo4j.kernel.api.procedure.BasicContext.buildContext) Context(org.neo4j.kernel.api.procedure.Context) CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 93 with ProcedureException

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

the class MethodSignatureCompilerTest method shouldGiveHelpfulErrorOnUnmappable.

@Test
void shouldGiveHelpfulErrorOnUnmappable() throws Throwable {
    // Given
    Method echo = ClassWithProcedureWithSimpleArgs.class.getMethod("echoWithInvalidType", UnmappableRecord.class);
    ProcedureException exception = assertThrows(ProcedureException.class, () -> new MethodSignatureCompiler(new TypeCheckers()).signatureFor(echo));
    assertThat(exception.getMessage()).startsWith(String.format("Argument `name` at position 0 in `echoWithInvalidType` with%n" + "type `UnmappableRecord` cannot be converted to a Neo4j type: Don't know how to map " + "`org.neo4j.procedure.impl.MethodSignatureCompilerTest$UnmappableRecord` to the Neo4j Type System.%n" + "Please refer to to the documentation for full details.%n" + "For your reference, known types are:"));
}
Also used : Method(java.lang.reflect.Method) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 94 with ProcedureException

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

the class MethodSignatureCompilerTest method shouldGiveHelpfulErrorOnMissingAnnotations.

@Test
void shouldGiveHelpfulErrorOnMissingAnnotations() throws Throwable {
    // Given
    Method echo = ClassWithProcedureWithSimpleArgs.class.getMethod("echoWithoutAnnotations", String.class, String.class);
    ProcedureException exception = assertThrows(ProcedureException.class, () -> new MethodSignatureCompiler(new TypeCheckers()).signatureFor(echo));
    assertThat(exception.getMessage()).isEqualTo(String.format("Argument at position 1 in method `echoWithoutAnnotations` is missing an `@Name` annotation.%n" + "Please add the annotation, recompile the class and try again."));
}
Also used : Method(java.lang.reflect.Method) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 95 with ProcedureException

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

the class ProcedureOutputSignatureCompilerTest method shouldGiveHelpfulErrorOnPrivateField.

@Test
void shouldGiveHelpfulErrorOnPrivateField() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> signatures(RecordWithPrivateField.class));
    assertThat(exception.getMessage()).startsWith("Field `wat` in record `RecordWithPrivateField` cannot be accessed. Please ensure the field is marked as `public`.");
}
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