Package siena.base.test.model

Examples of siena.base.test.model.RelatedManyParent


    assertEquals(adam1, children.get(0));
    assertEquals(adam2, children.get(1));
  }
 
  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);
   
    // tries to forcesync on god
    god.children.asList().forceSync();
    assertEquals(adam1, god.children.asList().get(0));
    assertEquals(adam2, god.children.asList().get(1));
   
    RelatedManyParent godbis = Model.getByKey(RelatedManyParent.class, god.id);
    List<RelatedManyChild> children = godbis.children.asQuery().fetch();
   
    assertEquals(god, godbis);
    assertEquals(adam1, children.get(0));
    assertEquals(adam2, children.get(1));
View Full Code Here


    assertEquals(adam1, children.get(0));
    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);
    assertNotNull(adam1.id);
    assertNotNull(adam2.id);
    assertEquals(god.id, adam1.owner.id);
    assertEquals(god.id, adam2.owner.id);
   
    RelatedManyParent godbis = Model.getByKey(RelatedManyParent.class, god.id);
    List<RelatedManyChild> children = godbis.children.asQuery().fetch();
   
    assertEquals(god, godbis);
    assertEquals(adam1, children.get(0));
    assertEquals(adam2, children.get(1));
View Full Code Here

    assertEquals(adam1, children.get(0));
    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);
    assertNotNull(adam1.id);
    assertNotNull(adam2.id);
    assertEquals(god.id, adam1.owner.id);
    assertEquals(god.id, adam2.owner.id);
   
    RelatedManyParent godbis = Model.all(RelatedManyParent.class).filter("name", god.name).get();
    List<RelatedManyChild> children = godbis.children.asQuery().fetch();
   
    assertEquals(god, godbis);
    assertEquals(adam1, children.get(0));
    assertEquals(adam2, children.get(1));
View Full Code Here

    assertEquals(adam1, children.get(0));
    assertEquals(adam2, children.get(1));
  }
 
  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();

    assertNotNull(god.id);
    for(int i=0; i<100; i++){
      assertNotNull(adams.get(i).id);
      assertEquals(god.id, adams.get(i).owner.id);
    }
   
    RelatedManyParent godbis = Model.all(RelatedManyParent.class).filter("name", god.name).get();
   
    List<RelatedManyChild> children = godbis.children.asList();
    for(int i=0; i<100; i++){
      assertEquals(adams.get(i), children.get(i));
    }
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));
View Full Code Here

    assertEquals(adams.get(57), children.get(57));

  }
 
  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));
View Full Code Here

    RelatedManyChild child57 = RelatedManyChild.all().filter("id", adams.get(57).id).get();   
    assertNull(child57.owner);
  }
 
  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));
View Full Code Here

 
  public void testRelatedManyCascadeUpdateManyAddMiddle() {
    // THIS TEST IS WEIRD...
    // 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));
View Full Code Here

TOP

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

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.