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