Search in sources :

Example 1 with Permission

use of com.haulmont.cuba.core.model.common.Permission in project jmix by jmix-framework.

the class UpdateDetachedTest method test.

@Test
public void test() throws Exception {
    Permission p;
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name"));
        p = em.find(Permission.class, permissionId, view);
        tx.commitRetaining();
        assertNotNull(p);
        p.setTarget("newTarget");
        em = persistence.getEntityManager();
        p = em.merge(p);
        tx.commit();
    } finally {
        tx.end();
    }
    p = testSupport.reserialize(p);
    assertTrue(entityStates.isDetached(p));
    assertNotNull(p.getRole());
    assertTrue(entityStates.isDetached(p.getRole()));
    assertTrue(entityStates.isLoaded(p, "role"));
}
Also used : Permission(com.haulmont.cuba.core.model.common.Permission) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 2 with Permission

use of com.haulmont.cuba.core.model.common.Permission in project jmix by jmix-framework.

the class UpdateDetachedTest method testDataManager.

@Test
public void testDataManager() throws Exception {
    Permission p;
    LoadContext<Permission> ctx = new LoadContext<>(Permission.class);
    ctx.setId(permissionId);
    ctx.setView(new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name")));
    p = dataManager.load(ctx);
    assertNotNull(p);
    p.setTarget("newTarget");
    CommitContext commitCtx = new CommitContext(Collections.singleton(p));
    Set<Entity> entities = dataManager.commit(commitCtx);
    Permission result = null;
    for (Entity entity : entities) {
        if (entity.equals(p))
            result = (Permission) entity;
    }
    result = testSupport.reserialize(result);
    assertTrue(entityStates.isDetached(result));
    assertNotNull(result.getRole());
    assertTrue(entityStates.isDetached(result.getRole()));
    assertTrue(entityStates.isLoaded(result, "role"));
}
Also used : Role(com.haulmont.cuba.core.model.common.Role) Entity(io.jmix.core.Entity) Permission(com.haulmont.cuba.core.model.common.Permission) CommitContext(com.haulmont.cuba.core.global.CommitContext) LoadContext(com.haulmont.cuba.core.global.LoadContext) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 3 with Permission

use of com.haulmont.cuba.core.model.common.Permission in project jmix by jmix-framework.

the class UpdateDetachedTest method testRollback.

@Test
public void testRollback() {
    Permission p = null;
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name"));
        p = em.find(Permission.class, permissionId, view);
        tx.commitRetaining();
        p.setTarget("newTarget");
        em = persistence.getEntityManager();
        p = em.merge(p);
        throwException();
        tx.commit();
    } catch (RuntimeException e) {
    // ok
    } finally {
        tx.end();
        assertNotNull(p);
    }
}
Also used : Permission(com.haulmont.cuba.core.model.common.Permission) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 4 with Permission

use of com.haulmont.cuba.core.model.common.Permission in project jmix by jmix-framework.

the class UpdateDetachedTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        Role role = new Role();
        roleId = role.getId();
        role.setName("testRole");
        em.persist(role);
        Role role2 = new Role();
        role2Id = role2.getId();
        role2.setName("testRole2");
        em.persist(role2);
        Permission permission = new Permission();
        permissionId = permission.getId();
        permission.setRole(role);
        permission.setType(PermissionType.SCREEN);
        permission.setTarget("testTarget");
        em.persist(permission);
        tx.commit();
    } finally {
        tx.end();
    }
}
Also used : Role(com.haulmont.cuba.core.model.common.Role) Permission(com.haulmont.cuba.core.model.common.Permission) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Permission (com.haulmont.cuba.core.model.common.Permission)4 View (com.haulmont.cuba.core.global.View)3 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)3 Test (org.junit.jupiter.api.Test)3 Role (com.haulmont.cuba.core.model.common.Role)2 FetchPlan (io.jmix.core.FetchPlan)2 CommitContext (com.haulmont.cuba.core.global.CommitContext)1 LoadContext (com.haulmont.cuba.core.global.LoadContext)1 Entity (io.jmix.core.Entity)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1