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"));
}
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"));
}
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);
}
}
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();
}
}
Aggregations