mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Update tests for multi-platform testing
This commit is contained in:
@@ -113,7 +113,7 @@ public class TestDbJson_List extends BaseTestCase {
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
// we don't update the phone numbers (as they are not dirty)
|
||||
// plain_bean=?, no longer included with MD5 dirty detection
|
||||
// plain_bean=?, no longer included with dirty detection
|
||||
assertSql(sql.get(0)).contains("update ebasic_json_list set name=?, version=? where");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.tests.model.array;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.SqlRow;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
@@ -24,14 +23,14 @@ import static org.junit.Assert.assertNull;
|
||||
|
||||
public class TestDbArray_basic extends BaseTestCase {
|
||||
|
||||
private EArrayBean bean = new EArrayBean();
|
||||
private final EArrayBean bean = new EArrayBean();
|
||||
|
||||
private EArrayBean found;
|
||||
|
||||
@Test
|
||||
@IgnorePlatform(Platform.HANA)
|
||||
public void insert() throws SQLException {
|
||||
|
||||
DB.find(EArrayBean.class).delete();
|
||||
bean.setName("some stuff");
|
||||
assertThat(bean.getStatuses()).as("DbArray is auto initialised").isNotNull();
|
||||
|
||||
@@ -62,14 +61,14 @@ public class TestDbArray_basic extends BaseTestCase {
|
||||
bean.getStatus2().add(EArrayBean.Status.TWO);
|
||||
bean.getStatus2().add(EArrayBean.Status.ONE);
|
||||
|
||||
Ebean.save(bean);
|
||||
DB.save(bean);
|
||||
|
||||
found = Ebean.find(EArrayBean.class, bean.getId());
|
||||
found = DB.find(EArrayBean.class, bean.getId());
|
||||
|
||||
assertThat(found.getPhoneNumbers()).containsExactly("4321", "9823");
|
||||
|
||||
if (isPostgres()) {
|
||||
Query<EArrayBean> query = Ebean.find(EArrayBean.class)
|
||||
Query<EArrayBean> query = DB.find(EArrayBean.class)
|
||||
.where()
|
||||
.arrayContains("otherIds", 96L, 97L)
|
||||
.arrayContains("uids", bean.getUids().get(0))
|
||||
@@ -100,7 +99,7 @@ public class TestDbArray_basic extends BaseTestCase {
|
||||
assertSql(query).contains(" coalesce(cardinality(t0.phone_numbers),0) <> 0");
|
||||
assertThat(list).hasSize(1);
|
||||
|
||||
query = Ebean.find(EArrayBean.class)
|
||||
query = DB.find(EArrayBean.class)
|
||||
.where()
|
||||
.arrayIsEmpty("otherIds")
|
||||
.arrayNotContains("uids", bean.getUids().get(0))
|
||||
@@ -128,11 +127,11 @@ public class TestDbArray_basic extends BaseTestCase {
|
||||
//@Test//(dependsOnMethods = "insert")
|
||||
public void json_parse_format() {
|
||||
|
||||
String asJson = Ebean.json().toJson(found);
|
||||
String asJson = DB.json().toJson(found);
|
||||
assertThat(asJson).contains("\"phoneNumbers\":[\"4321\",\"9823\"]");
|
||||
assertThat(asJson).contains("\"id\":");
|
||||
|
||||
EArrayBean fromJson = Ebean.json().toBean(EArrayBean.class, asJson);
|
||||
EArrayBean fromJson = DB.json().toBean(EArrayBean.class, asJson);
|
||||
assertEquals(found.getId(), fromJson.getId());
|
||||
assertEquals(found.getId(), fromJson.getId());
|
||||
assertEquals(found.getName(), fromJson.getName());
|
||||
@@ -144,7 +143,7 @@ public class TestDbArray_basic extends BaseTestCase {
|
||||
|
||||
found.setName("jack");
|
||||
LoggedSqlCollector.start();
|
||||
Ebean.save(found);
|
||||
DB.save(found);
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
// we don't update the phone numbers (as they are not dirty)
|
||||
@@ -158,7 +157,7 @@ public class TestDbArray_basic extends BaseTestCase {
|
||||
found.getUids().add(UUID.randomUUID());
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
Ebean.save(found);
|
||||
DB.save(found);
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertSql(sql.get(0)).contains("update earray_bean set phone_numbers=?, uids=?, version=? where");
|
||||
@@ -173,8 +172,8 @@ public class TestDbArray_basic extends BaseTestCase {
|
||||
bean.setPhoneNumbers(null);
|
||||
bean.setOtherIds(null);
|
||||
|
||||
Ebean.save(bean);
|
||||
Ebean.delete(bean);
|
||||
DB.save(bean);
|
||||
DB.delete(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,8 +189,8 @@ public class TestDbArray_basic extends BaseTestCase {
|
||||
List<EArrayBean> all = new ArrayList<>();
|
||||
all.add(bean);
|
||||
|
||||
Ebean.saveAll(all);
|
||||
Ebean.deleteAll(all);
|
||||
DB.saveAll(all);
|
||||
DB.deleteAll(all);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,9 +236,9 @@ public class TestDbArray_basic extends BaseTestCase {
|
||||
bean.getIntEnums().add(null);
|
||||
bean.getIntEnums().add(IntEnum.TWO);
|
||||
|
||||
Ebean.save(bean);
|
||||
DB.save(bean);
|
||||
|
||||
found = Ebean.find(EArrayBean.class, bean.getId());
|
||||
found = DB.find(EArrayBean.class, bean.getId());
|
||||
assertThat(found.getPhoneNumbers()).containsExactly("111222333", null, "333222111");
|
||||
assertThat(found.getOtherIds()).containsExactly(15L, null, 30L, null);
|
||||
assertNull(found.getUids().get(1));
|
||||
@@ -247,7 +246,7 @@ public class TestDbArray_basic extends BaseTestCase {
|
||||
assertThat(found.getStatuses()).containsExactly(EArrayBean.Status.ONE, null, EArrayBean.Status.THREE);
|
||||
assertThat(found.getVcEnums()).containsExactly(VarcharEnum.ONE, null, VarcharEnum.TWO);
|
||||
assertThat(found.getIntEnums()).containsExactly(null, IntEnum.ZERO, null, IntEnum.TWO);
|
||||
Ebean.delete(bean);
|
||||
DB.delete(bean);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -267,11 +266,11 @@ public class TestDbArray_basic extends BaseTestCase {
|
||||
bean.setUids(uids);
|
||||
bean.setStatuses(statuses);
|
||||
|
||||
Ebean.save(bean);
|
||||
DB.save(bean);
|
||||
// load cache
|
||||
Ebean.find(EArrayBean.class, bean.getId());
|
||||
DB.find(EArrayBean.class, bean.getId());
|
||||
// hit cache
|
||||
EArrayBean found = Ebean.find(EArrayBean.class, bean.getId());
|
||||
EArrayBean found = DB.find(EArrayBean.class, bean.getId());
|
||||
|
||||
assertThat(found.getUids()).isEqualTo(uids);
|
||||
assertThat(found.getStatuses()).isEqualTo(statuses);
|
||||
|
||||
@@ -6,11 +6,13 @@ import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
|
||||
import io.ebean.annotation.Identity;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.annotation.Where;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Identity(start = 1000)
|
||||
@Entity
|
||||
public class MnyNode {
|
||||
|
||||
|
||||
@@ -220,7 +220,12 @@ public class TestQueryFilterMany extends BaseTestCase {
|
||||
|
||||
List<String> sqlList = LoggedSqlCollector.stop();
|
||||
assertEquals(1, sqlList.size());
|
||||
assertThat(sqlList.get(0)).contains("from o_customer t0 left join o_order t1 on t1.kcustomer_id = t0.id and t1.order_date is not null left join o_customer t2 on t2.id = t1.kcustomer_id where t1.status in (?) order by t0.id");
|
||||
assertThat(sqlList.get(0)).contains("from o_customer t0 left join o_order t1 on t1.kcustomer_id = t0.id and t1.order_date is not null left join o_customer t2 on t2.id = t1.kcustomer_id where t1.status ");
|
||||
if (isPostgres()) {
|
||||
assertThat(sqlList.get(0)).contains("where t1.status = any(?) order by t0.id");
|
||||
} else {
|
||||
assertThat(sqlList.get(0)).contains("where t1.status in (?) order by t0.id");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -239,8 +244,13 @@ public class TestQueryFilterMany extends BaseTestCase {
|
||||
List<String> sqlList = LoggedSqlCollector.stop();
|
||||
assertEquals(2, sqlList.size());
|
||||
assertThat(sqlList.get(0)).contains("from o_customer t0");
|
||||
assertThat(sqlList.get(1)).contains("from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where t0.order_date is not null and (t0.kcustomer_id) in ");
|
||||
assertThat(sqlList.get(1)).contains(" and t0.status in ");
|
||||
if (isPostgres()) {
|
||||
assertThat(sqlList.get(1)).contains("from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where t0.order_date is not null and (t0.kcustomer_id) = any(?)");
|
||||
assertThat(sqlList.get(1)).contains(" and t0.status = any(?)");
|
||||
} else {
|
||||
assertThat(sqlList.get(1)).contains("from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where t0.order_date is not null and (t0.kcustomer_id) = any");
|
||||
assertThat(sqlList.get(1)).contains(" and t0.status in ");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -69,14 +69,20 @@ public class TestSubQuery extends BaseTestCase {
|
||||
// execute the subQuery as copy (generatedSQL must be part of original query)
|
||||
Query<OrderDetail> debugSq = sq.copy();
|
||||
debugSq.findSingleAttribute();
|
||||
assertThat(debugSq.getGeneratedSql()).isEqualTo(
|
||||
"select t1.id from o_order_detail t0 join o_order t1 on t1.id = t0.order_id where t0.product_id in (?)");
|
||||
if (isPostgres()) {
|
||||
assertThat(debugSq.getGeneratedSql()).isEqualTo("select t1.id from o_order_detail t0 join o_order t1 on t1.id = t0.order_id where t0.product_id = any(?)");
|
||||
} else {
|
||||
assertThat(debugSq.getGeneratedSql()).isEqualTo("select t1.id from o_order_detail t0 join o_order t1 on t1.id = t0.order_id where t0.product_id in (?)");
|
||||
}
|
||||
|
||||
Query<Order> query = DB.find(Order.class).select("shipDate").where().isIn("id", sq).query();
|
||||
query.findSingleAttribute();
|
||||
|
||||
assertThat(query.getGeneratedSql())
|
||||
.isEqualTo("select t0.ship_date from o_order t0 where (t0.id) in (" + debugSq.getGeneratedSql() + ")");
|
||||
if (isPostgres()) {
|
||||
assertThat(query.getGeneratedSql()).isEqualTo("select t0.ship_date from o_order t0 where (t0.id) in (" + debugSq.getGeneratedSql() + ")");
|
||||
} else {
|
||||
assertThat(query.getGeneratedSql()).isEqualTo("select t0.ship_date from o_order t0 where (t0.id) in (" + debugSq.getGeneratedSql() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +114,7 @@ public class TestSubQuery extends BaseTestCase {
|
||||
List<Integer> productIds = new ArrayList<>();
|
||||
productIds.add(3);
|
||||
|
||||
Query<OrderDetail> sq = DB.createQuery(OrderDetail.class).fetch("order.shipments", "id").where()
|
||||
Query<OrderDetail> sq = DB.createQuery(OrderDetail.class).alias("a").fetch("order.shipments", "id").where()
|
||||
.isIn("product.id", productIds).query();
|
||||
|
||||
// execute the subQuery as copy (generatedSQL must be part of original query)
|
||||
|
||||
@@ -169,9 +169,9 @@ public class TestWhereRawClause extends BaseTestCase {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql.get(0)).isEqualTo("select t0.id, t0.name from o_customer t0 where t0.name = any(?); --bind(Array[3]={Rob,Fiona,Jack})");
|
||||
assertThat(sql.get(1)).isEqualTo("select t0.id, t0.name from o_customer t0; --bind()");
|
||||
assertThat(sql.get(2)).isEqualTo("select t0.id, t0.name from o_customer t0; --bind()");
|
||||
assertThat(sql.get(0)).contains("select t0.id, t0.name from o_customer t0 where t0.name = any(?);");
|
||||
assertThat(sql.get(1)).contains("select t0.id, t0.name from o_customer t0; --bind()");
|
||||
assertThat(sql.get(2)).contains("select t0.id, t0.name from o_customer t0; --bind()");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -76,7 +76,9 @@ public class SqlQueryCancelTest extends BaseTestCase {
|
||||
EBasic model = new EBasic("Basic " + i);
|
||||
DB.save(model);
|
||||
}
|
||||
SlowDownEBasic.setSelectWaitMillis(0);
|
||||
if (Platform.H2.equals(DB.getDefault().getPlatform())) {
|
||||
SlowDownEBasic.setSelectWaitMillis(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user