use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class EntityStateTest method testTransactionRollback_new.
@Test
public void testTransactionRollback_new() throws Exception {
User user = null;
// create and persist
Transaction tx = persistence.createTransaction();
try {
user = new User();
assertTrue(user.__getEntityEntry().isNew());
assertFalse(user.__getEntityEntry().isManaged());
assertFalse(user.__getEntityEntry().isDetached());
userId = user.getId();
persistence.getEntityManager().persist(user);
assertTrue(user.__getEntityEntry().isNew());
assertTrue(user.__getEntityEntry().isManaged());
assertFalse(user.__getEntityEntry().isDetached());
tx.commit();
// due to absence login
fail();
} catch (Exception e) {
// ok
} finally {
tx.end();
}
assertTrue(user.__getEntityEntry().isNew());
assertFalse(user.__getEntityEntry().isManaged());
assertFalse(user.__getEntityEntry().isDetached());
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class EntityStateTest method testTransactionRollback_loaded.
@Test
public void testTransactionRollback_loaded() {
User user;
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
user = new User();
assertTrue(user.__getEntityEntry().isNew());
assertFalse(user.__getEntityEntry().isManaged());
assertFalse(user.__getEntityEntry().isDetached());
group = new Group();
group.setName("group");
em.persist(group);
userId = user.getId();
user.setName("testUser");
user.setLogin("testLogin");
user.setGroup(group);
em.persist(user);
tx.commit();
} finally {
tx.end();
}
tx = persistence.createTransaction();
try {
user = persistence.getEntityManager().find(User.class, userId);
assertFalse(user.__getEntityEntry().isNew());
assertTrue(user.__getEntityEntry().isManaged());
assertFalse(user.__getEntityEntry().isDetached());
} finally {
tx.end();
}
assertFalse(user.__getEntityEntry().isNew());
assertFalse(user.__getEntityEntry().isManaged());
assertTrue(user.__getEntityEntry().isDetached());
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class CheckLoadedStateTest method checkMinimalProperties.
@Test
public void checkMinimalProperties() {
DataManager dataManager = AppBeans.get(DataManager.class);
EntityStates entityStates = AppBeans.get(EntityStates.class);
User user = dataManager.load(LoadContext.create(User.class).setId(userId).setFetchPlan(View.MINIMAL));
entityStates.checkLoaded(user, "login", "name");
try {
entityStates.checkLoaded(user, "group");
fail("user.group is not loaded");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("group is not loaded"));
}
try {
entityStates.checkLoaded(user, "password");
fail("user.password is not loaded");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("password is not loaded"));
}
try {
entityStates.checkLoaded(user, "email");
fail("user.email is not loaded");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("email is not loaded"));
}
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class CheckLoadedStateTest method checkRecursiveView.
@Test
public void checkRecursiveView() {
DataManager dataManager = AppBeans.get(DataManager.class);
EntityStates entityStates = AppBeans.get(EntityStates.class);
User user = dataManager.load(LoadContext.create(User.class).setId(userId).setFetchPlan(FetchPlan.INSTANCE_NAME));
recursiveUserRelatedIds = new ArrayList<>();
UserRelatedNews parentRecord = metadata.create(UserRelatedNews.class);
parentRecord.setName("Test");
parentRecord.setUser(user);
UserRelatedNews committedParentRecord = dataManager.commit(parentRecord);
recursiveUserRelatedIds.add(committedParentRecord.getId());
UserRelatedNews record = metadata.create(UserRelatedNews.class);
record.setName("Test");
record.setUser(user);
record.setParent(committedParentRecord);
UserRelatedNews committedRecord = dataManager.commit(record);
recursiveUserRelatedIds.add(committedRecord.getId());
View view = new View(UserRelatedNews.class, false);
view.addProperty("parent");
view.addProperty("name");
assertTrue(entityStates.isLoadedWithFetchPlan(committedRecord, view));
entityStates.checkLoadedWithFetchPlan(committedRecord, view);
UserRelatedNews localRecord = dataManager.load(LoadContext.create(UserRelatedNews.class).setId(committedRecord.getId()).setFetchPlan(FetchPlan.LOCAL));
try {
assertFalse(entityStates.isLoadedWithFetchPlan(localRecord, view));
entityStates.checkLoadedWithFetchPlan(localRecord, view);
fail("local record attributes are not loaded");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("parent is not loaded"));
}
}
use of com.haulmont.cuba.core.model.common.User in project jmix by jmix-framework.
the class EclipseLinkDetachedTest method testSerializedFetchGroup.
@Test
public void testSerializedFetchGroup() throws Exception {
Transaction tx;
EntityManager em;
User user;
tx = persistence.createTransaction();
try {
em = persistence.getEntityManager();
FetchPlan view = new View(User.class).addProperty("login").setLoadPartialEntities(true);
user = em.find(User.class, userId, view);
assertNotNull(user);
tx.commit();
} finally {
tx.end();
}
user = testSupport.reserialize(user);
assertEquals("testLogin", user.getLogin());
// exception on getting not loaded references
try {
user.getName();
fail();
} catch (Exception ignored) {
}
try {
assertFalse(entityStates.isLoaded(user, "group"));
user.getGroup();
} catch (Exception ignored) {
}
try {
assertFalse(entityStates.isLoaded(user, "userRoles"));
user.getUserRoles().size();
} catch (Exception ignored) {
}
}
Aggregations