Package siena.base.test.model

Examples of siena.base.test.model.AggregateParentModel


    }

  }
 
  public void testAggregateMostSimple() {
    AggregateParentModel god = new AggregateParentModel("god");
    god.insert();
    assertNotNull(god.id);
   
    AggregateChildModel adam1 = new AggregateChildModel("adam1");
    adam1.aggregate(god, "child");
    adam1.insert();
   
    assertNotNull(adam1.id);
    assertNotNull(adam1.getRelation());

    AggregateParentModel god1 =
      Model.getByKey(AggregateParentModel.class, god.id);
    assertNotNull(god1);
    assertEquals(adam1, god1.child.get());
   
    adam1.name = "adam1_UPD";
    adam1.update();
   
    assertEquals(adam1, god1.child.forceSync().get());
   
    adam1.name = "adam1_UPD2";
    adam1.save();
   
    assertEquals(adam1, god1.child.forceSync().get());
   
    AggregateChildModel adam2 = new AggregateChildModel("adam2");
    adam2.aggregate(god, "child");
    adam2.save();
   
    assertEquals(adam1, god1.child.forceSync().get());
   
    god1.child.set(adam2);
    god1.update();

    AggregateParentModel god2 =
      Model.getByKey(AggregateParentModel.class, god1.id);
    assertNotNull(god2);
    assertEquals(adam2, god2.child.get());
   
    AggregateChildModel adam3 = new AggregateChildModel("adam3");
    adam3.aggregate(god, "child");
    adam3.save();
   
    god.child.set(adam3);
    god.update();
   
    AggregateParentModel god3 =
      Model.getByKey(AggregateParentModel.class, god.id);
    assertNotNull(god3);
    assertEquals(adam2, god3.child.get());
   
    god.child.forceSync().set(adam3);
View Full Code Here


    adam3.delete();
    assertNull(god3.child.forceSync().get());
  }

  public void testAggregateMostSimpleMultiple() {
    AggregateParentModel god = new AggregateParentModel("god");
    god.insert();
    assertNotNull(god.id);

    AggregateChildModel adam1 = new AggregateChildModel("adam1");
    adam1.aggregate(god, "child");
    adam1.insert();
   
    AggregateChildModel adam2 = new AggregateChildModel("adam2")
    adam2.aggregate(god, "children");
    adam2.insert();

    AggregateChildModel eve = new AggregateChildModel("eve");
    eve.aggregate(god, "children");
    eve.insert();

    AggregateChildModel bob = new AggregateChildModel("bob");
    bob.aggregate(god, "children");
    bob.insert();

    AggregateParentModel god1 =
      Model.getByKey(AggregateParentModel.class, god.id);
   
    assertNotNull(god1);
    assertEquals(adam1, god1.child.get());
    List<AggregateChildModel> children = god1.children.asQuery().fetch();
View Full Code Here

    AggregateChildModel adam1 = new AggregateChildModel("adam1");
    AggregateChildModel adam2 = new AggregateChildModel("adam2")
    AggregateChildModel eve = new AggregateChildModel("eve");
    AggregateChildModel bob = new AggregateChildModel("bob");

    AggregateParentModel god = new AggregateParentModel("god");
    god.child.set(adam1);
    god.children.asList().addAll(adam2, eve, bob);       
    god.insert();
   
    assertNotNull(god.id);
    assertNotNull(god.child.get().id);
   
    AggregateParentModel god1 =
      Model.getByKey(AggregateParentModel.class, god.id);
   
    assertNotNull(god1);
    assertEquals(adam1, god1.child.get());
    List<AggregateChildModel> children = god1.children.asQuery().fetch();
    assertEquals(adam2, children.get(0));
    assertEquals(eve, children.get(1));
    assertEquals(bob, children.get(2));
   
    // get aggregated one2one
    AggregateChildModel adamAfter2 = AggregateChildModel.all().aggregated(god, "child").get();
    assertEquals(adam1, adamAfter2);
   
    // get aggregated one2many
    children = AggregateChildModel.all().aggregated(god, "children").fetch();
    assertEquals(adam2, children.get(0));
    assertEquals(eve, children.get(1));
    assertEquals(bob, children.get(2));

    AggregateParentModel god2 = AggregateParentModel.all().filter("name", "god").get();
    assertEquals(adam1, god2.child.get());
    children = god2.children.asList();
    assertEquals(adam2, children.get(0));
    assertEquals(eve, children.get(1));
    assertEquals(bob, children.get(2));
View Full Code Here

    AggregateChildModel adam1 = new AggregateChildModel("adam1");
    AggregateChildModel adam2 = new AggregateChildModel("adam2")
    AggregateChildModel eve = new AggregateChildModel("eve");
    AggregateChildModel bob = new AggregateChildModel("bob");

    AggregateParentModel god = new AggregateParentModel("god");
    god.child.set(adam1);
    god.children.asList().addAll(Arrays.asList(adam2, eve, bob));
       
    god.insert();
   
    assertNotNull(god.id);
    assertNotNull(god.child.get().id);
   
    god.name = "goddy";
    adam1.name = "adammy";
    adam1.save();
    bob.name = "bobby";
    bob.save();
    eve.name = "evvy";
    eve.save();
   
    god.update();
   
    AggregateParentModel godbis = AggregateParentModel.all().filter("name", "goddy").get();
    assertEquals(god, godbis);
    List<AggregateChildModel> children = godbis.children.asList();
    assertEquals(adam2, children.get(0));
    assertEquals(eve, children.get(1));
    assertEquals(bob, children.get(2));
View Full Code Here

    AggregateChildModel adam1 = new AggregateChildModel("adam1");
    AggregateChildModel adam2 = new AggregateChildModel("adam2")
    AggregateChildModel eve = new AggregateChildModel("eve");
    AggregateChildModel bob = new AggregateChildModel("bob");

    AggregateParentModel god = new AggregateParentModel("god");
    god.child.set(adam1);
    god.children.asList().addAll(Arrays.asList(adam2, eve, bob));
       
    god.save();
   
    assertNotNull(god.id);
    assertNotNull(god.child.get().id);
   
    AggregateParentModel god1 =
      Model.getByKey(AggregateParentModel.class, god.id);
   
    assertNotNull(god1);
    assertEquals(adam1, god1.child.get());
    List<AggregateChildModel> children = god1.children.asQuery().fetch();
    assertEquals(adam2, children.get(0));
    assertEquals(eve, children.get(1));
    assertEquals(bob, children.get(2));

    god.name = "goddy";
    adam1.name = "adammy";
    bob.name = "bobby";
    eve.name = "evvy";
   
    Model.batch(AggregateChildModel.class).update(adam1, bob, eve);
   
    god.save();
   
    AggregateParentModel godbis = AggregateParentModel.all().filter("name", "goddy").get();
    assertNotNull(godbis);
    assertEquals(god.id, godbis.id);
    assertEquals(god.name, godbis.name);
    children = godbis.children.asList();
    assertEquals(adam2, children.get(0));
View Full Code Here

    AggregateChildModel adam1 = new AggregateChildModel("adam1");
    AggregateChildModel adam2 = new AggregateChildModel("adam2")
    AggregateChildModel eve = new AggregateChildModel("eve");
    AggregateChildModel bob = new AggregateChildModel("bob");

    AggregateParentModel god = new AggregateParentModel("god");
    god.child.set(adam1);
    god.children.asList().addAll(Arrays.asList(adam2, eve, bob));
       
    god.insert();
   
    assertNotNull(god.id);
    assertNotNull(god.child.get().id);
   
    god.delete();
   
    AggregateParentModel godbis = AggregateParentModel.all().filter("name", "god").get();
    assertNull(godbis);
   
    List<AggregateChildModel> children = Model.batch(AggregateChildModel.class).getByKeys(adam1.id, adam2.id, eve.id, bob.id);
    assertEquals(4, children.size());
    assertEquals(null, children.get(0));
View Full Code Here

    AggregateChildModel adam1 = new AggregateChildModel("adam1");
    AggregateChildModel adam2 = new AggregateChildModel("adam2")
    AggregateChildModel eve = new AggregateChildModel("eve");
    AggregateChildModel bob = new AggregateChildModel("bob");

    AggregateParentModel god = new AggregateParentModel("god");
    god.child.set(adam1);
    god.children.asList().addAll(Arrays.asList(adam2, eve, bob));
       
    god.insert();
   
    assertNotNull(god.id);
    assertNotNull(god.child.get().id);
   
    god.children.asList().remove(eve);
    god.update();
   
    AggregateParentModel godbis = AggregateParentModel.all().filter("name", "god").get();
    assertEquals(god, godbis);
    List<AggregateChildModel> children = godbis.children.asList();
    assertEquals(adam2, children.get(0));
    assertEquals(bob, children.get(1));
  }
View Full Code Here

    AggregateChildModel adam2 = new AggregateChildModel("adam2")
    AggregateChildModel eve = new AggregateChildModel("eve");
    AggregateChildModel bob = new AggregateChildModel("bob");
    AggregateChildModel eve2 = new AggregateChildModel("eve2");

    AggregateParentModel god = new AggregateParentModel("god");
    god.child.set(adam1);
    god.children.asList().addAll(Arrays.asList(adam2, eve, bob));
       
    god.insert();
   
    assertNotNull(god.id);
    assertNotNull(god.child.get().id);
   
    god.children.asList().add(eve2);
    god.update();
   
    AggregateParentModel godbis = AggregateParentModel.all().filter("name", "god").get();
    assertEquals(god, godbis);
    List<AggregateChildModel> children = godbis.children.asList();
    assertEquals(adam2, children.get(0));
    assertEquals(eve, children.get(1));
    assertEquals(bob, children.get(2));
View Full Code Here

      adams.add(adam);
    }
   
    AggregateChildModel eve = new AggregateChildModel("eve");

    AggregateParentModel god = new AggregateParentModel("god");
    god.child.set(eve);
    god.children.asList().addAll(adams);
       
    god.insert();
   
    assertNotNull(god.id);
    assertNotNull(god.child.get().id);
   
    // get aggregated one2many
    AggregateParentModel godbis = AggregateParentModel.all().filter("name", "god").get();
    List<AggregateChildModel> children = godbis.children.asQuery().fetch();
    for(int i=0; i<100; i++){
      assertEquals(adams.get(i), children.get(i));     
    }
   
View Full Code Here

    }
   
    AggregateChildModel eve = new AggregateChildModel();
    eve.name = "eve";

    AggregateParentModel god = new AggregateParentModel();
    god.name = "god";
    god.child.set(eve);
    god.children.asList().addAll(adams);
       
    god.insert();
   
    assertNotNull(god.id);
    assertNotNull(god.child.get().id);
   
    // get aggregated one2many
    AggregateParentModel godbis = AggregateParentModel.all().filter("name", "god").get();
    List<AggregateChildModel> children_0_10 = godbis.children.asQuery().fetch(10);
    for(int i=0; i<10; i++){
      assertEquals(adams.get(i), children_0_10.get(i));     
    }
   
View Full Code Here

TOP

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

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.