@FixFor( "MODE-909" )
@Test
public void shouldBeAbleToCreateAndExecuteJcrSql2QueryWithOrderBy() throws RepositoryException {

    String sql = "SELECT [jcr:primaryType] from [nt:base] ORDER BY [jcr:primaryType]";
    Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
    QueryResult result = query.execute();
    validateQuery().rowCount(totalNodeCount).hasColumns("jcr:primaryType").onEachRow(new Predicate() {
        private String lastPrimaryType;
        @Override
        public void validate( int rowNumber,
                              Row row ) throws RepositoryException {
            String primaryType = row.getValue("jcr:primaryType").getString();
            if (lastPrimaryType != null) {
                assertThat(primaryType.compareTo(lastPrimaryType) >= 0, is(true));
            }
            lastPrimaryType = primaryType;
        }
    }).validate(query, result);
}