Search in sources :

Example 11 with Server

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

the class DataManagerTest method testDiscardCommitted.

@Test
public void testDiscardCommitted() throws Exception {
    Server server = new Server();
    server.setName("localhost");
    CommitContext commitContext = new CommitContext(server);
    commitContext.setDiscardCommitted(true);
    Set<Entity> committed = dataManager.commit(commitContext);
    assertTrue(committed.isEmpty());
    Server saved = dataManager.load(LoadContext.create(Server.class).setId(server.getId()));
    assertNotNull(saved);
}
Also used : Entity(io.jmix.core.Entity) Server(com.haulmont.cuba.core.model.common.Server) CommitContext(com.haulmont.cuba.core.global.CommitContext) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 12 with Server

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

the class DataManagerTest method test.

@Test
public void test() {
    Server server = new Server();
    UUID id = server.getId();
    server.setName("localhost");
    server.setRunning(true);
    dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
    LoadContext<Server> loadContext = LoadContext.create(Server.class).setId(id);
    server = dataManager.load(loadContext);
    assertEquals("localhost", server.getName());
    server.setName("krivopustov");
    dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
}
Also used : Entity(io.jmix.core.Entity) Server(com.haulmont.cuba.core.model.common.Server) CommitContext(com.haulmont.cuba.core.global.CommitContext) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 13 with Server

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

the class DataManagerTest method testDataManagerLoadOneRecord.

@Test
public void testDataManagerLoadOneRecord() {
    Server server1 = new Server();
    server1.setName("app1");
    server1.setRunning(false);
    Server server2 = new Server();
    server2.setName("app2");
    server2.setRunning(false);
    dataManager.commit(new CommitContext(server1, server2));
    LoadContext<Server> lc = new LoadContext<>(Server.class);
    lc.setQueryString("select s from test$Server s order by s.name").setMaxResults(1);
    Server latest = dataManager.load(lc);
    assertEquals(server1, latest);
}
Also used : Server(com.haulmont.cuba.core.model.common.Server) CommitContext(com.haulmont.cuba.core.global.CommitContext) LoadContext(com.haulmont.cuba.core.global.LoadContext) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 14 with Server

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

the class DataManagerTest method testLoadListById.

@Test
public void testLoadListById() {
    Server server = new Server();
    UUID id = server.getId();
    server.setName("localhost");
    server.setRunning(true);
    dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
    LoadContext<Server> loadContext = LoadContext.create(Server.class).setId(id);
    List<Server> list = dataManager.loadList(loadContext);
    assertTrue(list.size() == 1);
}
Also used : Entity(io.jmix.core.Entity) Server(com.haulmont.cuba.core.model.common.Server) CommitContext(com.haulmont.cuba.core.global.CommitContext) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 15 with Server

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

the class EntityListenerTest method testExceptionInListener.

@Test
public void testExceptionInListener() throws Exception {
    Server server;
    try (Transaction tx = persistence.createTransaction()) {
        server = metadata.create(Server.class);
        server.setName("localhost");
        persistence.getEntityManager().persist(server);
        tx.commit();
    }
    entityListenerManager.addListener(Server.class, TestListenerThrowing.class);
    try {
        try (Transaction tx = persistence.createTransaction()) {
            Server s = persistence.getEntityManager().find(Server.class, server.getId());
            s.setName("changed");
            tx.commit();
            fail();
        } catch (Exception e) {
            assertTrue(e instanceof IllegalStateException);
            assertEquals("test exception", e.getMessage());
        }
    } finally {
        entityListenerManager.removeListener(Server.class, TestListenerThrowing.class);
        testSupport.deleteRecord(server);
    }
}
Also used : Server(com.haulmont.cuba.core.model.common.Server) 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