use of com.haulmont.cuba.testmodel.sales_1.OrderLine in project cuba by cuba-platform.
the class DataManagerTransactionalUsageTest method testSecureWithProgrammaticTx.
@Test
public void testSecureWithProgrammaticTx() {
SaleProcessor processor = AppBeans.get("test_SaleProcessor");
Id<OrderLine, UUID> orderLineId = processor.sellSecureWithProgrammaticTx("abc", 10);
Product product1 = dataManager.load(Product.class).query("select p from sales1$Product p where p.name = :name").parameter("name", "abc").one();
assertEquals(90, (int) product1.getQuantity());
Product product2 = dataManager.create(Product.class);
product2.setName("def");
product2.setQuantity(100);
dataManager.commit(product2);
OrderLine orderLine = dataManager.load(orderLineId).view("with-product").one();
orderLine.setProduct(product2);
dataManager.commit(orderLine);
Product changedProduct1 = dataManager.load(Id.of(product1)).one();
assertEquals(100, (int) changedProduct1.getQuantity());
Product changedProduct2 = dataManager.load(Id.of(product2)).one();
assertEquals(90, (int) changedProduct2.getQuantity());
}
use of com.haulmont.cuba.testmodel.sales_1.OrderLine in project cuba by cuba-platform.
the class DataManagerTransactionalUsageTest method test.
@Test
public void test() {
SaleProcessor processor = AppBeans.get("test_SaleProcessor");
Id<OrderLine, UUID> orderLineId = processor.sell("abc", 10);
Product product1 = dataManager.load(Product.class).query("select p from sales1$Product p where p.name = :name").parameter("name", "abc").one();
assertEquals(90, (int) product1.getQuantity());
// change Product in OrderLIne
Product product2 = dataManager.create(Product.class);
product2.setName("def");
product2.setQuantity(100);
dataManager.commit(product2);
OrderLine orderLine = dataManager.load(orderLineId).view("with-product").one();
orderLine.setProduct(product2);
dataManager.commit(orderLine);
Product changedProduct1 = dataManager.load(Id.of(product1)).one();
assertEquals(100, (int) changedProduct1.getQuantity());
Product changedProduct2 = dataManager.load(Id.of(product2)).one();
assertEquals(90, (int) changedProduct2.getQuantity());
// remove OrderLine
OrderLine orderLineToRemove = dataManager.load(orderLineId).view("with-product").one();
dataManager.remove(orderLineToRemove);
Product product21 = dataManager.load(Id.of(product2)).one();
assertEquals(100, (int) product21.getQuantity());
}