From c0eb896e1fa0b7bd5889693a7c62cd51c22c6851 Mon Sep 17 00:00:00 2001 From: Noemi Praml <63635801+nPraml@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:10:50 +0100 Subject: [PATCH] No productive code change: cleanup basic test data (#114) * Erste Tests bereinigt * fix * noch mehr Tests bereinigt * modify output * reformat --- .../batchinsert/TestBatchInsertFlush.java | 3 ++ .../cache/TestBeanCacheContactLazyLoad.java | 38 +++++++++++-------- .../org/tests/model/basic/ResetBasicData.java | 15 +++++--- .../transaction/TestExecuteComplete.java | 6 ++- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/ebean-test/src/test/java/org/tests/batchinsert/TestBatchInsertFlush.java b/ebean-test/src/test/java/org/tests/batchinsert/TestBatchInsertFlush.java index 370aa41f9b..efe5a52db7 100644 --- a/ebean-test/src/test/java/org/tests/batchinsert/TestBatchInsertFlush.java +++ b/ebean-test/src/test/java/org/tests/batchinsert/TestBatchInsertFlush.java @@ -55,6 +55,9 @@ public void batchFlush() { DB.saveAll(customers); txn.commit(); + } finally { + DB.find(Customer.class).where().startsWith("name", "BatchFlush").delete(); + DB.find(Contact.class).where().startsWith("firstName", "Fred").startsWith("lastName", "Blue").delete(); } } diff --git a/ebean-test/src/test/java/org/tests/cache/TestBeanCacheContactLazyLoad.java b/ebean-test/src/test/java/org/tests/cache/TestBeanCacheContactLazyLoad.java index 9f4e077924..89a8c2bb0f 100644 --- a/ebean-test/src/test/java/org/tests/cache/TestBeanCacheContactLazyLoad.java +++ b/ebean-test/src/test/java/org/tests/cache/TestBeanCacheContactLazyLoad.java @@ -52,24 +52,30 @@ public void testBeanCacheWithLazyLoading() { DB.save(contact); - // Only get two properties, so we have to lazy-load later - final Contact contactDb = DB.find(Contact.class).where().eq("email", "tim@button.com").select("email,lastName").findOne(); - assertThat(contactDb).isNotNull(); - LoggedSql.start(); - contactDb.setLastName("Buttonnnn"); - List sql = LoggedSql.collect(); - assertThat(sql).isEmpty(); // setter did not trigger lazy load + try { - // trigger lazy load - assertThat(contactDb.getPhone()).isEqualTo("1234567890"); - sql = LoggedSql.collect(); - assertThat(sql).isNotEmpty(); // Lazy-load took place + // Only get two properties, so we have to lazy-load later + final Contact contactDb = DB.find(Contact.class).where().eq("email", "tim@button.com").select("email,lastName").findOne(); + assertThat(contactDb).isNotNull(); + LoggedSql.start(); + contactDb.setLastName("Buttonnnn"); + List sql = LoggedSql.collect(); + assertThat(sql).isEmpty(); // setter did not trigger lazy load - final Contact contactDb2 = DB.find(Contact.class).where().eq("email", "tim@button.com").select("email,lastName").findOne(); - sql = LoggedSql.stop(); - assertThat(sql).isEmpty(); // We expect that the bean was loaded from cache - assertThat(contactDb2).isNotNull(); - assertThat(contactDb2.getLastName()).isEqualTo("Button"); + // trigger lazy load + assertThat(contactDb.getPhone()).isEqualTo("1234567890"); + sql = LoggedSql.collect(); + assertThat(sql).isNotEmpty(); // Lazy-load took place + + final Contact contactDb2 = DB.find(Contact.class).where().eq("email", "tim@button.com").select("email,lastName").findOne(); + sql = LoggedSql.stop(); + assertThat(sql).isEmpty(); // We expect that the bean was loaded from cache + assertThat(contactDb2).isNotNull(); + assertThat(contactDb2.getLastName()).isEqualTo("Button"); + } finally { + DB.delete(customer); + DB.find(Contact.class).where().eq("email", "tim@button.com").delete(); + } } } diff --git a/ebean-test/src/test/java/org/tests/model/basic/ResetBasicData.java b/ebean-test/src/test/java/org/tests/model/basic/ResetBasicData.java index 063411b19c..46bbae04d9 100644 --- a/ebean-test/src/test/java/org/tests/model/basic/ResetBasicData.java +++ b/ebean-test/src/test/java/org/tests/model/basic/ResetBasicData.java @@ -26,7 +26,7 @@ public static synchronized void reset() { // OK, test data not modified outputCustomerIds(); } else { - outputState(); + outputState(true); } return; } @@ -45,11 +45,11 @@ public static synchronized void reset() { me.insertProducts(); me.insertTestCustAndOrders(); }); - outputState(); + outputState(false); runOnce = true; } - private static void outputState() { + private static void outputState(boolean warning) { StringBuilder sb = new StringBuilder(); sb.append("CustomerIds:"); server.find(Customer.class).findEach(c -> sb.append(' ').append(c.getId())); @@ -59,8 +59,13 @@ private static void outputState() { server.find(Country.class).findEach(c -> sb.append(' ').append(c.getCode())); sb.append(", Products:"); server.find(Product.class).findEach(c -> sb.append(' ').append(c.getId())); - System.err.println("WARNING: basic test data was modified. Current content:"); - System.err.println(sb); + if (warning) { + System.err.println("WARNING: basic test data was modified. Current content:"); + System.err.println(sb); + } else { + System.out.println("ResetBasicData. basic test data was initialized Current content:"); + System.out.println(sb); + } } private static void outputCustomerIds() { diff --git a/ebean-test/src/test/java/org/tests/transaction/TestExecuteComplete.java b/ebean-test/src/test/java/org/tests/transaction/TestExecuteComplete.java index 17841d1d88..db31d630fd 100644 --- a/ebean-test/src/test/java/org/tests/transaction/TestExecuteComplete.java +++ b/ebean-test/src/test/java/org/tests/transaction/TestExecuteComplete.java @@ -141,7 +141,11 @@ public void implicit_save_expect_threadScopeCleanup() { cust.setName("Roland"); DB.save(cust); - assertThat(getInScopeTransaction()).isNull(); + try { + assertThat(getInScopeTransaction()).isNull(); + } finally { + DB.delete(cust); + } } @ForPlatform(Platform.H2)