Package com.avaje.tests.model.basic

Examples of com.avaje.tests.model.basic.MUser


    // Save r1 and r2
    Ebean.save(r0);
    Ebean.save(r1);

    // Create a new user
    MUser u0 = new MUser("usr0");
    u0.addRole(r0);
    u0.addRole(r1);

    // Save the user
    Ebean.save(u0);

    List<MRole> roles = u0.getRoles();

    Assert.assertTrue(roles.size() == 2);

    u0 = Ebean.find(MUser.class, u0.getUserid());

    roles = u0.getRoles();
    int nrRoles = roles.size();

    Assert.assertTrue(nrRoles == 2);

    roles.clear();
    roles.add(r0);
    roles.add(r1);
    roles.remove(r1);

    Ebean.save(u0);

    u0 = Ebean.find(MUser.class, u0.getUserid());

    roles = u0.getRoles();

    nrRoles = roles.size();

    Assert.assertTrue(nrRoles == 1);
  }
View Full Code Here


    MRole r1 = new MRole("r1");

    Ebean.save(r0);
    // Ebean.save(r1);

    MUser u0 = new MUser("usr0");
    u0.addRole(r0);
    u0.addRole(r1);

    Ebean.save(u0);

    List<MRole> roles = u0.getRoles();

    // this will delete
    Ebean.delete(u0);

    MUser notThere = Ebean.find(MUser.class, u0.getUserid());
    Assert.assertNull("been deleted", notThere);

    List<Object> roleIds = new ArrayList<Object>();
    Collections.addAll(roleIds, r0.getRoleid(), r1.getRoleid());
View Full Code Here

     * I'm not sure this exposes all causes of the problem.
     */
   
    MUserType ut = new MUserType("md");
    Ebean.save(ut);
    MUser user1 = new MUser("one");
    user1.setUserType(ut);
    Ebean.save(user1);
    MUser user2 = new MUser("two");
    user2.setUserType(ut);
    Ebean.save(user2);
   
    MRole roleA = new MRole("A");
    Ebean.save(roleA);
    MRole roleB = new MRole("B");
    Ebean.save(roleB);
   
    user1.addRole(roleA);
    Ebean.save(user1);
    user2.addRole(roleB);
    Ebean.save(user2);
   
    Query<MUser> query = Ebean.find(MUser.class)
        .fetch("userType","name")
        .where()
View Full Code Here

    MRole r3 = new MRole();
    r3.setRoleName("role3");
    Ebean.save(r3);

    MUser u0 = new MUser();
    u0.setUserName("user0");
    u0.addRole(r1);
    u0.addRole(r2);

    Ebean.save(u0);

    MUser u1 = new MUser();
    u1.setUserName("user1");
    u1.addRole(r1);

    Ebean.save(u1);

    Ebean.commitTransaction();
View Full Code Here

    MRole r1 = new MRole("r1");

    Ebean.save(r0);
    Ebean.save(r1);

    MUser u0 = new MUser("usr0");
    u0.addRole(r0);
    u0.addRole(r1);

    Ebean.save(u0);
  }
View Full Code Here

public class TestM2MCascadeOne extends BaseTestCase {

  @Test
  public void test() {

    MUser u = new MUser();
    u.setUserName("testM2M");

    List<MRole> roles = u.getRoles();
    if (roles != null) {
      if (roles instanceof BeanList<?>) {
        System.out.println("enhancement checkNullManyFields=true successful");
      }
    }

    Ebean.save(u);

    MRole r0 = new MRole();
    r0.setRoleName("rol_0");
    Ebean.save(r0);

    MRole r1 = new MRole();
    r1.setRoleName("rol_1");

    MUser u1 = Ebean.find(MUser.class, u.getUserid());

    u1.addRole(r0);
    u1.addRole(r1);

    Ebean.save(u1);

  }
View Full Code Here

    MRole r3 = new MRole();
    r3.setRoleName("role3");
    Ebean.save(r3);

    MUser u0 = new MUser();
    u0.setUserName("something");

    Ebean.save(u0);

    MUser user = Ebean.find(MUser.class, u0.getUserid());

    List<MRole> roleList = new ArrayList<MRole>();
    roleList.add(r1);
    roleList.add(r2);

    user.setRoles(roleList);

    Ebean.save(user);
    // Ebean.saveManyToManyAssociations(user, "roles");

    MUser checkUser = Ebean.find(MUser.class, u0.getUserid());
    List<MRole> checkRoles = checkUser.getRoles();
    Assert.assertNotNull(checkRoles);
    Assert.assertEquals(2, checkRoles.size());

    checkRoles.add(r3);

    Ebean.save(checkUser);
    // Ebean.saveManyToManyAssociations(checkUser, "roles");

    MUser checkUser2 = Ebean.find(MUser.class, u0.getUserid());
    List<MRole> checkRoles2 = checkUser2.getRoles();
    Assert.assertNotNull(checkRoles2);
    Assert.assertEquals("added a role", 3, checkRoles2.size());

    Query<MUser> rolesQuery0 = Ebean.find(MUser.class).where().eq("roles", r1).query();

    rolesQuery0.findList();

    Query<MUser> rolesQuery = Ebean.find(MUser.class).where().in("roles", roleList).query();

    List<MUser> userInRolesList = rolesQuery.findList();
    Assert.assertTrue(userInRolesList.size() > 0);

    List<MUser> list = Ebean.find(MUser.class)
        .where().in("roles", roleList)
        .filterMany("roles").eq("roleName", "role1")
        .findList();

    MUser mUser = list.get(0);
    List<MRole> roles = mUser.getRoles();
    Assert.assertEquals(1, roles.size());

//    Ebean.refreshMany(mUser, "roles");
//    Assert.assertEquals(1, mUser.getRoles().size());
View Full Code Here

    MRole r3 = new MRole();
    r3.setRoleName("rolej3");
    Ebean.save(r3);

    MUser u0 = new MUser();
    u0.setUserName("userj1");
    u0.addRole(r1);
    u0.addRole(r2);
    u0.addRole(r3);

    Ebean.save(u0);

    String jsonUser = jsonContext.toJson(u0);

    System.out.println(jsonUser);

    String s = "{\"userid\":" + u0.getUserid()
        + ",\"userName\":\"userj1\", \"roles\":[{\"roleid\":" + r2.getRoleid() + "},{\"roleid\":"
        + r3.getRoleid() + "}]} ";

    MUser updMUser = jsonContext.toBean(MUser.class, s);

    server.update(updMUser);

    // checked transaction log to confirm correct behaviour
  }
View Full Code Here

    MRole r3 = new MRole();
    r3.setRoleName("role3");
    Ebean.save(r3);

    MUser u0 = new MUser();
    u0.setUserName("user0");
    u0.addRole(r1);
    u0.addRole(r2);

    Ebean.save(u0);

    MUser u1 = new MUser();
    u1.setUserName("user1");
    u1.addRole(r1);

    Ebean.save(u1);

    Ebean.commitTransaction();
View Full Code Here

TOP

Related Classes of com.avaje.tests.model.basic.MUser

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.