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);
}
}
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();
}
}
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();
}
}
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);
}
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);
}
Aggregations