Search in sources :

Example 1 with Customer

use of com.haulmont.cuba.core.model.sales.Customer in project jmix by jmix-framework.

the class NonDetachedTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    try (Transaction tx = persistence.createTransaction()) {
        EntityManager em = persistence.getEntityManager();
        user = metadata.create(User.class);
        user.setName("testUser");
        user.setLogin("testLogin");
        companyGroup = metadata.create(Group.class);
        companyGroup.setName("Company");
        em.persist(companyGroup);
        user.setGroup(companyGroup);
        em.persist(user);
        customer = metadata.create(Customer.class);
        customer.setName("test customer");
        em.persist(customer);
        order = metadata.create(Order.class);
        order.setDate(new Date());
        order.setAmount(BigDecimal.TEN);
        order.setCustomer(customer);
        order.setUser(user);
        em.persist(order);
        cascadeEntity1 = metadata.create(CascadeDeletionPolicyEntity.class);
        cascadeEntity1.setName("cascadeEntity1");
        em.persist(cascadeEntity1);
        cascadeEntity2 = metadata.create(CascadeDeletionPolicyEntity.class);
        cascadeEntity2.setName("cascadeEntity2");
        cascadeEntity2.setFather(cascadeEntity1);
        em.persist(cascadeEntity2);
        cascadeEntity1.setFirstChild(cascadeEntity2);
        tx.commit();
    }
    orderView = new View(Order.class).addProperty("date").addProperty("amount").addProperty("customer", new View(Customer.class).addProperty("name")).addProperty("user", new View(User.class).addProperty("login").addProperty("name"));
}
Also used : Order(com.haulmont.cuba.core.model.sales.Order) Group(com.haulmont.cuba.core.model.common.Group) User(com.haulmont.cuba.core.model.common.User) CascadeDeletionPolicyEntity(com.haulmont.cuba.core.model.CascadeDeletionPolicyEntity) Customer(com.haulmont.cuba.core.model.sales.Customer) View(com.haulmont.cuba.core.global.View) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with Customer

use of com.haulmont.cuba.core.model.sales.Customer in project jmix by jmix-framework.

the class NonDetachedTest method loadChangeAndSave.

private Order loadChangeAndSave(Saver saver) {
    Order order = persistence.callInTransaction(em -> em.find(Order.class, this.order.getId()));
    Order orderCopy = metadata.getTools().copy(order);
    Customer customerCopy = metadata.getTools().copy(this.customer);
    Date date = DateUtils.addDays(orderCopy.getDate(), 1);
    orderCopy.setDate(date);
    orderCopy.setAmount(null);
    orderCopy.setCustomer(customerCopy);
    assertNull(orderCopy.getUser());
    assertTrue(entityStates.isNew(orderCopy));
    saver.save(orderCopy);
    order = persistence.callInTransaction(em -> em.find(Order.class, this.order.getId(), orderView));
    assertEquals(date, order.getDate());
    return order;
}
Also used : Order(com.haulmont.cuba.core.model.sales.Order) UuidProvider(io.jmix.core.UuidProvider) BeforeEach(org.junit.jupiter.api.BeforeEach) Customer(com.haulmont.cuba.core.model.sales.Customer) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) CoreTest(com.haulmont.cuba.core.testsupport.CoreTest) AppBeans(com.haulmont.cuba.core.global.AppBeans) Group(com.haulmont.cuba.core.model.common.Group) Metadata(com.haulmont.cuba.core.global.Metadata) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) HashSet(java.util.HashSet) BigDecimal(java.math.BigDecimal) CascadeDeletionPolicyEntity(com.haulmont.cuba.core.model.CascadeDeletionPolicyEntity) DataManager(com.haulmont.cuba.core.global.DataManager) Order(com.haulmont.cuba.core.model.sales.Order) FetchPlan(io.jmix.core.FetchPlan) Server(com.haulmont.cuba.core.model.common.Server) DateUtils(org.apache.commons.lang3.time.DateUtils) Test(org.junit.jupiter.api.Test) View(com.haulmont.cuba.core.global.View) AfterEach(org.junit.jupiter.api.AfterEach) TestSupport(com.haulmont.cuba.core.testsupport.TestSupport) EntityStates(io.jmix.core.EntityStates) Assertions(org.junit.jupiter.api.Assertions) Entity(io.jmix.core.Entity) User(com.haulmont.cuba.core.model.common.User) Customer(com.haulmont.cuba.core.model.sales.Customer) Date(java.util.Date)

Aggregations

View (com.haulmont.cuba.core.global.View)2 CascadeDeletionPolicyEntity (com.haulmont.cuba.core.model.CascadeDeletionPolicyEntity)2 Group (com.haulmont.cuba.core.model.common.Group)2 User (com.haulmont.cuba.core.model.common.User)2 Customer (com.haulmont.cuba.core.model.sales.Customer)2 Order (com.haulmont.cuba.core.model.sales.Order)2 Date (java.util.Date)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 DataManager (com.haulmont.cuba.core.global.DataManager)1 Metadata (com.haulmont.cuba.core.global.Metadata)1 Server (com.haulmont.cuba.core.model.common.Server)1 CoreTest (com.haulmont.cuba.core.testsupport.CoreTest)1 TestSupport (com.haulmont.cuba.core.testsupport.TestSupport)1 Entity (io.jmix.core.Entity)1 EntityStates (io.jmix.core.EntityStates)1 FetchPlan (io.jmix.core.FetchPlan)1 UuidProvider (io.jmix.core.UuidProvider)1 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1