use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.
the class DataManagerTest method testLoadListCaseInsensitive.
@Test
public void testLoadListCaseInsensitive() {
Server server = new Server();
server.setName("LocalHost");
server.setRunning(true);
dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
LoadContext<Server> loadContext = LoadContext.create(Server.class);
loadContext.setQueryString("select s from sys$Server s where s.name like :name").setParameter("name", "(?i)%loc%host%");
List<Server> list = dataManager.loadList(loadContext);
assertTrue(list.size() > 0);
}
use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.
the class DataManagerTest method testLoadList.
@Test
public void testLoadList() {
Server server = new Server();
server.setName("localhost");
server.setRunning(true);
dataManager.commit(new CommitContext(Collections.<Entity>singleton(server)));
LoadContext<Server> loadContext = LoadContext.create(Server.class);
loadContext.setQueryString("select s from " + PersistenceHelper.getEntityName(Server.class) + " s");
List<Server> list = dataManager.loadList(loadContext);
assertTrue(list.size() > 0);
}
use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.
the class DataManagerTest method testReloadWithDynamicAttributes.
@Test
public void testReloadWithDynamicAttributes() {
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).setLoadDynamicAttributes(true);
server = dataManager.load(loadContext);
assertNotNull(server.getDynamicAttributes());
server = dataManager.reload(server, View.LOCAL);
assertNotNull(server.getDynamicAttributes());
loadContext = LoadContext.create(Server.class).setId(id).setLoadDynamicAttributes(false);
server = dataManager.load(loadContext);
assertNull(server.getDynamicAttributes());
loadContext = LoadContext.create(Server.class).setLoadDynamicAttributes(true);
loadContext.setQueryString("select s from sys$Server s where s.id = :id").setParameter("id", id);
List<Server> resultList = dataManager.loadList(loadContext);
assertNotNull(resultList.get(0).getDynamicAttributes());
}
use of com.haulmont.cuba.core.entity.Server in project cuba by cuba-platform.
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.entity.Server in project cuba by cuba-platform.
the class EntityListenerTest method testEntityManager.
@Test
public void testEntityManager() throws Exception {
Server server;
UUID serverId;
Transaction tx = cont.persistence().createTransaction();
try {
// create
server = new Server();
server.setName("server1");
serverId = server.getId();
cont.persistence().getEntityManager().persist(server);
tx.commitRetaining();
assertNotNull(server.getData());
UUID relatedId = UUID.fromString(server.getData());
FileDescriptor related = cont.persistence().getEntityManager().find(FileDescriptor.class, relatedId);
assertNotNull(related);
assertEquals("Related", related.getName());
tx.commitRetaining();
// update
server = cont.persistence().getEntityManager().find(Server.class, serverId);
assertNotNull(server);
server.setName("server1 updated");
tx.commitRetaining();
related = cont.persistence().getEntityManager().find(FileDescriptor.class, relatedId);
assertNotNull(related);
assertEquals("Related updated", related.getName());
tx.commitRetaining();
// remove
server = cont.persistence().getEntityManager().find(Server.class, serverId);
assertNotNull(server);
cont.persistence().getEntityManager().remove(server);
tx.commitRetaining();
related = cont.persistence().getEntityManager().find(FileDescriptor.class, relatedId);
assertNull(related);
tx.commit();
} finally {
tx.end();
}
}
Aggregations