Package org.jugile.daims

Source Code of org.jugile.daims.CommitTest

package org.jugile.daims;

import org.jugile.proto2.domain.*;
import org.jugile.util.JugileTestCase;
import org.jugile.util.Time;

public class CommitTest extends JugileTestCase {

  public void setUp() {
    Domain d = Domain.getDomain();
    for (Person o : d.getPersons()) o.delete();
    for (Family o : d.getFamilies()) o.delete();
    d.commit();
  }

  public void testTypes() {
    Domain d = Domain.getDomain();
    assertEquals(0,d.getPersons().size());
   
    Person p = d.createPerson();
    p.setName("Jukka");
    p.setAge(10);
    p.setTs(new Time("11.11.2011"));
    assertTrue(d.getCommitSize() > 0);
    assertEquals(1,d.getPersons().size());
    d.commit();
    assertTrue(d.getCommitSize() == 0);

    assertEquals(1,d.getPersons().size());
    Person p1 = d.getPerson(p.id());
    assertEquals("Jukka",p1.getName());
    assertEquals(10,p1.getAge());
    assertEquals(new Time("11.11.2011"),p1.getTs());
    d.rollback();
  }
 
  public void test1N() {
    Domain.reset();
    Domain d = Domain.getDomain();
    Person p = d.createPerson();
    p.setName("p1");
    Family f = d.createFamily();
    f.setName("f1");
    p.setFamily(f);
    assertEquals(1,f.getPersons().size());
    d.commit();
   
    Person p1 = d.getPerson(p.id());
    assertNotNull(p1.getFamily());
   
    Family f1 = d.getFamily(f.id());
    assertEquals(1,f1.getPersons().size());
    d.dump("test");
   
    f1.removePerson(p1);
    d.dump("removed");
    assertEquals(0,f1.getPersons().size());
    d.commit();
   
    p1 = d.getPerson(p.id());
    assertNull(p1.getFamily());
   
    f1 = d.getFamily(f.id());
    assertEquals(0,f1.getPersons().size());

    Person p2 = d.createPerson().setName("p2");
    Person p3 = d.createPerson().setName("p3");
    f1.removePerson(p2);
    f1.removePerson(p3);
    assertEquals(0,f1.getPersons().size());
   
    d.commit();
    f1 = d.getFamily(f.id());
    assertEquals(0,f1.getPersons().size());
    d.rollback();
  }

  public void testNN() {
    Domain.reset();
    Domain d = Domain.getDomain();
    Person p1 = d.createPerson().setName("p1");
    Person p2 = d.createPerson().setName("p2");
    Family f1 = d.createFamily().setName("f1");
    Family f2 = d.createFamily().setName("f2");
    p1.addFriendFamily(f1);
    assertEquals(1,f1.getFriendPersons().size());
    p2.addFriendFamily(f1);
    assertEquals(2,f1.getFriendPersons().size());
    assertEquals(1,p2.getFriendFamilies().size());
   
    d.commit();

    Person p11 = d.getPerson(p1.id());
    Family f11 = d.getFamily(f1.id());
   
    assertEquals(2,f11.getFriendPersons().size());
    assertEquals(1,p11.getFriendFamilies().size());

    f11.removeFriendPerson(p11);
    assertEquals(1,f11.getFriendPersons().size());
    assertEquals(0,p11.getFriendFamilies().size());
   
    d.dump("nn - f1 removed person p1 - before commit");
    d.commit();
   
    p11 = d.getPerson(p1.id());
    f11 = d.getFamily(f1.id());
    d.dump("nn - f1 removed person p1");
    assertEquals(1,f11.getFriendPersons().size());
    assertEquals(0,p11.getFriendFamilies().size());
    d.rollback();
  }
 
  public void testDeleteCreated() {
    Domain d = Domain.getDomain();
    Person p = d.createPerson().setName("dp1");
    p.delete();
    d.commit();
    assertNull(d.getPerson(p.id()));
  }
 
}
TOP

Related Classes of org.jugile.daims.CommitTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.