FIX: Clean up before running tests - otherwise tests will fail if a previous test did not clean up well. (This fixes test failures in Eclipse where tests are executed in different order than in maven) (#1089)

This commit is contained in:
Roland Praml
2017-08-30 17:44:30 +12:00
committed by Rob Bygrave
parent ff496ad2d3
commit a5bcd49ecb
6 changed files with 34 additions and 1 deletions
@@ -37,6 +37,7 @@ public class TestBatchLazyWithCacheHits extends BaseTestCase {
ServerCacheManager serverCacheManager = Ebean.getDefaultServer().getServerCacheManager();
ServerCache beanCache = serverCacheManager.getBeanCache(UUOne.class);
beanCache.clear();
beanCache.getStatistics(true); // Reset statistics - otherwise other tests will interfere
UUOne b = Ebean.find(UUOne.class, inserted.get(1).getId());
assertNotNull(b);
+2 -1
View File
@@ -1,5 +1,6 @@
package org.tests.inherit;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
@@ -16,7 +17,7 @@ public class Data {
private Integer val;
@ManyToMany(mappedBy = "data")
@ManyToMany(mappedBy = "data", cascade = CascadeType.ALL)
public List<Parent> parents = new ArrayList<>();
public Data(int number) {
@@ -4,6 +4,8 @@ import io.ebean.BaseTestCase;
import io.ebean.DuplicateKeyException;
import io.ebean.Ebean;
import io.ebean.annotation.Transactional;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -18,6 +20,11 @@ public class TestInsertDuplicateKey extends BaseTestCase {
private static final Logger log = LoggerFactory.getLogger(TestInsertDuplicateKey.class);
@Before
public void clearDb() {
server().find(Document.class).asDraft().where().contains("title", "UniqueKey").delete();
}
@Test(expected = DuplicateKeyException.class)
public void insert_duplicateKey() {
@@ -6,6 +6,7 @@ import org.tests.inherit.ChildA;
import org.tests.inherit.ChildB;
import org.tests.inherit.Data;
import org.tests.inherit.Parent;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
@@ -16,6 +17,14 @@ import static org.junit.Assert.assertNotNull;
public class ParentQueryTest extends BaseTestCase {
@Before
public void clearDb() {
Ebean.deleteAll(Ebean.find(Data.class).findList());
//@rob: this does not work as it does not clear the ManyToMany relations.
//Ebean.find(Data.class).delete();
Ebean.find(Parent.class).delete();
}
@Test
public void QueryParentCollectionFetch() {
@@ -11,6 +11,7 @@ import org.tests.inherit.Data;
import org.tests.inherit.EUncle;
import org.tests.inherit.Parent;
import org.tests.inherit.ParentAggregate;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
@@ -20,6 +21,14 @@ import static org.junit.Assert.*;
public class ParentRawSqlTest extends BaseTestCase {
@Before
public void clearDb() {
Ebean.deleteAll(Ebean.find(Data.class).findList());
//@rob: this does not work as it does not clear the ManyToMany relations.
//Ebean.find(Data.class).delete();
Ebean.find(Parent.class).delete();
}
@Test
public void RawSqlParentLoad() {
@@ -6,6 +6,7 @@ import io.ebean.text.json.JsonContext;
import io.ebean.text.json.JsonWriteOptions;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
@@ -13,6 +14,11 @@ import java.util.List;
public class TestTextJsonInvokeLazy extends BaseTestCase {
@Before
public void clearBeanCache() {
server().getPluginApi().getBeanType(Customer.class).clearBeanCache();
}
@Test
public void test() throws IOException {