Clean up of test for #162

This commit is contained in:
rbygrave
2014-07-10 21:23:45 +12:00
parent 0543745e18
commit 713ba4889d
@@ -33,35 +33,27 @@ public class TestSelfRefExample extends BaseTestCase {
Ebean.save(e8);
Query<SelfRefExample> examples = Ebean.createQuery(SelfRefExample.class);
List<SelfRefExample> findList = examples.where().eq("name", "test1").findList();
List<SelfRefExample> list = examples.where().eq("name", "test1").findList();
System.out.println("Amount of Example instances with name 'test1' is 2: " + (findList.size() == 2));
Assert.assertEquals(2, findList.size());
Assert.assertEquals(2, list.size());
//The first Example is e1. e2 is the first child of e1. e3 is the first child of e2.
SelfRefExample e3Example = findList.get(0).getChildren().get(0).getChildren().get(0);
SelfRefExample e3Example = list.get(0).getChildren().get(0).getChildren().get(0);
//ID should be 3, since this has to be e3.
System.out.println(e3Example.getId());
Assert.assertEquals(e3.getId(), e3Example.getId());
//Now that we have e3, it should also have a child: e7.
System.out.println(e3Example.getChildren());
Assert.assertEquals(1, e3Example.getChildren().size());
//However, the output is: BeanList size[0] hasMoreRows[false] list[]
//The reason I see behind this is that e1 and e2 both matched the query built by the finder. So they were retrieved from the DB and so were their fields, including children like e3.
//But e3 did not match the query from the finder and so its children were not fetched, which is not what I was expecting.
//I was expecting that first the 2 matching instances would be retrieved and then all their children, regardless of them meeting the query or not.
Assert.assertEquals(e7.getId(), e3Example.getChildren().get(0).getId());
// If we get all the items, you can see the structure goes down a fair bit further.
Query<SelfRefExample> examples2 = Ebean.createQuery(SelfRefExample.class);
List<SelfRefExample> findList2 = examples2.findList();
System.out.println(findList2.get(0));
System.out.println(findList2.get(0).getChildren().get(0));
System.out.println(findList2.get(0).getChildren().get(0).getChildren().get(0));
System.out.println(findList2.get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0));
System.out.println(findList2.get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0));
Query<SelfRefExample> examples2 = Ebean.createQuery(SelfRefExample.class).orderBy("id asc");
List<SelfRefExample> list2 = examples2.findList();
Assert.assertEquals(e1.getId(), list2.get(0).getId());
Assert.assertEquals(e2.getId(), list2.get(0).getChildren().get(0).getId());
Assert.assertEquals(e3.getId(), list2.get(0).getChildren().get(0).getChildren().get(0).getId());
Assert.assertEquals(e7.getId(), list2.get(0).getChildren().get(0).getChildren().get(0).getChildren().get(0).getId());
}
}