Search in sources :

Example 21 with ProcedureException

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

the class ReflectiveProcedureTest method shouldRunClassWithMultipleProceduresDeclared.

@Test
public void shouldRunClassWithMultipleProceduresDeclared() throws Throwable {
    // Given
    List<CallableProcedure> compiled = compile(MultiProcedureProcedure.class);
    CallableProcedure bananaPeople = compiled.get(0);
    CallableProcedure coolPeople = compiled.get(1);
    // When
    RawIterator<Object[], ProcedureException> coolOut = coolPeople.apply(new BasicContext(), new Object[0]);
    RawIterator<Object[], ProcedureException> bananaOut = bananaPeople.apply(new BasicContext(), new Object[0]);
    // Then
    assertThat(asList(coolOut), contains(new Object[] { "Bonnie" }, new Object[] { "Clyde" }));
    assertThat(asList(bananaOut), contains(new Object[] { "Jake", 18L }, new Object[] { "Pontus", 2L }));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 22 with ProcedureException

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

the class ReflectiveProcedureTest method shouldRunSimpleReadOnlyProcedure.

@Test
public void shouldRunSimpleReadOnlyProcedure() throws Throwable {
    // Given
    CallableProcedure proc = compile(SingleReadOnlyProcedure.class).get(0);
    // When
    RawIterator<Object[], ProcedureException> out = proc.apply(new BasicContext(), new Object[0]);
    // Then
    assertThat(asList(out), contains(new Object[] { "Bonnie" }, new Object[] { "Clyde" }));
}
Also used : BasicContext(org.neo4j.kernel.api.proc.BasicContext) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 23 with ProcedureException

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

the class BuiltInProceduresIT method listRelationshipTypes.

@Test
public void listRelationshipTypes() throws Throwable {
    // Given
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int relType = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("MyRelType");
    long startNodeId = statement.dataWriteOperations().nodeCreate();
    long endNodeId = statement.dataWriteOperations().nodeCreate();
    statement.dataWriteOperations().relationshipCreate(relType, startNodeId, endNodeId);
    commit();
    // When
    RawIterator<Object[], ProcedureException> stream = procedureCallOpsInNewTx().procedureCallRead(procedureName("db", "relationshipTypes"), new Object[0]);
    // Then
    assertThat(asList(stream), contains(equalTo(new Object[] { "MyRelType" })));
}
Also used : Statement(org.neo4j.kernel.api.Statement) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 24 with ProcedureException

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

the class BuiltInProceduresIT method listAllLabels.

@Test
public void listAllLabels() throws Throwable {
    // Given
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    long nodeId = statement.dataWriteOperations().nodeCreate();
    int labelId = statement.tokenWriteOperations().labelGetOrCreateForName("MyLabel");
    statement.dataWriteOperations().nodeAddLabel(nodeId, labelId);
    commit();
    // When
    RawIterator<Object[], ProcedureException> stream = procedureCallOpsInNewTx().procedureCallRead(procedureName("db", "labels"), new Object[0]);
    // Then
    assertThat(asList(stream), contains(equalTo(new Object[] { "MyLabel" })));
}
Also used : Statement(org.neo4j.kernel.api.Statement) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 25 with ProcedureException

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

the class ProceduresKernelIT method shouldCallReadOnlyProcedure.

@Test
public void shouldCallReadOnlyProcedure() throws Throwable {
    // Given
    kernel.registerProcedure(procedure);
    // When
    RawIterator<Object[], ProcedureException> found = procedureCallOpsInNewTx().procedureCallRead(new QualifiedName(new String[] { "example" }, "exampleProc"), new Object[] { 1337 });
    // Then
    assertThat(asList(found), contains(equalTo(new Object[] { 1337 })));
}
Also used : QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) NTString(org.neo4j.kernel.api.proc.Neo4jTypes.NTString) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Aggregations

ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)49 Test (org.junit.Test)28 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)14 BasicContext (org.neo4j.kernel.api.proc.BasicContext)10 MethodHandle (java.lang.invoke.MethodHandle)8 ArrayList (java.util.ArrayList)8 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)8 FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)8 QualifiedName (org.neo4j.kernel.api.proc.QualifiedName)8 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)7 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)7 RawIterator (org.neo4j.collection.RawIterator)6 Context (org.neo4j.kernel.api.proc.Context)6 Log (org.neo4j.logging.Log)6 List (java.util.List)5 Statement (org.neo4j.kernel.api.Statement)5 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)5 Procedure (org.neo4j.procedure.Procedure)5 Method (java.lang.reflect.Method)4 Comparator (java.util.Comparator)4