Package com.alvazan.test.db

Examples of com.alvazan.test.db.Activity


  public void testOneToManyWithList() {
    Account acc = new Account("acc1");
    acc.setName(ACCOUNT_NAME);
    acc.setUsers(5.0f);
    mgr.fillInWithKey(acc);
    Activity act1 = new Activity("act1");
    act1.setAccount(acc);
    act1.setName("dean");
    act1.setNumTimes(3);
   
    mgr.put(act1);
   
    Activity act2 = new Activity("act2");
    act2.setName("dean");
    act2.setNumTimes(4);
   
    mgr.put(act2);
   
    acc.addActivity(act1);
    acc.addActivity(act2);
    mgr.put(acc);
   
    mgr.flush();
   
    Account accountResult = mgr.find(Account.class, acc.getId());
    Assert.assertEquals(ACCOUNT_NAME, accountResult.getName());
    Assert.assertEquals(acc.getUsers(), accountResult.getUsers());
    List<Activity> activities = accountResult.getActivities();
    Assert.assertEquals(2, activities.size());
   
    //Now let's force proxy creation by getting one of the Activities
    Activity activity = activities.get(0);
   
    //This should NOT hit the database since the id is wrapped by the proxy and exists already
    String id = activity.getId();
    //since we added activity1 first, we better see that same activity be first in the list again...
    Assert.assertEquals(act1.getId(), id);
   
    //Now let's force a database lookup to have the activity filled in
    Assert.assertEquals("dean", activity.getName());
  }
View Full Code Here


  public void testEmptyRowCase() {
    Account acc = new Account("acc1");
    acc.setName(ACCOUNT_NAME);
    acc.setUsers(5.0f);
    mgr.fillInWithKey(acc);
    Activity act1 = new Activity("act1");
    act1.setAccount(acc);
    act1.setName("dean");
    act1.setNumTimes(3);
    mgr.put(act1);
   
    Activity act2 = new Activity("act2");
    act2.setAccount(acc);
    act2.setName("dean");
    act2.setNumTimes(4);
    mgr.put(act2);
   
    acc.addActivity(act1);
    acc.addActivity(act2);
   
    mgr.put(acc);
   
    mgr.flush();
    mgr.clear();

    mgr.remove(act2);
    mgr.flush();
    mgr.clear();
   
    //At this point we have corrupted our database, but we can check that
    Account account = mgr.find(Account.class, acc.getId());
    List<Activity> activities = account.getActivities();
   
    Activity nonExist = activities.get(0);
    if(!nonExist.getId().equals(act2.getId()))
      nonExist = activities.get(1);
   
    Activity activity = mgr.find(Activity.class, act2.getId());
    Assert.assertNull(activity);
  }
View Full Code Here

TOP

Related Classes of com.alvazan.test.db.Activity

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.