Search in sources :

Example 21 with Product

use of com.haulmont.cuba.testmodel.sales_1.Product in project java-retail by googleapis.

the class GetProductTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException, ExecutionException {
    String generatedProductId = UUID.randomUUID().toString();
    bout = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(bout);
    originalPrintStream = System.out;
    System.setOut(out);
    Product createdProduct = createProduct(generatedProductId);
    Product product = getProduct(createdProduct.getName());
    deleteProduct(product.getName());
}
Also used : PrintStream(java.io.PrintStream) CrudProduct.getProduct(product.CrudProduct.getProduct) SetupCleanup.createProduct(setup.SetupCleanup.createProduct) SetupCleanup.deleteProduct(setup.SetupCleanup.deleteProduct) Product(com.google.cloud.retail.v2.Product) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 22 with Product

use of com.haulmont.cuba.testmodel.sales_1.Product 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)

Example 23 with Product

use of com.haulmont.cuba.testmodel.sales_1.Product in project cuba by cuba-platform.

the class TransactionalActionUsageTest method testOnSuccessAction.

@Test
public void testOnSuccessAction() {
    EntitySet entities = transactionalActionFactory.getTransactionalAction().withCommitContext(() -> {
        CommitContext cc = new CommitContext();
        Product p = metadata.create(Product.class);
        p.setName("test");
        p.setQuantity(100);
        cc.addInstanceToCommit(p);
        return cc;
    }).onSuccess(es -> {
        es.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).forEach(e -> ((Product) e).setName("newName"));
    }).perform();
    Product product = (Product) entities.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).findFirst().orElse(null);
    assertNotNull(product);
    assertEquals("newName", product.getName());
    Product productFromDb = transactionalDataManager.load(Id.of(product)).one();
    assertNotNull(productFromDb);
    assertEquals("test", productFromDb.getName());
}
Also used : Test(org.junit.jupiter.api.Test) BeforeEach(org.junit.jupiter.api.BeforeEach) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions(org.junit.jupiter.api.Assertions) QueryRunner(com.haulmont.bali.db.QueryRunner) Product(com.haulmont.cuba.testmodel.sales_1.Product) Id(com.haulmont.cuba.core.entity.contracts.Id) TestContainer(com.haulmont.cuba.testsupport.TestContainer) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Product(com.haulmont.cuba.testmodel.sales_1.Product) Test(org.junit.jupiter.api.Test)

Example 24 with Product

use of com.haulmont.cuba.testmodel.sales_1.Product in project cuba by cuba-platform.

the class TransactionalActionUsageTest method testOnFailAction.

@Test
public void testOnFailAction() {
    EntitySet entities = transactionalActionFactory.getTransactionalAction().withCommitContext(() -> {
        CommitContext cc = new CommitContext();
        Product p = metadata.create(Product.class);
        p.setName("test");
        p.setQuantity(100);
        p.setId(null);
        cc.addInstanceToCommit(p);
        return cc;
    }).onFail((cc, t) -> {
        messageFromOnFailAction = "[testOnFailAction] commit failed";
    }).perform();
    assertNull(entities);
    assertEquals("[testOnFailAction] commit failed", messageFromOnFailAction);
}
Also used : Test(org.junit.jupiter.api.Test) BeforeEach(org.junit.jupiter.api.BeforeEach) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions(org.junit.jupiter.api.Assertions) QueryRunner(com.haulmont.bali.db.QueryRunner) Product(com.haulmont.cuba.testmodel.sales_1.Product) Id(com.haulmont.cuba.core.entity.contracts.Id) TestContainer(com.haulmont.cuba.testsupport.TestContainer) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Product(com.haulmont.cuba.testmodel.sales_1.Product) Test(org.junit.jupiter.api.Test)

Example 25 with Product

use of com.haulmont.cuba.testmodel.sales_1.Product in project cuba by cuba-platform.

the class TransactionalActionUsageTest method testAllActions.

@Test
public void testAllActions() {
    EntitySet entities = transactionalDataManager.commitAction(() -> {
        CommitContext cc = new CommitContext();
        Product p = transactionalDataManager.create(Product.class);
        p.setName("allActionsTest");
        p.setQuantity(100);
        cc.addInstanceToCommit(p);
        return cc;
    }).onSuccess(es -> {
        es.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).forEach(e -> ((Product) e).setName("onSuccessName"));
    }).onFail((cc, t) -> {
        messageFromOnFailAction = "[testAllActions] commit failed";
    }).afterCompletion(cc -> {
        messageFromAfterCommitAction = "[testAllActions] transaction ended";
    }).perform();
    Product product = (Product) entities.stream().filter(e -> Product.class.equals(e.getMetaClass().getJavaClass())).findFirst().orElse(null);
    assertNotNull(product);
    assertEquals("onSuccessName", product.getName());
    Product productFromDb = transactionalDataManager.load(Id.of(product)).one();
    assertNotNull(productFromDb);
    assertEquals("allActionsTest", productFromDb.getName());
    assertNotEquals("[testAllActions] commit failed", messageFromOnFailAction);
    assertEquals("[testAllActions] transaction ended", messageFromAfterCommitAction);
}
Also used : Test(org.junit.jupiter.api.Test) BeforeEach(org.junit.jupiter.api.BeforeEach) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions(org.junit.jupiter.api.Assertions) QueryRunner(com.haulmont.bali.db.QueryRunner) Product(com.haulmont.cuba.testmodel.sales_1.Product) Id(com.haulmont.cuba.core.entity.contracts.Id) TestContainer(com.haulmont.cuba.testsupport.TestContainer) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Product(com.haulmont.cuba.testmodel.sales_1.Product) Test(org.junit.jupiter.api.Test)

Aggregations

Product (com.google.cloud.retail.v2.Product)20 Product (com.google.cloud.vision.v1.Product)10 SetupCleanup.deleteProduct (setup.SetupCleanup.deleteProduct)9 ProductServiceClient (com.google.cloud.retail.v2.ProductServiceClient)8 SetupCleanup.createProduct (setup.SetupCleanup.createProduct)6 ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)5 Product (com.haulmont.cuba.testmodel.sales_1.Product)5 Test (org.junit.jupiter.api.Test)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 PrintStream (java.io.PrintStream)4 Before (org.junit.Before)4 Test (org.junit.Test)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 CreateProductRequest (com.google.cloud.retail.v2.CreateProductRequest)3 GetProductRequest (com.google.cloud.retail.v2.GetProductRequest)3 QueryRunner (com.haulmont.bali.db.QueryRunner)3 Id (com.haulmont.cuba.core.entity.contracts.Id)3 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)3 TestContainer (com.haulmont.cuba.testsupport.TestContainer)3 Assertions (org.junit.jupiter.api.Assertions)3