Skip to content

Commit

Permalink
No productive code change: cleanup basic test data (#114)
Browse files Browse the repository at this point in the history
* Erste Tests bereinigt

* fix

* noch mehr Tests bereinigt

* modify output

* reformat
  • Loading branch information
nPraml committed Nov 5, 2024
1 parent 7035b4c commit c0eb896
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String> 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();
}
}

}
15 changes: 10 additions & 5 deletions ebean-test/src/test/java/org/tests/model/basic/ResetBasicData.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static synchronized void reset() {
// OK, test data not modified
outputCustomerIds();
} else {
outputState();
outputState(true);
}
return;
}
Expand All @@ -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()));
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c0eb896

Please sign in to comment.