use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class UnfetchedAttributeTest method setUp.
@Before
public void setUp() throws Exception {
group = new Group();
group.setName("Some group");
Transaction tx = cont.persistence().createTransaction();
try {
cont.persistence().getEntityManager().persist(group);
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class GroupTest method testNew.
@Test
public void testNew() {
createGroups();
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group group2 = em.find(Group.class, group2Id);
for (GroupHierarchy hierarchy : group2.getHierarchyList()) {
assertEquals(group2, hierarchy.getGroup());
if (hierarchy.getLevel() == 0)
assertEquals(rootId, hierarchy.getParent().getId());
else if (hierarchy.getLevel() == 1)
assertEquals(group1Id, hierarchy.getParent().getId());
}
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class GroupTest method testUpdate.
@Test
public void testUpdate() {
createGroups();
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group group1 = em.find(Group.class, group1Id);
Group group3 = em.find(Group.class, group3Id);
group1.setParent(group3);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
group1 = em.find(Group.class, group1Id);
for (GroupHierarchy hierarchy : group1.getHierarchyList()) {
assertEquals(group1, hierarchy.getGroup());
if (hierarchy.getLevel() == 0)
assertEquals(rootId, hierarchy.getParent().getId());
else if (hierarchy.getLevel() == 1)
assertEquals(group3Id, hierarchy.getParent().getId());
}
Group group2 = em.find(Group.class, group2Id);
for (GroupHierarchy hierarchy : group2.getHierarchyList()) {
assertEquals(group2, hierarchy.getGroup());
if (hierarchy.getLevel() == 0)
assertEquals(rootId, hierarchy.getParent().getId());
else if (hierarchy.getLevel() == 1)
assertEquals(group3Id, hierarchy.getParent().getId());
else if (hierarchy.getLevel() == 2)
assertEquals(group1Id, hierarchy.getParent().getId());
}
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class GroupTest method createGroups.
private void createGroups() {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group root = new Group();
rootId = root.getId();
root.setName("root");
em.persist(root);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
root = em.find(Group.class, rootId);
Group group1 = new Group();
group1Id = group1.getId();
group1.setName("group1");
group1.setParent(root);
em.persist(group1);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
group1 = em.find(Group.class, group1Id);
Group group2 = new Group();
group2Id = group2.getId();
group2.setName("group2");
group2.setParent(group1);
em.persist(group2);
tx.commitRetaining();
em = cont.persistence().getEntityManager();
root = em.find(Group.class, rootId);
Group group3 = new Group();
group3Id = group3.getId();
group3.setName("group3");
group3.setParent(root);
em.persist(group3);
tx.commit();
} finally {
tx.end();
}
}
use of com.haulmont.cuba.security.entity.Group in project cuba by cuba-platform.
the class LoadSubstitutionsTest method setUp.
@Before
public void setUp() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Group group = em.find(Group.class, UUID.fromString("0fa2b1a5-1d68-4d69-9fbd-dff348347f93"));
user = new User();
user.setLogin("user-" + user.getId());
user.setGroup(group);
em.persist(user);
substitutedUser = new User();
substitutedUser.setLogin("substitutedUser");
substitutedUser.setGroup(group);
em.persist(substitutedUser);
userSubstitution = new UserSubstitution();
userSubstitution.setUser(user);
userSubstitution.setSubstitutedUser(substitutedUser);
user.setSubstitutions(new ArrayList<>(ImmutableList.of(userSubstitution)));
em.persist(userSubstitution);
tx.commit();
} finally {
tx.end();
}
cont.setupLogging("com.haulmont.cuba.core.sys.FetchGroupManager", Level.TRACE);
}
Aggregations