package org.jugile.daims;
import org.jugile.proto2.common.FamilyType;
import org.jugile.proto2.domain.Domain;
import org.jugile.proto2.domain.Family;
import org.jugile.proto2.domain.Person;
import org.jugile.util.JugileTestCase;
import org.jugile.util.Time;
public class CreateAndVerifyTest extends JugileTestCase {
private static long pid1;
private static long pid2;
private static long fid1;
private static long fid2;
public void testCreateAndVerify() {
Domain.reset();
Domain d = Domain.getDomain();
createDomain(d);
verifyDomain(d); // before commit, all is in uow
d.commit();
verifyDomain(d); // after commit, all is now in dd
d.rollback();
}
public static void createDomain(Domain d) {
Person p1 = d.createPerson();
p1.setName("Jukka");
p1.setAge(10);
p1.setTs(new Time("11.11.2011"));
pid1 = p1.id();
Family f1 = d.createFamily().setName("f1");
f1.setType(FamilyType.BIG);
fid1 = f1.id();
Family f2 = d.createFamily().setName("f2");
fid2 = f2.id();
Person p2 = d.createPerson().setName("p2");
pid2 = p2.id();
p1.setFamily(f1);
p1.addFriendFamily(f1);
p1.addFriendFamily(f2);
f1.addFriendPerson(p2);
Person c1 = d.createPerson().setName("c1");
c1.setParent(p1);
}
public static void verifyDomain(Domain d) {
print("stats: " + d.stats());
print(" families: " + d.getFamilies().size());
assertTrue(d.getPersons().size() > 2);
Person p1 = d.getPerson(pid1);
assertEquals("Jukka",p1.getName());
assertEquals(10,p1.getAge());
assertEquals(new Time("11.11.2011"),p1.getTs());
Family f1 = p1.getFamily();
assertNotNull(f1);
assertEquals("f1", f1.getName());
assertEquals(FamilyType.BIG, f1.getType());
assertEquals(2, p1.getFriendFamilies().size());
Person p2 = d.getPerson(pid2);
assertEquals(1, p2.getFriendFamilies().size());
assertEquals(2, f1.getFriendPersons().size());
assertEquals(1, p1.getChildren().size());
}
}