Search in sources :

Example 26 with AnyValue

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();
}
Also used : AnyValue(org.neo4j.values.AnyValue) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) NO_VALUE(org.neo4j.values.storable.Values.NO_VALUE) Arrays(java.util.Arrays) TextArray(org.neo4j.values.storable.TextArray) RawIterator(org.neo4j.collection.RawIterator) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureSignature.procedureName(org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName) Function(java.util.function.Function) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) StringValue(org.neo4j.values.storable.StringValue) Collectors.toMap(java.util.stream.Collectors.toMap) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) Matcher(org.hamcrest.Matcher) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Matcher(org.hamcrest.Matcher) ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) StringValue(org.neo4j.values.storable.StringValue) TextArray(org.neo4j.values.storable.TextArray) Test(org.junit.jupiter.api.Test)

Example 27 with AnyValue

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);
    });
}
Also used : AnyValue(org.neo4j.values.AnyValue) AnyValue(org.neo4j.values.AnyValue) Values.doubleValue(org.neo4j.values.storable.Values.doubleValue) Value(org.neo4j.values.storable.Value) Values.longValue(org.neo4j.values.storable.Values.longValue) MapValue(org.neo4j.values.virtual.MapValue) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue)

Example 28 with AnyValue

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"));
    }
}
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 29 with AnyValue

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"));
    }
}
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 30 with AnyValue

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);
}
Also used : AnyValue(org.neo4j.values.AnyValue) MapValue(org.neo4j.values.virtual.MapValue) Test(org.junit.jupiter.api.Test)

Aggregations

AnyValue (org.neo4j.values.AnyValue)95 Test (org.junit.jupiter.api.Test)58 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)19 ListValue (org.neo4j.values.virtual.ListValue)14 CallableUserFunction (org.neo4j.kernel.api.procedure.CallableUserFunction)11 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)11 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)10 List (java.util.List)9 TextValue (org.neo4j.values.storable.TextValue)9 RawIterator (org.neo4j.collection.RawIterator)8 MapValue (org.neo4j.values.virtual.MapValue)8 Context (org.neo4j.kernel.api.procedure.Context)7 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)7 ArrayList (java.util.ArrayList)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Values.stringValue (org.neo4j.values.storable.Values.stringValue)6 LocalDate (java.time.LocalDate)5 LocalTime (java.time.LocalTime)5 ZonedDateTime (java.time.ZonedDateTime)5 Arrays (java.util.Arrays)5