Search in sources :

Example 31 with Group

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();
    }
}
Also used : Group(com.haulmont.cuba.security.entity.Group) Before(org.junit.Before)

Example 32 with Group

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();
    }
}
Also used : Group(com.haulmont.cuba.security.entity.Group) EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) GroupHierarchy(com.haulmont.cuba.security.entity.GroupHierarchy) Test(org.junit.Test)

Example 33 with Group

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();
    }
}
Also used : Group(com.haulmont.cuba.security.entity.Group) EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction) GroupHierarchy(com.haulmont.cuba.security.entity.GroupHierarchy) Test(org.junit.Test)

Example 34 with Group

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();
    }
}
Also used : Group(com.haulmont.cuba.security.entity.Group) EntityManager(com.haulmont.cuba.core.EntityManager) Transaction(com.haulmont.cuba.core.Transaction)

Example 35 with Group

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);
}
Also used : Group(com.haulmont.cuba.security.entity.Group) EntityManager(com.haulmont.cuba.core.EntityManager) User(com.haulmont.cuba.security.entity.User) Transaction(com.haulmont.cuba.core.Transaction) UserSubstitution(com.haulmont.cuba.security.entity.UserSubstitution)

Aggregations

Group (com.haulmont.cuba.security.entity.Group)79 User (com.haulmont.cuba.security.entity.User)65 Test (org.junit.Test)60 UUID (java.util.UUID)30 Datasource (com.haulmont.cuba.gui.data.Datasource)29 Ignore (org.junit.Ignore)29 Component (com.haulmont.cuba.gui.components.Component)24 ArrayList (java.util.ArrayList)24 Assert.assertEquals (org.junit.Assert.assertEquals)24 Assert.assertTrue (org.junit.Assert.assertTrue)24 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)23 List (java.util.List)20 View (com.haulmont.cuba.core.global.View)15 Assert.assertNotNull (org.junit.Assert.assertNotNull)12 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)11 DatasourceImpl (com.haulmont.cuba.gui.data.impl.DatasourceImpl)10 Before (org.junit.Before)10 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)9 EntityManager (com.haulmont.cuba.core.EntityManager)8 Transaction (com.haulmont.cuba.core.Transaction)7