use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class CommunityProcedureITBase method listProcedures.
@Test
void listProcedures() throws Throwable {
// When
ProcedureHandle procedures = procs().procedureGet(procedureName("dbms", "procedures"));
RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procedures.id(), new AnyValue[0], ProcedureCallContext.EMPTY);
// Then
List<AnyValue[]> actual = asList(stream);
List<Object[]> expected = getExpectedCommunityProcs();
Map<String, AnyValue[]> resultMap = actual.stream().collect(toMap(row -> ((StringValue) row[0]).stringValue(), Function.identity()));
Map<String, Object[]> expectedMap = expected.stream().collect(toMap(row -> ((StringValue) row[0]).stringValue(), Function.identity()));
assertThat(resultMap.keySet(), containsInAnyOrder(expectedMap.keySet().toArray()));
for (String procName : resultMap.keySet()) {
AnyValue[] actualArray = resultMap.get(procName);
Object[] expectedArray = expectedMap.get(procName);
assertNotNull(expectedArray, "Got an unexpected entry for " + procName + " =>\n" + printElementsOfArray(actualArray));
assertEquals(expectedArray.length, actualArray.length, "Count of columns for " + procName + " does not match");
for (int i = 1; i < actualArray.length; i++) {
Matcher matcher;
if (expectedArray[i] instanceof TextArray) {
// this has to be a list of roles, we ignore those in community and expect a null here
matcher = equalTo(NO_VALUE);
} else if (expectedArray[i] instanceof Matcher) {
matcher = (Matcher) expectedArray[i];
} else {
matcher = equalTo(expectedArray[i]);
}
assertThat("Column " + i + " for " + procName + " does not match", actualArray[i], matcher);
}
}
commit();
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class DbIndexesFailureMessageIT method assertMapsEqual.
private void assertMapsEqual(Map<String, Value> expected, MapValue actual) {
assertEquals(expected.size(), actual.size());
expected.forEach((k, v) -> {
final AnyValue value = actual.get(k);
assertNotNull(value);
assertEquals(v, value);
});
actual.foreach((k, v) -> {
final Value value = expected.get(k);
assertNotNull(value);
assertEquals(v, value);
});
}
use of org.neo4j.values.AnyValue 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.values.AnyValue 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.values.AnyValue in project neo4j by neo4j.
the class ValueUtilsTest method shouldHandleMaps.
@Test
void shouldHandleMaps() {
// Given
Map<String, Object> map = MapUtil.map("a", Arrays.asList("foo", 42));
// When
AnyValue anyValue = ValueUtils.of(map);
// Then
assertThat(anyValue).isInstanceOf(MapValue.class);
MapValue mapValue = (MapValue) anyValue;
assertThat(mapValue.get("a")).isEqualTo(VirtualValues.list(stringValue("foo"), intValue(42)));
assertThat(mapValue.size()).isEqualTo(1);
}
Aggregations