Search in sources :

Example 51 with FetchPlan

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

the class ViewBuilderTest method testMinimal.

@Test
public void testMinimal() {
    FetchPlan view = ViewBuilder.of(Pet.class).addView(FetchPlan.INSTANCE_NAME).build();
    assertFalse(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 52 with FetchPlan

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

the class ViewBuilderTest method testProperty.

@Test
public void testProperty() {
    FetchPlan view = ViewBuilder.of(Pet.class).add("name").build();
    assertFalse(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 53 with FetchPlan

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

the class ViewBuilderTest method testRefLocalView.

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

Example 54 with FetchPlan

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

the class SoftDeleteTest method testOneToOneMappedBy.

@Test
public void testOneToOneMappedBy() {
    System.out.println("===================== BEGIN testOneToOneMappedBy =====================");
    // test fetchMode = AUTO
    System.out.println("===================== BEGIN testOneToOneMappedBy fetchMode = AUTO =====================");
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(SoftDeleteOneToOneB.class, "testView").addProperty("name").addProperty("a", new View(SoftDeleteOneToOneA.class, "testView").addProperty("name"));
        SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id, view);
        assertNotNull(oneToOneB);
        assertNull(oneToOneB.getA());
        tx.commit();
    } finally {
        tx.end();
    }
    // test fetchMode = BATCH
    System.out.println("===================== BEGIN testOneToOneMappedBy fetchMode = BATCH =====================");
    tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(SoftDeleteOneToOneB.class, "testView").addProperty("name").addProperty("a", new View(SoftDeleteOneToOneA.class, "testView").addProperty("name"), FetchMode.BATCH);
        SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id, view);
        assertNotNull(oneToOneB);
        assertNull(oneToOneB.getA());
        tx.commit();
    } finally {
        tx.end();
    }
    // test fetchMode = UNDEFINED
    System.out.println("===================== BEGIN testOneToOneMappedBy fetchMode = UNDEFINED =====================");
    tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(SoftDeleteOneToOneB.class, "testView").addProperty("name").addProperty("a", new View(SoftDeleteOneToOneA.class, "testView").addProperty("name"), FetchMode.UNDEFINED);
        SoftDeleteOneToOneB oneToOneB = em.find(SoftDeleteOneToOneB.class, oneToOneB1Id, view);
        assertNotNull(oneToOneB);
        assertNull(oneToOneB.getA());
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToOneMappedBy =====================");
}
Also used : JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) SoftDeleteOneToOneB(com.haulmont.cuba.core.model.SoftDeleteOneToOneB) 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 55 with FetchPlan

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

the class SoftDeleteTest method testOneToMany.

@Test
public void testOneToMany() {
    System.out.println("===================== BEGIN testOneToMany =====================");
    // test fetchMode = AUTO
    Transaction tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("userRoles", new View(UserRole.class, "testView").addProperty("role", new View(Role.class, "testView").addProperty("name")));
        User user = em.find(User.class, userId, view);
        List<UserRole> userRoles = user.getUserRoles();
        assertEquals(1, userRoles.size());
        for (UserRole ur : userRoles) {
            assertNotNull(ur.getRole());
        }
        tx.commit();
    } finally {
        tx.end();
    }
    // test fetchMode = JOIN
    tx = persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        FetchPlan view = new View(User.class, "testView").addProperty("name").addProperty("login").addProperty("userRoles", new View(UserRole.class, "testView"), FetchMode.JOIN);
        User user = em.find(User.class, userId, view);
        List<UserRole> userRoles = user.getUserRoles();
        assertEquals(1, userRoles.size());
        for (UserRole ur : userRoles) {
            assertNotNull(ur.getRole());
        }
        tx.commit();
    } finally {
        tx.end();
    }
    System.out.println("===================== END testOneToMany =====================");
}
Also used : JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) 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)

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