Search in sources :

Example 41 with ProcedureException

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

the class DbIndexesFailureMessageIT method indexDetailsWithNonExistingIndex.

@Test
void indexDetailsWithNonExistingIndex() {
    ProcedureException exception = assertThrows(ProcedureException.class, () -> {
        procs().procedureCallRead(procs().procedureGet(procedureName("db", "indexDetails")).id(), new TextValue[] { stringValue("MyIndex") }, ProcedureCallContext.EMPTY);
    });
    assertEquals(exception.getMessage(), "Could not find index with name \"MyIndex\"");
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 42 with ProcedureException

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

the class SchemaProcedureIT method testLabelIndex.

@Test
void testLabelIndex() throws Throwable {
    KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
    long nbrIndexesOnStartup = Iterators.count(transaction.schemaRead().indexesGetAll());
    // Given there is label with index and a constraint
    long nodeId = transaction.dataWrite().nodeCreate();
    int labelId = transaction.tokenWrite().labelGetOrCreateForName("Person");
    transaction.dataWrite().nodeAddLabel(nodeId, labelId);
    int propertyIdName = transaction.tokenWrite().propertyKeyGetOrCreateForName("name");
    int propertyIdAge = transaction.tokenWrite().propertyKeyGetOrCreateForName("age");
    transaction.dataWrite().nodeSetProperty(nodeId, propertyIdName, Values.of("Emil"));
    commit();
    SchemaWrite schemaOps = schemaWriteInNewTransaction();
    schemaOps.indexCreate(forLabel(labelId, propertyIdName), "my index");
    schemaOps.uniquePropertyConstraintCreate(uniqueForSchema(forLabel(labelId, propertyIdAge)).withName("constraint name"));
    commit();
    // When
    RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "schema", "visualization")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
    // Then
    while (stream.hasNext()) {
        AnyValue[] next = stream.next();
        assertEquals(2, next.length);
        ListValue nodes = (ListValue) next[0];
        assertEquals(1, nodes.size());
        NodeValue node = (NodeValue) nodes.value(0);
        assertThat(node.labels()).isEqualTo(Values.stringArray("Person"));
        assertEquals(stringValue("Person"), node.properties().get("name"));
        assertEquals(VirtualValues.list(stringValue("name")), node.properties().get("indexes"));
        assertEquals(VirtualValues.list(stringValue("Constraint( id=" + (3 + nbrIndexesOnStartup) + ", name='constraint name', type='UNIQUENESS', schema=(:Person {age}), " + "ownedIndex=" + (2 + nbrIndexesOnStartup) + " )")), node.properties().get("constraints"));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValue(org.neo4j.values.virtual.NodeValue) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 43 with ProcedureException

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

the class SchemaProcedureIT method testRelationShip.

@Test
void testRelationShip() throws Throwable {
    // Given there ar
    KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
    long nodeIdPerson = transaction.dataWrite().nodeCreate();
    int labelIdPerson = transaction.tokenWrite().labelGetOrCreateForName("Person");
    transaction.dataWrite().nodeAddLabel(nodeIdPerson, labelIdPerson);
    long nodeIdLocation = transaction.dataWrite().nodeCreate();
    int labelIdLocation = transaction.tokenWrite().labelGetOrCreateForName("Location");
    transaction.dataWrite().nodeAddLabel(nodeIdLocation, labelIdLocation);
    int relationshipTypeId = transaction.tokenWrite().relationshipTypeGetOrCreateForName("LIVES_IN");
    transaction.dataWrite().relationshipCreate(nodeIdPerson, relationshipTypeId, nodeIdLocation);
    commit();
    RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "schema", "visualization")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
    // Then
    while (stream.hasNext()) {
        AnyValue[] next = stream.next();
        assertEquals(2, next.length);
        ListValue relationships = (ListValue) next[1];
        assertEquals(1, relationships.size());
        RelationshipValue relationship = (RelationshipValue) relationships.value(0);
        assertEquals("LIVES_IN", relationship.type().stringValue());
        assertThat(relationship.startNode().labels()).isEqualTo(Values.stringArray("Person"));
        assertThat(relationship.endNode().labels()).isEqualTo(Values.stringArray("Location"));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 44 with ProcedureException

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

the class ProceduresKernelIT method shouldCallReadOnlyProcedure.

@Test
void shouldCallReadOnlyProcedure() throws Throwable {
    // Given
    internalKernel().registerProcedure(procedure);
    // When
    RawIterator<AnyValue[], ProcedureException> found = procs().procedureCallRead(procs().procedureGet(new QualifiedName(new String[] { "example" }, "exampleProc")).id(), new AnyValue[] { longValue(1337) }, ProcedureCallContext.EMPTY);
    // Then
    assertThat(asList(found)).contains(new AnyValue[] { longValue(1337) });
    commit();
}
Also used : QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) NTString(org.neo4j.internal.kernel.api.procs.Neo4jTypes.NTString) Test(org.junit.jupiter.api.Test)

Example 45 with ProcedureException

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

the class AuthProcedures method runSystemCommand.

private void runSystemCommand(String query, String procedureName) throws ProcedureException {
    try {
        Result execute = transaction.execute(query);
        execute.accept(row -> true);
    } catch (Exception e) {
        translateException(e, procedureName);
    }
}
Also used : ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Result(org.neo4j.graphdb.Result)

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