mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Refactor tests using assertSql() helper method
This helper method trims column alias from the sql (for Oracle)
This commit is contained in:
@@ -20,7 +20,7 @@ public class TestInEmpty extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
List<Order> list = query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("1=0");
|
||||
assertSql(query).contains("1=0");
|
||||
assertEquals(0, list.size());
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class TestInEmpty extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
List<Order> list = query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("1=0");
|
||||
assertSql(query).contains("1=0");
|
||||
assertEquals(0, list.size());
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TestInEmpty extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
assertThat(query.getGeneratedSql()).contains("1=1");
|
||||
assertSql(query).contains("1=1");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
|
||||
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount");
|
||||
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,7 +90,7 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
|
||||
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount");
|
||||
assertSql(query).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +99,7 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
|
||||
Query<OrderAggregate> query = Ebean.find(OrderAggregate.class);
|
||||
List<OrderAggregate> list = query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount");
|
||||
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount");
|
||||
assertNotNull(list);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
|
||||
Query<OrderAggregate> query = Ebean.getDefaultServer().createNamedQuery(OrderAggregate.class, "withMax");
|
||||
List<OrderAggregate> list = query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertNotNull(list);
|
||||
}
|
||||
|
||||
@@ -127,8 +127,8 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
|
||||
.order().desc("totalAmount")
|
||||
.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertThat(query.getGeneratedSql()).contains("from o_order_detail where order_id > ? group by order_id having count(*) > ? order by sum(order_qty*unit_price) desc");
|
||||
assertSql(query).contains("count(*) as total_items, sum(order_qty*unit_price) as total_amount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertSql(query).contains("from o_order_detail where order_id > ? group by order_id having count(*) > ? order by sum(order_qty*unit_price) desc");
|
||||
assertNotNull(list);
|
||||
}
|
||||
|
||||
@@ -146,8 +146,8 @@ public class TestOrderTotalAmountReportBean extends BaseTestCase {
|
||||
.setMaxRows(10)
|
||||
.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertThat(query.getGeneratedSql()).contains("from o_order_detail where id > ? and order_id is not null group by order_id having sum(order_qty*unit_price) < ? order by sum(order_qty*unit_price) desc");
|
||||
assertSql(query).contains("count(*) as totalItems, sum(order_qty*unit_price) as totalAmount, max(order_qty*unit_price) as maxAmount from o_order_detail");
|
||||
assertSql(query).contains("from o_order_detail where id > ? and order_id is not null group by order_id having sum(order_qty*unit_price) < ? order by sum(order_qty*unit_price) desc");
|
||||
assertNotNull(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ public class TestQueryForUpdate extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(2);
|
||||
if (isH2() || isPostgres()) {
|
||||
assertThat(sql.get(0)).contains("from e_basic t0 where t0.id =");
|
||||
assertThat(sql.get(1)).contains("from e_basic t0 where t0.id =");
|
||||
assertThat(sql.get(1)).contains("for update");
|
||||
assertSql(sql.get(0)).contains("from e_basic t0 where t0.id =");
|
||||
assertSql(sql.get(1)).contains("from e_basic t0 where t0.id =");
|
||||
assertSql(sql.get(1)).contains("for update");
|
||||
}
|
||||
|
||||
transaction.end();
|
||||
|
||||
@@ -43,7 +43,7 @@ public class TestQueryWhereInRange extends BaseTestCase {
|
||||
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.order_date = ? or t0.order_date is null)");
|
||||
assertSql(query).contains("where (t0.order_date = ? or t0.order_date is null)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,7 +59,7 @@ public class TestQueryWhereInRange extends BaseTestCase {
|
||||
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("where (t0.order_date > ? or t0.order_date is null)");
|
||||
assertSql(query).contains("where (t0.order_date > ? or t0.order_date is null)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,7 +75,7 @@ public class TestQueryWhereInRange extends BaseTestCase {
|
||||
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains(" where (t0.order_date < ? or t0.order_date is null)");
|
||||
assertSql(query).contains(" where (t0.order_date < ? or t0.order_date is null)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,6 +91,6 @@ public class TestQueryWhereInRange extends BaseTestCase {
|
||||
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("(t0.order_date <= ? and (t0.ship_date > ? or t0.ship_date is null))");
|
||||
assertSql(query).contains("(t0.order_date <= ? and (t0.ship_date > ? or t0.ship_date is null))");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class TestQueryWithCache extends BaseTestCase {
|
||||
Query<Country> query = Ebean.find(Country.class).setId("NZ").setUseCache(false);
|
||||
query.findOne();
|
||||
|
||||
assertThat(query.getGeneratedSql()).isNotNull();
|
||||
assertSql(query).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,14 +43,14 @@ public class TestQueryAdapter extends BaseTestCase {
|
||||
.update();
|
||||
|
||||
List<String> sql = LoggedSqlCollector.current();
|
||||
assertThat(sql.get(0)).contains(" 2=2");
|
||||
assertSql(sql.get(0)).contains(" 2=2");
|
||||
|
||||
Ebean.find(TOne.class)
|
||||
.where().idEq(o.getId())
|
||||
.delete();
|
||||
|
||||
sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains(" 3=3");
|
||||
assertSql(sql.get(0)).contains(" 3=3");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user