mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Feature/contitional test runner (#1132)
* FIX: warnings (add generics, overrides, fix imports) - should be no effecive code change * replaced deprecated methods by default methods * FIX: more compiler warnings * FIX more warnings - no code changes * FIX: deprecated call to JsonParseException * Remove unused code, check unused variables * ADD: ContitonaltestRunner to skip tests for certain platforms * Use annotations to control on which platforms a test shoud run * FIX: compile errors
This commit is contained in:
committed by
Rob Bygrave
parent
f3e4696498
commit
8d334ff2e8
@@ -2,6 +2,8 @@ package org.tests.basic;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Platform;
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.metaannotation.SizeMedium;
|
||||
import org.junit.Test;
|
||||
@@ -9,6 +11,7 @@ import org.junit.Test;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Very simple test case to check if Ebean recognizes meta-annotation correctly.
|
||||
@@ -46,17 +49,16 @@ public class TestMetaAnnotation extends BaseTestCase {
|
||||
* This test writes 101 spaces to "line1" which is annotated with @Size(max=100).
|
||||
*/
|
||||
@Test
|
||||
@IgnorePlatform({Platform.POSTGRES, Platform.SQLSERVER, Platform.MYSQL}) // pg & mssql does not fail if string is too long.
|
||||
public void testWrite101SpacesToLine1() {
|
||||
|
||||
if (isH2()) {
|
||||
Address address = new Address();
|
||||
address.setLine1(spaces101);
|
||||
try {
|
||||
Ebean.save(address);
|
||||
assertTrue("H2 fails this insert", false);
|
||||
} catch (PersistenceException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
Address address = new Address();
|
||||
address.setLine1(spaces101);
|
||||
try {
|
||||
Ebean.save(address);
|
||||
fail("Test failed, Could insert a too long string");
|
||||
} catch (PersistenceException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,17 +66,16 @@ public class TestMetaAnnotation extends BaseTestCase {
|
||||
* This test writes 101 spaces to "line1" which is meta-annotated with {@link SizeMedium}.
|
||||
*/
|
||||
@Test
|
||||
@IgnorePlatform({Platform.POSTGRES, Platform.SQLSERVER, Platform.MYSQL})
|
||||
public void testWrite101SpacesToLine2() {
|
||||
|
||||
if (isH2()) {
|
||||
Address address = new Address();
|
||||
address.setLine2(spaces101);
|
||||
try {
|
||||
Ebean.save(address);
|
||||
assertTrue("H2 fails this insert", false);
|
||||
} catch (PersistenceException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
Address address = new Address();
|
||||
address.setLine2(spaces101);
|
||||
try {
|
||||
Ebean.save(address);
|
||||
fail("Test failed, Could insert a too long string");
|
||||
} catch (PersistenceException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,11 @@ import io.ebean.AcquireLockException;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.Platform;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
@@ -17,37 +20,38 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestQueryForUpdate extends BaseTestCase {
|
||||
|
||||
private boolean isSupportLocking() {
|
||||
return isH2() || isOracle() || isPostgres() || isSqlServer() || isMySql();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@ForPlatform({
|
||||
Platform.H2, Platform.ORACLE, Platform.POSTGRES, Platform.SQLSERVER, Platform.MYSQL
|
||||
})
|
||||
public void testForUpdate() {
|
||||
|
||||
if (isSupportLocking()) {
|
||||
ResetBasicData.reset();
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.forUpdate()
|
||||
.setMaxRows(1)
|
||||
.order().desc("id");
|
||||
|
||||
query.findList();
|
||||
if (isSqlServer()) {
|
||||
assertThat(sqlOf(query)).contains("with (updlock)");
|
||||
} else {
|
||||
assertThat(sqlOf(query)).contains("for update");
|
||||
}
|
||||
if (isSqlServer()) {
|
||||
assertThat(sqlOf(query)).contains("with (updlock)");
|
||||
} else {
|
||||
assertThat(sqlOf(query)).contains("for update");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForPlatform({
|
||||
Platform.H2, Platform.ORACLE, Platform.POSTGRES, Platform.SQLSERVER
|
||||
})
|
||||
public void testForUpdate_noWait() {
|
||||
|
||||
if (isSupportLocking()) {
|
||||
ResetBasicData.reset();
|
||||
ResetBasicData.reset();
|
||||
|
||||
EbeanServer server = Ebean.getDefaultServer();
|
||||
|
||||
EbeanServer server = Ebean.getDefaultServer();
|
||||
|
||||
Ebean.beginTransaction();
|
||||
try {
|
||||
@@ -83,9 +87,8 @@ public class TestQueryForUpdate extends BaseTestCase {
|
||||
txn2.end();
|
||||
}
|
||||
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
} finally {
|
||||
Ebean.endTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,16 @@ package org.tests.basic.encrypt;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Platform;
|
||||
import io.ebean.SqlQuery;
|
||||
import io.ebean.SqlRow;
|
||||
import io.ebean.Update;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.config.dbplatform.DbEncrypt;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.tests.model.basic.EBasicEncrypt;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Date;
|
||||
@@ -22,13 +23,9 @@ public class TestEncrypt extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
@ForPlatform(Platform.H2) // only run this on H2 - PGCrypto not happy on CI server
|
||||
public void testQueryBind() {
|
||||
|
||||
if (!isH2()) {
|
||||
// only run this on H2 - PGCrypto not happy on CI server
|
||||
return;
|
||||
}
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
Ebean.find(EBasicEncrypt.class)
|
||||
.where().startsWith("description", "Rob")
|
||||
@@ -39,8 +36,8 @@ public class TestEncrypt extends BaseTestCase {
|
||||
assertThat(loggedSql.get(0)).contains("; --bind(****,Rob%)");
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
@ForPlatform(Platform.H2)
|
||||
public void test() {
|
||||
|
||||
Update<EBasicEncrypt> deleteAll = Ebean.createUpdate(EBasicEncrypt.class, "delete from EBasicEncrypt");
|
||||
|
||||
Reference in New Issue
Block a user