Search in sources :

Example 6 with Server

use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.

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);
        cont.deleteRecord(server);
    }
}
Also used : Server(com.haulmont.cuba.core.entity.Server) Test(org.junit.Test)

Example 7 with Server

use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.

the class EntityListenerTest method test.

@Test
public void test() {
    UUID id, id1;
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.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 = cont.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 = cont.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.entity.Server) UUID(java.util.UUID) Date(java.util.Date) Test(org.junit.Test)

Example 8 with Server

use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.

the class EntityListenerTest method testDetachAttch.

@Test
public void testDetachAttch() throws Exception {
    UUID id;
    Transaction tx = cont.persistence().createTransaction();
    try {
        EntityManager em = cont.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 = cont.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.entity.Server) UUID(java.util.UUID) Test(org.junit.Test)

Example 9 with Server

use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.

the class LockManagerTest method testLock.

@Test
public void testLock() throws Exception {
    Server entity = new Server();
    LockInfo lockInfo = lockManager.lock(entity);
    assertNull(lockInfo);
    lockInfo = lockManager.lock(entity);
    assertNotNull(lockInfo);
    lockManager.unlock(entity);
    lockInfo = lockManager.getLockInfo("sys$Server", entity.getId().toString());
    assertNull(lockInfo);
}
Also used : Server(com.haulmont.cuba.core.entity.Server) LockInfo(com.haulmont.cuba.core.global.LockInfo) Test(org.junit.Test)

Example 10 with Server

use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.

the class NamePatternTest method test.

@Test
public void test() {
    Server server = new Server();
    server.setName("orion");
    server.setRunning(false);
    String instanceName = ((Instance) server).getInstanceName();
    assertEquals(InstanceUtils.getInstanceName((Instance) server), instanceName);
}
Also used : Server(com.haulmont.cuba.core.entity.Server) Instance(com.haulmont.chile.core.model.Instance) Test(org.junit.Test)

Aggregations

Server (com.haulmont.cuba.core.entity.Server)33 Test (org.junit.Test)25 UUID (java.util.UUID)10 Entity (com.haulmont.cuba.core.entity.Entity)8 Before (org.junit.Before)4 UserSession (com.haulmont.cuba.security.global.UserSession)3 TestUserSessionSource (com.haulmont.cuba.testsupport.TestUserSessionSource)3 Date (java.util.Date)3 EntityManager (com.haulmont.cuba.core.EntityManager)2 Transaction (com.haulmont.cuba.core.Transaction)2 LoginWorker (com.haulmont.cuba.security.app.LoginWorker)2 User (com.haulmont.cuba.security.entity.User)2 QueryRunner (com.haulmont.bali.db.QueryRunner)1 Instance (com.haulmont.chile.core.model.Instance)1 DataService (com.haulmont.cuba.core.app.DataService)1 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)1 EntitySnapshot (com.haulmont.cuba.core.entity.EntitySnapshot)1 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)1 EntityDiff (com.haulmont.cuba.core.entity.diff.EntityDiff)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1