Search in sources :

Example 21 with Server

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

Example 22 with Server

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

Example 23 with Server

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

Example 24 with Server

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

Example 25 with Server

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();
    }
}
Also used : Server(com.haulmont.cuba.core.entity.Server) UUID(java.util.UUID) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor) 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