Search in sources :

Example 96 with User

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());
}
Also used : User(com.haulmont.cuba.core.model.common.User) Test(org.junit.jupiter.api.Test) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest)

Example 97 with User

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());
}
Also used : Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) Test(org.junit.jupiter.api.Test) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest)

Example 98 with User

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"));
    }
}
Also used : User(com.haulmont.cuba.core.model.common.User) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 99 with User

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"));
    }
}
Also used : User(com.haulmont.cuba.core.model.common.User) UserRelatedNews(com.haulmont.cuba.core.model.UserRelatedNews) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 100 with User

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) {
    }
}
Also used : User(com.haulmont.cuba.core.model.common.User) 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)

Aggregations

User (com.haulmont.cuba.core.model.common.User)154 Test (org.junit.jupiter.api.Test)133 Group (com.haulmont.cuba.core.model.common.Group)63 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)57 Datasource (com.haulmont.cuba.gui.data.Datasource)54 Subscription (io.jmix.core.common.event.Subscription)54 Consumer (java.util.function.Consumer)54 Disabled (org.junit.jupiter.api.Disabled)54 HasValue (io.jmix.ui.component.HasValue)49 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)44 UUID (java.util.UUID)29 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)23 ArrayList (java.util.ArrayList)21 List (java.util.List)19 Date (java.util.Date)18 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15 View (com.haulmont.cuba.core.global.View)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13