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\"");
}
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"));
}
}
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"));
}
}
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();
}
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);
}
}
Aggregations