Search in sources :

Example 16 with Server

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

the class EntityListenerTest method testEntityManager.

@Test
public void testEntityManager() throws Exception {
    Server server;
    UUID serverId;
    Transaction tx = persistence.createTransaction();
    try {
        // create
        server = new Server();
        server.setName("server1");
        serverId = server.getId();
        persistence.getEntityManager().persist(server);
        tx.commitRetaining();
        assertNotNull(server.getData());
        UUID relatedId = UUID.fromString(server.getData());
        FileDescriptor related = persistence.getEntityManager().find(FileDescriptor.class, relatedId);
        assertNotNull(related);
        assertEquals("Related", related.getName());
        tx.commitRetaining();
        // update
        server = persistence.getEntityManager().find(Server.class, serverId);
        assertNotNull(server);
        server.setName("server1 updated");
        tx.commitRetaining();
        related = persistence.getEntityManager().find(FileDescriptor.class, relatedId);
        assertNotNull(related);
        assertEquals("Related updated", related.getName());
        tx.commitRetaining();
        // remove
        server = persistence.getEntityManager().find(Server.class, serverId);
        assertNotNull(server);
        persistence.getEntityManager().remove(server);
        tx.commitRetaining();
        related = persistence.getEntityManager().find(FileDescriptor.class, relatedId);
        assertNull(related);
        tx.commit();
    } finally {
        tx.end();
    }
}
Also used : Server(com.haulmont.cuba.core.model.common.Server) UUID(java.util.UUID) FileDescriptor(com.haulmont.cuba.core.model.common.FileDescriptor) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 17 with Server

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

the class EntityListenerTest method testDetachAttach.

@Test
public void testDetachAttach() throws Exception {
    UUID id;
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        Server server = new Server();
        id = server.getId();
        server.setName("localhost");
        server.setRunning(true);
        em.persist(server);
        tx.commitRetaining();
        assertEquals(1, detachAttachListener.events.size());
        assertEquals("onBeforeDetach: " + id, detachAttachListener.events.get(0));
        detachAttachListener.events.clear();
        server.setName("somehost");
        em = persistence.getEntityManager();
        em.merge(server);
        assertEquals(1, detachAttachListener.events.size());
        assertEquals("onBeforeAttach: " + id, detachAttachListener.events.get(0));
        detachAttachListener.events.clear();
        tx.commit();
        assertEquals(1, detachAttachListener.events.size());
        assertEquals("onBeforeDetach: " + id, detachAttachListener.events.get(0));
        detachAttachListener.events.clear();
    } finally {
        tx.end();
    }
}
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 18 with Server

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

the class EntityListenerTest method test.

@Test
public void test() {
    UUID id, id1;
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        assertNotNull(em);
        Server server = new Server();
        id = server.getId();
        server.setName("localhost");
        server.setRunning(true);
        em.persist(server);
        Server server1 = new Server();
        id1 = server1.getId();
        server1.setName("otherhost");
        server1.setRunning(true);
        em.persist(server1);
        tx.commitRetaining();
        assertEquals(2, TestListener.events.size());
        assertTrue(CollectionUtils.isEqualCollection(Arrays.asList("onAfterInsert: " + id, "onAfterInsert: " + id1), TestListener.events));
        TestListener.events.clear();
        assertEquals(2, listenerBean.events.size());
        assertTrue(CollectionUtils.isEqualCollection(Arrays.asList("onAfterInsert: " + id, "onAfterInsert: " + id1), listenerBean.events));
        listenerBean.events.clear();
        em = persistence.getEntityManager();
        server = em.find(Server.class, id);
        server.setName(server.getName() + " - " + new Date());
        tx.commitRetaining();
        assertEquals(1, TestListener.events.size());
        assertEquals("onAfterUpdate: " + id, TestListener.events.get(0));
        TestListener.events.clear();
        assertEquals(1, listenerBean.events.size());
        assertEquals("onAfterUpdate: " + id, listenerBean.events.get(0));
        listenerBean.events.clear();
        em = persistence.getEntityManager();
        server = em.find(Server.class, id1);
        em.remove(server);
        tx.commit();
        assertEquals(1, TestListener.events.size());
        assertEquals("onAfterDelete: " + id1, TestListener.events.get(0));
        assertEquals(1, listenerBean.events.size());
        assertEquals("onAfterDelete: " + id1, listenerBean.events.get(0));
    } finally {
        tx.end();
    }
}
Also used : Server(com.haulmont.cuba.core.model.common.Server) UUID(java.util.UUID) Date(java.util.Date) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 19 with Server

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

the class DataManagerTest method testNonEntityResults.

@Test
public void testNonEntityResults() throws Exception {
    // fails on aggregates
    LoadContext context = LoadContext.create(Server.class).setQuery(LoadContext.createQuery("select count(s) from test$Server s"));
    try {
        dataManager.load(context);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof DevelopmentException);
    }
    // fails on single attributes
    context = LoadContext.create(Server.class).setQuery(LoadContext.createQuery("select s.name from test$Server s"));
    try {
        dataManager.load(context);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof DevelopmentException);
    }
}
Also used : Server(com.haulmont.cuba.core.model.common.Server) LoadContext(com.haulmont.cuba.core.global.LoadContext) DevelopmentException(io.jmix.core.DevelopmentException) DevelopmentException(io.jmix.core.DevelopmentException) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 20 with Server

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

the class DataManagerTest method testLoad.

@Test
public void testLoad() {
    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());
}
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)

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