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"));
}
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;
}
Aggregations