Search in sources :

Example 1 with DbAccess

use of org.neo4j.cypher.internal.runtime.DbAccess in project neo4j by neo4j.

the class PathValueBuilderTest method builder.

private static PathValueBuilder builder(AnyValue... values) {
    DbAccess dbAccess = mock(DbAccess.class);
    RelationshipScanCursor cursors = mock(RelationshipScanCursor.class);
    Map<Long, RelationshipValue> relMap = new HashMap<>();
    for (AnyValue value : values) {
        if (value instanceof NodeValue) {
            NodeValue nodeValue = (NodeValue) value;
            when(dbAccess.nodeById(nodeValue.id())).thenReturn(nodeValue);
        } else if (value instanceof RelationshipValue) {
            RelationshipValue relationshipValue = (RelationshipValue) value;
            relMap.put(relationshipValue.id(), relationshipValue);
        } else {
            throw new AssertionError("invalid input");
        }
        Mockito.doAnswer((Answer<Void>) invocationOnMock -> {
            long id = invocationOnMock.getArgument(0);
            RelationshipScanCursor cursor = invocationOnMock.getArgument(1);
            RelationshipValue rel = relMap.get(id);
            when(cursor.sourceNodeReference()).thenReturn(rel.startNode().id());
            when(cursor.targetNodeReference()).thenReturn(rel.endNode().id());
            return null;
        }).when(dbAccess).singleRelationship(anyLong(), any(RelationshipScanCursor.class));
    }
    return new PathValueBuilder(dbAccess, cursors);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) EMPTY_MAP(org.neo4j.values.virtual.VirtualValues.EMPTY_MAP) AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) NO_VALUE(org.neo4j.values.storable.Values.NO_VALUE) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NodeValue(org.neo4j.values.virtual.NodeValue) HashMap(java.util.HashMap) Mockito.when(org.mockito.Mockito.when) Values.stringValue(org.neo4j.values.storable.Values.stringValue) VirtualValues.list(org.neo4j.values.virtual.VirtualValues.list) EMPTY_LIST(org.neo4j.values.virtual.VirtualValues.EMPTY_LIST) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) EMPTY_TEXT_ARRAY(org.neo4j.values.storable.Values.EMPTY_TEXT_ARRAY) DbAccess(org.neo4j.cypher.internal.runtime.DbAccess) Map(java.util.Map) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PathValue(org.neo4j.values.virtual.PathValue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) VirtualValues(org.neo4j.values.virtual.VirtualValues) Mockito.mock(org.mockito.Mockito.mock) NodeValue(org.neo4j.values.virtual.NodeValue) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) HashMap(java.util.HashMap) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) DbAccess(org.neo4j.cypher.internal.runtime.DbAccess)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1 Mockito (org.mockito.Mockito)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 Answer (org.mockito.stubbing.Answer)1 DbAccess (org.neo4j.cypher.internal.runtime.DbAccess)1 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)1 AnyValue (org.neo4j.values.AnyValue)1 EMPTY_TEXT_ARRAY (org.neo4j.values.storable.Values.EMPTY_TEXT_ARRAY)1 NO_VALUE (org.neo4j.values.storable.Values.NO_VALUE)1 Values.stringValue (org.neo4j.values.storable.Values.stringValue)1 NodeValue (org.neo4j.values.virtual.NodeValue)1 PathValue (org.neo4j.values.virtual.PathValue)1 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)1