/** Test creating group */ @Test public void testCraeteGroup() throws Exception { System.out.println(">>> Create group"); UserTransaction tx = getUserTransaction(); try { AdminEJBLocal instance = (AdminEJBLocal) getEJBInstance(AdminEJB.class.getSimpleName()); tx.begin(); // Get roles List<Role> roles = instance.getRoles(); tx.commit(); assertNotNull("List of roles is null.", roles); tx.begin(); List<GroupRole> groupRoles = new ArrayList<GroupRole>(); if (roles != null) { for (Role role : roles) { GroupRole groupRole = new GroupRole(); groupRole.setRoleCode(role.getCode()); groupRole.setEntityAction(EntityAction.INSERT); groupRoles.add(groupRole); } } Group userGroup = new Group(); userGroup.setId(GROUP_ID); userGroup.setName("Test group"); userGroup.setDescription("This is test group"); userGroup.setLoaded(false); userGroup.setEntityAction(EntityAction.INSERT); userGroup.setGroupRoles(groupRoles); Group result = instance.saveGroup(userGroup); tx.commit(); assertNotNull("Failed to create group", result); System.out.println(">>> Group has been saved!"); } catch (Exception e) { tx.rollback(); fail(e.getMessage()); } }
/** Test roles loading */ @Test public void testLoadAllRoles() throws Exception { System.out.println(">>> Loading all roles"); UserTransaction tx = getUserTransaction(); try { AdminEJBLocal instance = (AdminEJBLocal) getEJBInstance(AdminEJB.class.getSimpleName()); tx.begin(); List<Role> result = instance.getRoles(); tx.commit(); assertNotNull("List of roles is null.", result); System.out.println(">>> Found " + result.size() + " roles."); } catch (Exception e) { tx.rollback(); fail(e.getMessage()); } }