Search in sources :

Example 11 with FetchPlan

use of io.jmix.core.FetchPlan in project jmix by jmix-framework.

the class PersistenceHelperTest method testCheckLoaded.

@Test
public void testCheckLoaded() {
    Server server = new Server();
    persistence.runInTransaction((em) -> {
        em.persist(server);
    });
    FetchPlan view = new View(Server.class).addProperty("name").addProperty("data").setLoadPartialEntities(true);
    Server reloadedServer = persistence.callInTransaction((em) -> {
        return em.find(Server.class, server.getId(), view);
    });
    // fine
    entityStates.checkLoaded(reloadedServer, "name");
    try {
        entityStates.checkLoaded(reloadedServer, "data", "running");
        Assertions.fail("Must throw exception");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("Server.running"));
    }
}
Also used : Server(com.haulmont.cuba.core.model.common.Server) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) Test(org.junit.jupiter.api.Test) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest)

Example 12 with FetchPlan

use of io.jmix.core.FetchPlan in project jmix by jmix-framework.

the class UpdateDetachedTest method test.

@Test
public void test() throws Exception {
    Permission p;
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name"));
        p = em.find(Permission.class, permissionId, view);
        tx.commitRetaining();
        assertNotNull(p);
        p.setTarget("newTarget");
        em = persistence.getEntityManager();
        p = em.merge(p);
        tx.commit();
    } finally {
        tx.end();
    }
    p = testSupport.reserialize(p);
    assertTrue(entityStates.isDetached(p));
    assertNotNull(p.getRole());
    assertTrue(entityStates.isDetached(p.getRole()));
    assertTrue(entityStates.isLoaded(p, "role"));
}
Also used : Permission(com.haulmont.cuba.core.model.common.Permission) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 13 with FetchPlan

use of io.jmix.core.FetchPlan in project jmix by jmix-framework.

the class UpdateDetachedTest method testRollback.

@Test
public void testRollback() {
    Permission p = null;
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(Permission.class).addProperty("target").addProperty("role", new View(Role.class).addProperty("name"));
        p = em.find(Permission.class, permissionId, view);
        tx.commitRetaining();
        p.setTarget("newTarget");
        em = persistence.getEntityManager();
        p = em.merge(p);
        throwException();
        tx.commit();
    } catch (RuntimeException e) {
    // ok
    } finally {
        tx.end();
        assertNotNull(p);
    }
}
Also used : Permission(com.haulmont.cuba.core.model.common.Permission) FetchPlan(io.jmix.core.FetchPlan) View(com.haulmont.cuba.core.global.View) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) Test(org.junit.jupiter.api.Test)

Example 14 with FetchPlan

use of io.jmix.core.FetchPlan in project jmix by jmix-framework.

the class ViewBuilderTest method testBase.

@Test
public void testBase() {
    FetchPlan view = ViewBuilder.of(Pet.class).addView(FetchPlan.BASE).build();
    assertTrue(containsSystemProperties(view));
    assertTrue(view.containsProperty("name"));
}
Also used : FetchPlan(io.jmix.core.FetchPlan) Test(org.junit.jupiter.api.Test) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest)

Example 15 with FetchPlan

use of io.jmix.core.FetchPlan in project jmix by jmix-framework.

the class ViewBuilderTest method testLocalAndRef.

@Test
public void testLocalAndRef() {
    FetchPlan view = ViewBuilder.of(Pet.class).addView(FetchPlan.LOCAL).add("owner").build();
    assertTrue(containsSystemProperties(view));
    assertTrue(view.containsProperty("name"));
    assertNotNull(view.getProperty("owner"));
    FetchPlan ownerView = view.getProperty("owner").getFetchPlan();
    assertNotNull(ownerView);
    assertFalse(containsSystemProperties(ownerView));
    assertFalse(ownerView.containsProperty("name"));
    assertFalse(ownerView.containsProperty("address"));
    view = ViewBuilder.of(Pet.class).addView(FetchPlan.LOCAL).add("owner.name").add("owner.address.city").build();
    assertTrue(containsSystemProperties(view));
    assertTrue(view.containsProperty("name"));
    assertNotNull(view.getProperty("owner"));
    ownerView = view.getProperty("owner").getFetchPlan();
    assertNotNull(ownerView);
    assertFalse(containsSystemProperties(ownerView));
    assertTrue(ownerView.containsProperty("name"));
    assertTrue(ownerView.containsProperty("address"));
    FetchPlan addressView = ownerView.getProperty("address").getFetchPlan();
    assertTrue(addressView.containsProperty("city"));
}
Also used : FetchPlan(io.jmix.core.FetchPlan) Pet(com.haulmont.cuba.core.model.Pet) Test(org.junit.jupiter.api.Test) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest)

Aggregations

FetchPlan (io.jmix.core.FetchPlan)61 Test (org.junit.jupiter.api.Test)48 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)45 View (com.haulmont.cuba.core.global.View)35 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)10 Pet (com.haulmont.cuba.core.model.Pet)5 SoftDeleteOneToOneA (com.haulmont.cuba.core.model.SoftDeleteOneToOneA)5 Group (com.haulmont.cuba.core.model.common.Group)5 User (com.haulmont.cuba.core.model.common.User)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 DataManager (com.haulmont.cuba.core.global.DataManager)3 LoadContext (com.haulmont.cuba.core.global.LoadContext)3 FetchPlanProperty (io.jmix.core.FetchPlanProperty)3 Metadata (io.jmix.core.Metadata)3 MetadataTools (io.jmix.core.MetadataTools)3 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 SoftDeleteOneToOneB (com.haulmont.cuba.core.model.SoftDeleteOneToOneB)2 Permission (com.haulmont.cuba.core.model.common.Permission)2 QueryImpl (com.haulmont.cuba.core.sys.QueryImpl)2 Entity (io.jmix.core.Entity)2