extended the test cases

This commit is contained in:
Roland Praml committed 2016-11-11 09:57:13 +01:00
1 parent e4e850717d
commit 56c96923c4
3 files changed
+44 -9

No files matched your search

@@ -104,9 +104,16 @@ public class TestInheritance extends BaseTestCase {
//grandparent1 = server().find(GrandParentPerson.class).setId(grandparent1.getIdentifier()).where()
// .in("effectiveBean.id",2,null) // geht nicht!
// .findUnique();
grandparent1 = server().find(GrandParentPerson.class).setId(grandparent1.getIdentifier()).where()
parent1 = server().find(ParentPerson.class).setId(1).fetch("someBean").findUnique();
assertEquals("A Bean", parent1.getSomeBean().getName());
grandparent1 = server().find(GrandParentPerson.class)
.fetch("children","*") // FIXME If I do not fetch childrenBean, I will get an exception
.fetch("children.effectiveBean","*")
.fetch("children.children","*")
.fetch("children.children.effectiveBean","*")
.setId(grandparent1.getIdentifier()).where()
.or()
.in("effectiveBean.id",2)
.in("effectiveBean.id",1)
.isNull("effectiveBean.id")
.endOr()
.findUnique();
@@ -120,7 +127,7 @@ public class TestInheritance extends BaseTestCase {
assertEquals("Josef", grandparent1.getName());
assertEquals("Foo", grandparent1.getFamilyName());
assertEquals("Munich", grandparent1.getAddress());
// assertEquals(2, grandparent1.getEffectiveBean().getId().intValue());
assertEquals(1, grandparent1.getEffectiveBean().getId().intValue());
// now check children of grandparent
parent1 = grandparent1.getChildren().get(0);
@@ -185,5 +192,32 @@ public class TestInheritance extends BaseTestCase {
assertEquals("Berlin", child3.getEffectiveAddress());
assertNull(child3.getEffectiveBean());
// Now start from bottom up
child2 = server().find(ChildPerson.class).where().eq("name", "Julia").select("parent.name").findUnique();
assertEquals("Baz", child2.getEffectiveFamilyName());
assertEquals("Munich", child2.getEffectiveAddress());
assertNull(child2.getSomeBean());
assertEquals("A Bean", child2.getEffectiveBean().getName());
parent1 = child2.getParent();
assertEquals("Maria", parent1.getName());
assertEquals("Bar", parent1.getFamilyName()); // overwritten family name
assertEquals("Bar", parent1.getEffectiveFamilyName()); // test inheritance
assertNull(parent1.getAddress()); // no alternative address set
assertEquals("Munich", parent1.getEffectiveAddress()); // -> inherit munich
assertEquals(2, parent1.getChildCount().intValue());
assertEquals(21, parent1.getTotalAge().intValue());
assertEquals("A Bean", parent1.getEffectiveBean().getName());
grandparent1 = parent1.getParent();
// check if aggregation works
assertEquals(3, grandparent1.getChildCount().intValue());
assertEquals(150, grandparent1.getTotalAge().intValue());
// check normal properties
assertEquals("Josef", grandparent1.getName());
assertEquals("Foo", grandparent1.getFamilyName());
assertEquals("Munich", grandparent1.getAddress());
assertEquals(1, grandparent1.getEffectiveBean().getId().intValue());
}
}
@@ -20,7 +20,7 @@ public class GrandParentPerson extends InheritablePerson {
// This rather complex formulas should be built later by CustomAnnotationParser
private static final String PARENT_PERSON_AGGREGATE_JOIN = "left join "
+ "(select parent_identifier, count(*) as child_count, sum(age) as child_age from parent_person group by parent_identifier) "
+ "(select i1.parent_identifier, count(*) as child_count, sum(i1.age) as child_age from parent_person i1 group by i1.parent_identifier) "
+ "as f1 on f1.parent_identifier = ${ta}.identifier";
//@Count("children")
@@ -36,7 +36,8 @@ public class GrandParentPerson extends InheritablePerson {
private String address;
@Formula(select = "${ta}.some_bean_id+1")
// Demonstrate formula usage
@Formula(select = "coalesce(${ta}.some_bean_id,1)")
@ManyToOne
private EBasic effectiveBean;
@@ -18,8 +18,8 @@ public class ParentPerson extends InheritablePerson {
//This rather complex formulas should be built later by CustomAnnotationParser
private static final String CHILD_PERSON_AGGREGATE_JOIN = "left join "
+ "(select parent_identifier, count(*) as child_count, sum(age) as child_age from child_person group by parent_identifier) "
+ "as f1 on f1.parent_identifier = ${ta}.identifier";
+ "(select i2.parent_identifier, count(*) as child_count, sum(i2.age) as child_age from child_person i2 group by i2.parent_identifier) "
+ "as f2 on f2.parent_identifier = ${ta}.identifier";
private static final String GRAND_PARENT_PERSON_JOIN = "join grand_parent_person j1 on j1.identifier = ${ta}.parent_identifier";
@@ -30,11 +30,11 @@ public class ParentPerson extends InheritablePerson {
private List<ChildPerson> children = new ArrayList<>();
//@Count("children")
@Formula(select = "coalesce(f1.child_count, 0)", join = CHILD_PERSON_AGGREGATE_JOIN )
@Formula(select = "coalesce(f2.child_count, 0)", join = CHILD_PERSON_AGGREGATE_JOIN )
private Integer childCount;
//@Sum("children.age")
@Formula(select = "coalesce(f1.child_age, 0)", join = CHILD_PERSON_AGGREGATE_JOIN )
@Formula(select = "coalesce(f2.child_age, 0)", join = CHILD_PERSON_AGGREGATE_JOIN )
private Integer totalAge;
private String familyName;