Search in sources :

Example 26 with Server

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

the class TransactionTest method testRunInTransaction.

@Test
public void testRunInTransaction() throws Exception {
    UUID id = persistence.callInTransaction(em -> {
        assertNotNull(em);
        Server server = new Server();
        server.setName("localhost");
        server.setRunning(true);
        em.persist(server);
        return server.getId();
    });
    persistence.runInTransaction(em -> {
        Server server = em.find(Server.class, id);
        assertNotNull(server);
        assertEquals(id, server.getId());
        server.setRunning(false);
    });
}
Also used : Server(com.haulmont.cuba.core.model.common.Server) UUID(java.util.UUID) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 27 with Server

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

the class NonDetachedTest method testCreateNew_DM.

@Test
public void testCreateNew_DM() throws Exception {
    // check versioned entity
    Group companyGroupCopy = metadata.getTools().copy(companyGroup);
    assertTrue(entityStates.isNew(companyGroupCopy));
    entityStates.makeDetached(companyGroupCopy);
    User user = persistence.callInTransaction((em) -> em.find(User.class, this.user.getId()));
    User userCopy = metadata.getTools().copy(user);
    assertNull(userCopy.getGroup());
    assertTrue(entityStates.isNew(userCopy));
    entityStates.makeDetached(userCopy);
    userCopy.setId(UuidProvider.createUuid());
    userCopy.setVersion(null);
    userCopy.setGroup(companyGroupCopy);
    userCopy.setName("new name");
    try {
        AppBeans.get(DataManager.class).commit(userCopy);
        user = persistence.callInTransaction((em) -> em.find(User.class, userCopy.getId()));
        assertEquals("new name", user.getName());
    } finally {
        testSupport.deleteRecord(userCopy);
    }
    // check non-versioned entity
    Server server = metadata.create(Server.class);
    server.setName("server-" + server.getId());
    assertTrue(entityStates.isNew(server));
    entityStates.makeDetached(server);
    try {
        AppBeans.get(DataManager.class).commit(server);
        Server loaded = persistence.callInTransaction(em -> em.find(Server.class, server.getId()));
        assertNotNull(loaded);
    } finally {
        testSupport.deleteRecord(server);
    }
}
Also used : UuidProvider(io.jmix.core.UuidProvider) BeforeEach(org.junit.jupiter.api.BeforeEach) Customer(com.haulmont.cuba.core.model.sales.Customer) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) AppBeans(com.haulmont.cuba.core.global.AppBeans) Group(com.haulmont.cuba.core.model.common.Group) Metadata(com.haulmont.cuba.core.global.Metadata) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) CascadeDeletionPolicyEntity(com.haulmont.cuba.core.model.CascadeDeletionPolicyEntity) DataManager(com.haulmont.cuba.core.global.DataManager) Order(com.haulmont.cuba.core.model.sales.Order) FetchPlan(io.jmix.core.FetchPlan) Server(com.haulmont.cuba.core.model.common.Server) DateUtils(org.apache.commons.lang3.time.DateUtils) Test(org.junit.jupiter.api.Test) View(com.haulmont.cuba.core.global.View) AfterEach(org.junit.jupiter.api.AfterEach) TestSupport(com.haulmont.cuba.core.testsupport.TestSupport) EntityStates(io.jmix.core.EntityStates) Assertions(org.junit.jupiter.api.Assertions) Entity(io.jmix.core.Entity) User(com.haulmont.cuba.core.model.common.User) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) Server(com.haulmont.cuba.core.model.common.Server) DataManager(com.haulmont.cuba.core.global.DataManager) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Aggregations

Server (com.haulmont.cuba.core.model.common.Server)27 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)24 Test (org.junit.jupiter.api.Test)24 UUID (java.util.UUID)10 CommitContext (com.haulmont.cuba.core.global.CommitContext)8 Entity (io.jmix.core.Entity)8 DataManager (com.haulmont.cuba.core.global.DataManager)2 LoadContext (com.haulmont.cuba.core.global.LoadContext)2 View (com.haulmont.cuba.core.global.View)2 User (com.haulmont.cuba.core.model.common.User)2 FetchPlan (io.jmix.core.FetchPlan)2 Date (java.util.Date)2 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 CascadeDeletionPolicyEntity (com.haulmont.cuba.core.model.CascadeDeletionPolicyEntity)1 EntityDiff (com.haulmont.cuba.core.model.common.EntityDiff)1 FileDescriptor (com.haulmont.cuba.core.model.common.FileDescriptor)1 Group (com.haulmont.cuba.core.model.common.Group)1 Customer (com.haulmont.cuba.core.model.sales.Customer)1 Order (com.haulmont.cuba.core.model.sales.Order)1