@Test
public void testWithHaving() {
RawSqlBuilder r = RawSqlBuilder
.parse("select id, sum(x) from t_cust where id > ? group by id having sum(x) > ? order by id desc");
Sql sql = r.getSql();
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
Assert.assertEquals("id desc", sql.getOrderBy());
// no where
r = RawSqlBuilder
.parse("select id, sum(x) from t_cust group by id having sum(x) > ? order by id desc");
sql = r.getSql();
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
Assert.assertEquals("from t_cust", sql.getPreWhere());
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
Assert.assertEquals("id desc", sql.getOrderBy());
// no where, no order by
r = RawSqlBuilder.parse("select id, sum(x) from t_cust group by id having sum(x) > ?");
sql = r.getSql();
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
Assert.assertEquals("from t_cust", sql.getPreWhere());
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
Assert.assertNull(sql.getOrderBy());
// no order by
r = RawSqlBuilder
.parse("select id, sum(x) from t_cust where id > ? group by id having sum(x) > ?");
sql = r.getSql();
Assert.assertEquals("id, sum(x)", sql.getPreFrom());
Assert.assertEquals("from t_cust where id > ?", sql.getPreWhere());
Assert.assertEquals("group by id having sum(x) > ?", sql.getPreHaving());
Assert.assertNull(sql.getOrderBy());
}