public void complexDistinctCountTest() {
    oracle.toplink.essentials.ejb.cmp3.EntityManager em =
        (oracle.toplink.essentials.ejb.cmp3.EntityManager) createEntityManager();

    ExpressionBuilder expbldr = new ExpressionBuilder();

    ReportQuery rq = new ReportQuery(Employee.class, expbldr);

    Expression exp = expbldr.get("lastName").equal("Smith");

    rq.setReferenceClass(Employee.class);
    rq.setSelectionCriteria(exp);
    rq.useDistinct();
    rq.returnSingleAttribute();
    rq.dontRetrievePrimaryKeys();
    rq.addCount("COUNT", expbldr.get("lastName").distinct(), Long.class);
    Vector expectedResultVector = (Vector) em.getActiveSession().executeQuery(rq);
    Long expectedResult = (Long) expectedResultVector.get(0);

    String ejbqlString =
        "SELECT COUNT(DISTINCT emp.lastName) FROM Employee emp WHERE emp.lastName = \"Smith\"";
    Long result = (Long) em.createQuery(ejbqlString).getSingleResult();

    Assert.assertEquals("Complex DISTINCT COUNT test failed", expectedResult, result);
  }
  public void complexSumTest() {
    oracle.toplink.essentials.ejb.cmp3.EntityManager em =
        (oracle.toplink.essentials.ejb.cmp3.EntityManager) createEntityManager();

    ExpressionBuilder expbldr = new ExpressionBuilder();

    ReportQuery rq = new ReportQuery(Employee.class, expbldr);
    rq.setReferenceClass(Employee.class);
    rq.returnSingleAttribute();
    rq.dontRetrievePrimaryKeys();
    rq.addAttribute("salary", expbldr.get("salary").distinct().sum(), Long.class);
    Vector expectedResultVector = (Vector) em.getActiveSession().executeQuery(rq);
    Long expectedResult = (Long) expectedResultVector.get(0);

    String ejbqlString = "SELECT SUM(DISTINCT emp.salary) FROM Employee emp";
    Long result = (Long) em.createQuery(ejbqlString).getSingleResult();

    Assert.assertEquals("Complex SUMtest failed", expectedResult, result);
  }