@FixFor( "MODE-1309" )
@Test
public void shouldBeAbleToCreateAndExecuteJcrSql2QueryUsingResidualPropertiesForJoinCriteria() throws RepositoryException {

    String sql = "SELECT x.propA AS pa, y.propB as pb FROM [nt:unstructured] AS x INNER JOIN [nt:unstructured] AS y ON x.propA = y.propB WHERE x.propA = 'value1'";
    Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
    QueryResult result = query.execute();
    final Set<String> expectedPaths = new HashSet<String>();
    expectedPaths.add("/Other/NodeA[2]");
    expectedPaths.add("/Other/NodeA[3]");
    validateQuery().rowCount(2).hasColumns("pa", "pb").onEachRow(new Predicate() {
        @Override
        public void validate( int rowNumber,
                              Row row ) throws RepositoryException {
            // All the rows are identical ...
            assertThat(row.getValue("pa").getString(), is("value1"));
            assertThat(row.getValue("pb").getString(), is("value1"));
            // The path of the first column is the same ...
            assertThat(row.getNode("x").getPath(), is("/Other/NodeA"));
            // The path of the second selector will vary in each row ...
            assertThat(expectedPaths.remove(row.getNode("y").getPath()), is(true));
        }
    }).validate(query, result);
}