@FixFor( "MODE-1671" )
@Test
public void shouldReturnResolvableNodeIdentifierFromQuery() throws RepositoryException {

    String sql = "SELECT [mode:id] AS reallylongvaluethatwillprintcompletely  FROM [nt:unstructured]";
    Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
    QueryResult result = query.execute();
    final Map<String, Node> nodesById = new HashMap<>();
    validateQuery().rowCount(24).noWarnings().hasColumns("reallylongvaluethatwillprintcompletely").onEachRow(new Predicate() {
        @Override
        public void validate( int rowNumber,
                              Row row ) throws RepositoryException {
            String id = row.getValue("mode:id").getString();
            Node nodeFromQuery = row.getNode();
            Node resolvedNode = session().getNodeByIdentifier(id);
            assertSame(nodeFromQuery, resolvedNode);
            nodesById.put(id, nodeFromQuery);
        }
    }).validate(query, result);
    for (Map.Entry<String, Node> entry : nodesById.entrySet()) {
        final String id = entry.getKey();
        final Node expectedNode = entry.getValue();
        sql = "SELECT [mode:id] AS reallylongvaluethatwillprintcompletely FROM [nt:unstructured] WHERE [mode:id] = '" + id
              + "'";
        query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
        result = query.execute();
        validateQuery().rowCount(1).noWarnings().hasColumns("reallylongvaluethatwillprintcompletely")
                       .onEachRow(new Predicate() {
                           @Override
                           public void validate( int rowNumber,
                                                 Row row ) throws RepositoryException {
                               String id = row.getValue("mode:id").getString();
                               Node nodeFromQuery = row.getNode();
                               String nodeId = nodeFromQuery.getIdentifier();
                               assertSame(nodeFromQuery, expectedNode);
                               assertSame(nodeId, id);
                           }
                       }).validate(query, result);
        sql = "SELECT [mode:id] FROM [nt:unstructured] WHERE [mode:id] = $id";
        query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
        query.bindValue("id", session().getValueFactory().createValue(id));
        result = query.execute();
        validateQuery().rowCount(1).noWarnings().hasColumns("mode:id").onEachRow(new Predicate() {
            @Override
            public void validate( int rowNumber,
                                  Row row ) throws RepositoryException {
                String id = row.getValue("mode:id").getString();
                Node nodeFromQuery = row.getNode();
                assertSame(nodeFromQuery, expectedNode);
                assertSame(nodeFromQuery.getIdentifier(), id);
            }
        }).validate(query, result);
    }
}