From 2b21588c903aa526c5586648ea35a5955673bfb9 Mon Sep 17 00:00:00 2001 From: Noemi Szemenyei Date: Tue, 15 Mar 2022 10:24:36 +0100 Subject: [PATCH] Created failing test case --- .../TestWithCacheAndLazyLoad.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/ebean-test/src/test/java/org/tests/model/lazywithcache/TestWithCacheAndLazyLoad.java b/ebean-test/src/test/java/org/tests/model/lazywithcache/TestWithCacheAndLazyLoad.java index 380f82c5d..8c8066dbc 100644 --- a/ebean-test/src/test/java/org/tests/model/lazywithcache/TestWithCacheAndLazyLoad.java +++ b/ebean-test/src/test/java/org/tests/model/lazywithcache/TestWithCacheAndLazyLoad.java @@ -2,9 +2,14 @@ package org.tests.model.lazywithcache; import io.ebean.BaseTestCase; import io.ebean.DB; +import io.ebean.Transaction; + import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.util.List; /** * Test with bean cache and lazy loaded property. @@ -47,5 +52,37 @@ public class TestWithCacheAndLazyLoad extends BaseTestCase{ assertThat(temp.getAddress()).isEqualTo("Address"); assertThat(temp.getName()).isEqualTo("Child With Cache"); } + + @Test + public void testBatch() throws Exception { + + for (int i = 0; i < 2; i++) { + ChildWithCache child = new ChildWithCache(); + child.setId(1000L+i); + child.setName("Child With Cache "+ i); + child.setAddress("Address"); + DB.save(child); + + ParentA parentA = new ParentA(); + parentA.setId(1000L+i); + parentA.setName("Parent A"); + parentA.setChild(child); + DB.save(parentA); + } + // 0. load cache + ParentA temp = DB.find(ParentA.class, 1000L); + temp.getChild().getName(); + + try (Transaction txn = DB.beginTransaction()) { + // 1. FindList + List list = DB.find(ParentA.class).where().ge("id", 1000L).orderBy("id").findList(); + // 2. FindById (first element from list) + temp = DB.find(ParentA.class, 1000L); + assertNotNull(temp.getChild().getName()); + // 3. access elements in list + assertNotNull(list.get(0).getChild().getAddress()); + assertNotNull(list.get(1).getChild().getAddress()); + } + } }