mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Update tests only - handle MySql specifics (boolean literal, lack of order by nulls last)
This commit is contained in:
@@ -7,6 +7,8 @@ import org.avaje.agentloader.AgentLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
public class BaseTestCase {
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(BaseTestCase.class);
|
||||
@@ -50,18 +52,27 @@ public class BaseTestCase {
|
||||
* so tests that do this need to be skipped for SQL Server.
|
||||
*/
|
||||
public boolean isMsSqlServer() {
|
||||
SpiEbeanServer spi = (SpiEbeanServer)Ebean.getDefaultServer();
|
||||
return spi.getDatabasePlatform().getName().startsWith("mssqlserver");
|
||||
return platformName().startsWith("mssqlserver");
|
||||
}
|
||||
|
||||
public boolean isH2() {
|
||||
SpiEbeanServer spi = (SpiEbeanServer)Ebean.getDefaultServer();
|
||||
return spi.getDatabasePlatform().getName().equals("h2");
|
||||
return platformName().equals("h2");
|
||||
}
|
||||
|
||||
public boolean isPostgres() {
|
||||
SpiEbeanServer spi = (SpiEbeanServer)Ebean.getDefaultServer();
|
||||
return spi.getDatabasePlatform().getName().equals("postgres");
|
||||
return platformName().equals("postgres");
|
||||
}
|
||||
|
||||
public boolean isMySql() {
|
||||
return platformName().equals("mysql");
|
||||
}
|
||||
|
||||
public boolean isPlatformBooleanNative() {
|
||||
return Types.BOOLEAN == spiEbeanServer().getDatabasePlatform().getBooleanDbType();
|
||||
}
|
||||
|
||||
public boolean isPlatformOrderNullsSupport() {
|
||||
return isH2() || isPostgres();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,6 +86,10 @@ public class BaseTestCase {
|
||||
return spiEbeanServer().getBeanDescriptor(cls);
|
||||
}
|
||||
|
||||
protected String platformName() {
|
||||
return spiEbeanServer().getDatabasePlatform().getName();
|
||||
}
|
||||
|
||||
protected SpiEbeanServer spiEbeanServer() {
|
||||
return (SpiEbeanServer) Ebean.getDefaultServer();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ public class UpdateQueryTest extends BaseTestCase {
|
||||
@Test
|
||||
public void withJoin() {
|
||||
|
||||
if (isMySql()) {
|
||||
return;
|
||||
}
|
||||
EbeanServer server = server();
|
||||
|
||||
Country nz = server.getReference(Country.class, "NZ");
|
||||
|
||||
@@ -368,6 +368,10 @@ public class EqlParserTest extends BaseTestCase {
|
||||
@Test
|
||||
public void orderBy_nullsLast() throws Exception {
|
||||
|
||||
if (!isPlatformOrderNullsSupport()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = parse("order by id desc nulls last");
|
||||
@@ -380,6 +384,9 @@ public class EqlParserTest extends BaseTestCase {
|
||||
@Test
|
||||
public void orderBy_nullsFirst() throws Exception {
|
||||
|
||||
if (!isPlatformOrderNullsSupport()) {
|
||||
return;
|
||||
}
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = parse("order by id nulls first");
|
||||
@@ -392,6 +399,9 @@ public class EqlParserTest extends BaseTestCase {
|
||||
@Test
|
||||
public void orderBy_multiple() throws Exception {
|
||||
|
||||
if (!isPlatformOrderNullsSupport()) {
|
||||
return;
|
||||
}
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = parse("order by billingAddress.city desc nulls last, name, id desc nulls last");
|
||||
|
||||
+22
-6
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.model.onetoone.album;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.Transaction;
|
||||
@@ -13,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class DeleteById_SoftDelete_Tests {
|
||||
public class DeleteById_SoftDelete_Tests extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void ebean_deleteById_when_softDelete() {
|
||||
@@ -27,7 +28,11 @@ public class DeleteById_SoftDelete_Tests {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=true where id = ?");
|
||||
if (isPlatformBooleanNative()) {
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=true where id = ?");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=1 where id = ?");
|
||||
}
|
||||
|
||||
cover.deletePermanent();
|
||||
}
|
||||
@@ -76,8 +81,11 @@ public class DeleteById_SoftDelete_Tests {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=true where id = ?");
|
||||
|
||||
if (isPlatformBooleanNative()) {
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=true where id = ?");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=1 where id = ?");
|
||||
}
|
||||
cover.deletePermanent();
|
||||
}
|
||||
|
||||
@@ -109,7 +117,11 @@ public class DeleteById_SoftDelete_Tests {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=true where id in (?,?)");
|
||||
if (isPlatformBooleanNative()) {
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=true where id in (?,?)");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=1 where id in (?,?)");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,7 +143,11 @@ public class DeleteById_SoftDelete_Tests {
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=true where id in (?,?)");
|
||||
if (isPlatformBooleanNative()) {
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=true where id in (?,?)");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("update cover set deleted=1 where id in (?,?)");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.query.softdelete;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.PagedList;
|
||||
import com.avaje.tests.model.onetoone.album.Cover;
|
||||
@@ -11,7 +12,7 @@ import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestSoftDeletePagingList {
|
||||
public class TestSoftDeletePagingList extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
@@ -41,9 +42,17 @@ public class TestSoftDeletePagingList {
|
||||
|
||||
assertThat(sql).hasSize(2);
|
||||
assertThat(sql.get(0)).contains("select count(*) from cover t0 where t0.s3url like");
|
||||
assertThat(sql.get(0)).contains("and coalesce(t0.deleted,false)=false; --bind(SoftDelPaged-%)");
|
||||
if (isPlatformBooleanNative()) {
|
||||
assertThat(sql.get(0)).contains("and coalesce(t0.deleted,false)=false; --bind(SoftDelPaged-%)");
|
||||
} else {
|
||||
assertThat(sql.get(0)).contains("and coalesce(t0.deleted,0)=0; --bind(SoftDelPaged-%)");
|
||||
}
|
||||
|
||||
assertThat(sql.get(1)).contains("where t0.s3url like ");
|
||||
assertThat(sql.get(1)).contains("and coalesce(t0.deleted,false)=false order by t0.id");
|
||||
if (isPlatformBooleanNative()) {
|
||||
assertThat(sql.get(1)).contains("and coalesce(t0.deleted,false)=false order by t0.id");
|
||||
} else {
|
||||
assertThat(sql.get(1)).contains("and coalesce(t0.deleted,0)=0 order by t0.id");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class TestRawSqlOrmQuery extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
RawSql rawSql = RawSqlBuilder.parse("select o.id, o.order_date, o.ship_date from o_order o order by o.ship_date desc nulls last")
|
||||
RawSql rawSql = RawSqlBuilder.parse("select o.id, o.order_date, o.ship_date from o_order o order by o.ship_date desc")
|
||||
.columnMapping("o.id", "id")
|
||||
.columnMapping("o.order_date", "orderDate")
|
||||
.columnMapping("o.ship_date", "shipDate")
|
||||
@@ -144,7 +144,7 @@ public class TestRawSqlOrmQuery extends BaseTestCase {
|
||||
query.setMaxRows(100);
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains("order by o.ship_date desc nulls last, o.id limit 100");
|
||||
assertThat(query.getGeneratedSql()).contains("order by o.ship_date desc, o.id limit 100");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,7 +173,7 @@ public class TestRawSqlOrmQuery extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
RawSql rawSql = RawSqlBuilder.parse("select o.id, o.order_date, o.ship_date from o_order o order by o.ship_date desc nulls last")
|
||||
RawSql rawSql = RawSqlBuilder.parse("select o.id, o.order_date, o.ship_date from o_order o order by o.ship_date desc")
|
||||
.columnMapping("o.id", "id")
|
||||
.columnMapping("o.order_date", "orderDate")
|
||||
.columnMapping("o.ship_date", "shipDate")
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
package com.avaje.tests.singleTableInheritance.model;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="warehouses")
|
||||
public class Warehouse {
|
||||
@Id
|
||||
@Column(name="id")
|
||||
private Integer id;
|
||||
|
||||
@ManyToOne//(optional = false) //todo: should this be nullable with assertions made?
|
||||
@JoinColumn(name = "officeZoneId")
|
||||
private ZoneInternal officeZone;
|
||||
|
||||
@ManyToMany(cascade = CascadeType.PERSIST)
|
||||
@JoinTable(name = "WarehousesShippingZones",
|
||||
joinColumns = { @JoinColumn(name = "warehouseId", referencedColumnName = "ID") },
|
||||
inverseJoinColumns = { @JoinColumn(name = "shippingZoneId", referencedColumnName = "ID") }
|
||||
)
|
||||
private Set<ZoneExternal> shippingZones;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ZoneInternal getOfficeZone() {
|
||||
return officeZone;
|
||||
}
|
||||
|
||||
public void setOfficeZone(ZoneInternal officeZone) {
|
||||
this.officeZone = officeZone;
|
||||
}
|
||||
|
||||
public Set<ZoneExternal> getShippingZones() {
|
||||
return shippingZones;
|
||||
}
|
||||
|
||||
public void setShippingZones(Set<ZoneExternal> shippingZones) {
|
||||
this.shippingZones = shippingZones;
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.tests.singleTableInheritance.model;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name="warehouses")
|
||||
public class Warehouse {
|
||||
@Id
|
||||
@Column(name="id")
|
||||
private Integer id;
|
||||
|
||||
@ManyToOne//(optional = false) //todo: should this be nullable with assertions made?
|
||||
@JoinColumn(name = "officeZoneId")
|
||||
private ZoneInternal officeZone;
|
||||
|
||||
@ManyToMany(cascade = CascadeType.PERSIST)
|
||||
@JoinTable(name = "warehousesshippingzones",
|
||||
joinColumns = { @JoinColumn(name = "warehouseId", referencedColumnName = "ID") },
|
||||
inverseJoinColumns = { @JoinColumn(name = "shippingZoneId", referencedColumnName = "ID") }
|
||||
)
|
||||
private Set<ZoneExternal> shippingZones;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ZoneInternal getOfficeZone() {
|
||||
return officeZone;
|
||||
}
|
||||
|
||||
public void setOfficeZone(ZoneInternal officeZone) {
|
||||
this.officeZone = officeZone;
|
||||
}
|
||||
|
||||
public Set<ZoneExternal> getShippingZones() {
|
||||
return shippingZones;
|
||||
}
|
||||
|
||||
public void setShippingZones(Set<ZoneExternal> shippingZones) {
|
||||
this.shippingZones = shippingZones;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user