Skip to content

Commit

Permalink
Update tests to ensure ResetBasicData.reset() was called early
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Aug 4, 2024
1 parent 20caae5 commit b0ec23e
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 88 deletions.
3 changes: 2 additions & 1 deletion ebean-test/src/test/java/org/tests/basic/TestTransient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.ebean.DB;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;

import java.sql.Types;
import java.util.Optional;
Expand All @@ -16,7 +17,7 @@ public class TestTransient extends BaseTestCase {

@Test
public void testTransient() {

ResetBasicData.reset();
Customer cnew = new Customer();
cnew.setName("testTrans");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Contact;
import org.tests.model.basic.Customer;
Expand All @@ -13,11 +14,13 @@

public class TestBasicNavOnEmpty extends BaseTestCase {

@Test
public void test() {

@BeforeAll
static void before() {
ResetBasicData.reset();
}

@Test
public void test() {
Customer c = new Customer();
c.setName("HelloRob");

Expand Down
12 changes: 6 additions & 6 deletions ebean-test/src/test/java/org/tests/batchload/TestBeanState.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.ebean.bean.EntityBean;
import io.ebean.bean.EntityBeanIntercept;
import io.ebean.xtest.BaseTestCase;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
Expand All @@ -18,14 +19,18 @@

class TestBeanState extends BaseTestCase {

@BeforeAll
static void before() {
ResetBasicData.reset();
}

@Test
void invalid() {
assertThrows(IllegalArgumentException.class, () -> DB.beanState(new Object()));
}

@Test
void loadErrors_when_empty() {
ResetBasicData.reset();
Customer one = DB.find(Customer.class).setMaxRows(1).findOne();
BeanState beanState = DB.beanState(one);

Expand All @@ -34,8 +39,6 @@ void loadErrors_when_empty() {

@Test
void test() {
ResetBasicData.reset();

List<Customer> custs = DB.find(Customer.class).findList();

Customer customer = DB.find(Customer.class).setId(custs.get(0).getId()).select("name")
Expand Down Expand Up @@ -69,8 +72,6 @@ void test() {

@Test
void setDisableLazyLoad_expect_lazyLoadingDisabled() {
ResetBasicData.reset();

List<Customer> custs = DB.find(Customer.class).order("id").findList();

Customer customer = DB.find(Customer.class)
Expand All @@ -86,7 +87,6 @@ void setDisableLazyLoad_expect_lazyLoadingDisabled() {

@Test
void changedProps_when_setManyProperty() {
ResetBasicData.reset();

Customer customer = DB.find(Customer.class).order("id").setMaxRows(1).findOne();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import io.ebean.DB;
import io.ebean.xtest.base.TransactionalTestCase;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Contact;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
Expand All @@ -11,11 +12,13 @@

public class TestSecondQueryNoRows extends BaseTestCase {

@Test
public void test() {

@BeforeAll
static void before() {
ResetBasicData.reset();
}

@Test
public void test() {
Customer cnew = new Customer();
cnew.setName("testSecQueryNoRows");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import io.ebean.test.LoggedSql;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Contact;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;

import java.sql.Date;
import java.time.LocalDate;
Expand All @@ -18,6 +20,11 @@
*/
public class TestBeanCacheContactLazyLoad extends BaseTestCase {

@BeforeAll
static void before() {
ResetBasicData.reset();
}

/**
* This test shows a wrong behaviour of the bean cache up to at least Ebean 12.4.*:
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class TestCacheInterceptSaveWhenLazyLoaded extends BaseTestCase {

@Test
public void test() {

ResetBasicData.reset();

Customer customer = new Customer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.ebean.DB;
import io.ebean.Query;
import io.ebean.cache.ServerCache;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Address;
import org.tests.model.basic.Contact;
Expand All @@ -18,11 +19,14 @@

public class TestQueryCacheTableDependency extends BaseTestCase {

@BeforeAll
static void before() {
ResetBasicData.reset();
}

@Test
public void testFindCountOnDependent() {

ResetBasicData.reset();

ServerCache customerCache = DB.cacheManager().queryCache(Customer.class);
customerCache.clear();

Expand Down Expand Up @@ -95,8 +99,6 @@ public void testFindCountOnDependent() {
@Test
public void testFindCountOnOtherL2Cached() {

ResetBasicData.reset();

Customer fi = DB.find(Customer.class).where().eq("name", "Fiona").findOne();

int custCount0 = DB.find(Customer.class).setUseQueryCache(true).setReadOnly(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import io.ebean.xtest.BaseTestCase;
import io.ebean.text.json.JsonReadOptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.Product;
Expand All @@ -16,19 +17,19 @@

public class CustomerReportTest extends BaseTestCase {

@Test
public void testToJson() throws Exception {
@BeforeAll
static void before() {
ResetBasicData.reset();
}



@Test
public void testToJson() {
String json = server().json().toJson(getCustomerReport());
assertThat(json).isEqualTo("{\"dtype\":\"CR\",\"friends\":[{\"id\":2},{\"id\":3}],\"customer\":{\"id\":1}}");
}

@Test
public void testFromJson() throws Exception {
ResetBasicData.reset();
public void testFromJson() {
String json = "{\"dtype\":\"CR\",\"friends\":[{\"id\":2},{\"id\":3}],\"customer\":{\"id\":1}}";

JsonReadOptions opts = new JsonReadOptions();
Expand All @@ -43,9 +44,7 @@ public void testFromJson() throws Exception {


@Test
public void testEmbeddedDocs() throws Exception {
ResetBasicData.reset();

public void testEmbeddedDocs() {
CustomerReport report = getCustomerReport();
report.getEmbeddedReports().add(getProductReport());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.ebean.annotation.Platform;
import io.ebean.meta.*;
import io.ebean.test.LoggedSql;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
import org.tests.model.basic.EBasic;
Expand All @@ -19,11 +20,13 @@

public class TestCustomerFinder extends BaseTestCase {

@Test
public void a_runFirst_metricsAsJson_sqlInInitialCollectionOnly() {

@BeforeAll
static void before() {
ResetBasicData.reset();
}

@Test
public void a_runFirst_metricsAsJson_sqlInInitialCollectionOnly() {
runQueries();

StringBuilder buffer0 = new StringBuilder();
Expand Down Expand Up @@ -55,18 +58,12 @@ public void a_runFirst_metricsAsJson_sqlInInitialCollectionOnly() {

@Test
public void test_ref() {

ResetBasicData.reset();

Customer customer = Customer.find.ref(1);
assertThat(customer.getId()).isEqualTo(1);
}

@Test
public void test_all_byId_byName() {

ResetBasicData.reset();

List<Customer> all = Customer.find.all();
List<Customer> list = DB.find(Customer.class).findList();

Expand All @@ -93,7 +90,6 @@ public void currentTransaction() {

@Test
public void flush() {

Transaction transaction = DB.beginTransaction();
try {
Customer.find.currentTransaction().setBatchMode(true);
Expand All @@ -114,7 +110,6 @@ public void flush() {

@Test
public void test_byName_deleteById() {

Customer customer = new Customer();
customer.setName("Newbie-879879897");

Expand All @@ -134,16 +129,12 @@ public void test_byName_deleteById() {

@Test
public void test_update() {

int rowsUpdated = Customer.find.updateToInactive("Frankie Who");
logger.debug("updated {}", rowsUpdated);
}

@Test
public void test_ormQuery() {

ResetBasicData.reset();

List<Customer> customers =
Customer.find.byNameStatus("R", Customer.Status.NEW);

Expand All @@ -152,19 +143,13 @@ public void test_ormQuery() {

@Test
public void test_nativeSingleAttribute() {

ResetBasicData.reset();

List<String> names = Customer.find.namesStartingWith("F");
assertThat(names).isNotEmpty();
}

@Test
@IgnorePlatform(Platform.DB2) // no query plans yet, for DB2
public void test_finders_queryPlans() {

ResetBasicData.reset();

// change default collect query plan threshold to 20 micros
QueryPlanInit init0 = new QueryPlanInit();
init0.setAll(true);
Expand Down Expand Up @@ -219,9 +204,6 @@ public void test_finders_queryPlans() {

@Test
public void test_metricsAsJson_withAll() {

ResetBasicData.reset();

runQueries();

String metricsJson = server().metaInfo()
Expand All @@ -243,9 +225,6 @@ public void test_metricsAsJson_withAll() {

@Test
public void test_metricsAsJson_minimal() {

ResetBasicData.reset();

runQueries();

String metricsJson = server().metaInfo()
Expand All @@ -265,9 +244,6 @@ public void test_metricsAsJson_minimal() {

@Test
public void test_metricsAsJson_write() {

ResetBasicData.reset();

runQueries();

StringBuilder buffer = new StringBuilder();
Expand All @@ -283,9 +259,6 @@ public void test_metricsAsJson_write() {

@Test
public void test_metricsAsJson_writeWithHeader() {

ResetBasicData.reset();

runQueries();

StringBuilder buffer = new StringBuilder();
Expand Down
Loading

0 comments on commit b0ec23e

Please sign in to comment.