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