Package siena.base.test.model

Examples of siena.base.test.model.RelatedManyChild


 
  public void testRelatedManyOldInsertWay() {
    RelatedManyParent god = new RelatedManyParent("god");
    god.insert();

    RelatedManyChild adam1 = new RelatedManyChild("adam1");
    adam1.owner = god;
    adam1.insert();
   
    RelatedManyChild adam2 = new RelatedManyChild("adam2");
    adam2.owner = god;
    adam2.insert();

    assertNotNull(god.id);
    assertEquals(god.id, adam1.owner.id);
    assertEquals(god.id, adam2.owner.id);
   
View Full Code Here


    assertEquals(adam2, children.get(1));
  }
 
  public void testRelatedManyCascadeInsert() {
    RelatedManyParent god = new RelatedManyParent("god");
    RelatedManyChild adam1 = new RelatedManyChild("adam1");
    RelatedManyChild adam2 = new RelatedManyChild("adam2");
    god.children.asList().add(adam1);
    god.children.asList().add(adam2);
    god.insert();

    assertNotNull(god.id);
View Full Code Here

    assertEquals(adam2, children.get(1));
  }
 
  public void testRelatedManyCascadeInsertFetch() {
    RelatedManyParent god = new RelatedManyParent("god");
    RelatedManyChild adam1 = new RelatedManyChild("adam1");
    RelatedManyChild adam2 = new RelatedManyChild("adam2");
    god.children.asList().add(adam1);
    god.children.asList().add(adam2);
    god.insert();

    assertNotNull(god.id);
View Full Code Here

 
  public void testRelatedManyCascadeInsertMany() {
    RelatedManyParent god = new RelatedManyParent("god");   
    List<RelatedManyChild> adams = new ArrayList<RelatedManyChild>();
    for(int i=0; i<100; i++){
      RelatedManyChild adam = new RelatedManyChild("adam"+i);
      god.children.asList().add(adam);
      adams.add(adam);
    }
    god.insert();
View Full Code Here

 
  public void testRelatedManyCascadeUpdateMany() {
    RelatedManyParent god = new RelatedManyParent("god");   
    List<RelatedManyChild> adams = new ArrayList<RelatedManyChild>();
    for(int i=0; i<100; i++){
      RelatedManyChild adam = new RelatedManyChild("adam"+i);
      god.children.asList().add(adam);
      adams.add(adam);
    }
    god.insert();

    assertNotNull(god.id);
    for(int i=0; i<100; i++){
      assertNotNull(adams.get(i).id);
      assertEquals(god.id, adams.get(i).owner.id);
    }
   
    // update
    adams.get(57).name = "adam57_modified";
    adams.get(57).update();
   
    RelatedManyParent godbis = Model.all(RelatedManyParent.class).filter("name", god.name).get();
   
    List<RelatedManyChild> children = godbis.children.asList();
    for(int i=0; i<100; i++){
      if(i!=57){
        assertEquals(adams.get(i), children.get(i));
      }else {
        assertEquals("adam57_modified", children.get(i).name);
      }
    }
   
    RelatedManyChild child57 = godbis.children.asQuery().filter("id", adams.get(57).id).get();   
    assertEquals("adam57_modified", child57.name);

    children = god.children.asList().forceSync();
    assertEquals(adams.get(57), children.get(57));
View Full Code Here

 
  public void testRelatedManyCascadeUpdateManyRemove() {
    RelatedManyParent god = new RelatedManyParent("god");   
    List<RelatedManyChild> adams = new ArrayList<RelatedManyChild>();
    for(int i=0; i<100; i++){
      RelatedManyChild adam = new RelatedManyChild("adam"+i);
      god.children.asList().add(adam);
      adams.add(adam);
    }
    god.insert();

    assertNotNull(god.id);
    for(int i=0; i<100; i++){
      assertNotNull(adams.get(i).id);
      assertEquals(god.id, adams.get(i).owner.id);
    }
   
    // update
    god.children.asList().remove(57);
    god.update();
   
    RelatedManyParent godbis = Model.all(RelatedManyParent.class).filter("name", god.name).get();
   
    List<RelatedManyChild> children = godbis.children.asList();
    for(int i=0; i<99; i++){
      if(i<57){
        assertEquals(adams.get(i), children.get(i));
      }else {
        assertEquals(adams.get(i+1), children.get(i));
      }
    }
   
    RelatedManyChild child57 = RelatedManyChild.all().filter("id", adams.get(57).id).get();   
    assertNull(child57.owner);
  }
View Full Code Here

 
  public void testRelatedManyCascadeUpdateManyAddEnd() {
    RelatedManyParent god = new RelatedManyParent("god");   
    List<RelatedManyChild> adams = new ArrayList<RelatedManyChild>();
    for(int i=0; i<100; i++){
      RelatedManyChild adam = new RelatedManyChild("adam"+i);
      god.children.asList().add(adam);
      adams.add(adam);
    }
    god.insert();

    assertNotNull(god.id);
    for(int i=0; i<100; i++){
      assertNotNull(adams.get(i).id);
      assertEquals(god.id, adams.get(i).owner.id);
    }
   
    // add
    RelatedManyChild adam100 = new RelatedManyChild("adam100");
    god.children.asList().add(adam100);
    god.update();
   
    RelatedManyParent godbis = Model.all(RelatedManyParent.class).filter("name", god.name).get();
   
    List<RelatedManyChild> children = godbis.children.asList();
    for(int i=0; i<101; i++){
      if(i<100){
        assertEquals(adams.get(i), children.get(i));
      }else {
        assertEquals(adam100, children.get(i));
      }
    }
   
    RelatedManyChild child100 = RelatedManyChild.all().filter("id", adam100.id).get();   
    assertEquals(god.id, child100.owner.id);

  }
View Full Code Here

    // if you add a item in the middle of the list, it will go at the end when you fetch it
    // due to the ordering by ID when calling asList()
    RelatedManyParent god = new RelatedManyParent("god");   
    List<RelatedManyChild> adams = new ArrayList<RelatedManyChild>();
    for(int i=0; i<100; i++){
      RelatedManyChild adam = new RelatedManyChild("adam"+i);
      god.children.asList().add(adam);
      adams.add(adam);
    }
    god.insert();

    assertNotNull(god.id);
    for(int i=0; i<100; i++){
      assertNotNull(adams.get(i).id);
      assertEquals(god.id, adams.get(i).owner.id);
    }
   
    // add
    RelatedManyChild adam_chboing = new RelatedManyChild("adam_chboing");
    god.children.asList().add(57, adam_chboing);
    god.update();
   
    RelatedManyParent godbis = Model.all(RelatedManyParent.class).filter("name", god.name).get();
   
    List<RelatedManyChild> children = godbis.children.asList();
    for(int i=0; i<101; i++){
      if(i<100){
        assertEquals(adams.get(i), children.get(i));
      }else {
        assertEquals(adam_chboing, children.get(i));
      }
    }
   
    RelatedManyChild adam_chboing_bis = RelatedManyChild.all().filter("id", adam_chboing.id).get();   
    assertEquals(god.id, adam_chboing_bis.owner.id);

  }
View Full Code Here

TOP

Related Classes of siena.base.test.model.RelatedManyChild

Copyright © 2018 www.massapicom. 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.