Search in sources :

Example 1 with OrderLine

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());
}
Also used : OrderLine(com.haulmont.cuba.testmodel.sales_1.OrderLine) Product(com.haulmont.cuba.testmodel.sales_1.Product) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 2 with OrderLine

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());
}
Also used : OrderLine(com.haulmont.cuba.testmodel.sales_1.OrderLine) Product(com.haulmont.cuba.testmodel.sales_1.Product) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

OrderLine (com.haulmont.cuba.testmodel.sales_1.OrderLine)2 Product (com.haulmont.cuba.testmodel.sales_1.Product)2 UUID (java.util.UUID)2 Test (org.junit.jupiter.api.Test)2