Search in sources :

Example 26 with Product

use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.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 27 with Product

use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.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)

Example 28 with Product

use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-retail by googleapis.

the class CrudProduct method getProduct.

// get product
public static Product getProduct(String productName) throws IOException {
    Product product = Product.newBuilder().build();
    GetProductRequest getProductRequest = GetProductRequest.newBuilder().setName(productName).build();
    try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
        product = serviceClient.getProduct(getProductRequest);
        System.out.println("Get product response: " + product);
        return product;
    } catch (NotFoundException e) {
        System.out.printf("Product %s not found", productName);
        return product;
    }
}
Also used : GetProductRequest(com.google.cloud.retail.v2.GetProductRequest) Product(com.google.cloud.retail.v2.Product) ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Example 29 with Product

use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-retail by googleapis.

the class CrudProduct method updateProduct.

// update product
public static void updateProduct(Product originalProduct, String productName) throws IOException {
    UpdateProductRequest updateProductRequest = UpdateProductRequest.newBuilder().setProduct(generateProductForUpdate(originalProduct.getId(), productName)).setAllowMissing(true).build();
    System.out.printf("Update product request: %s%n", updateProductRequest);
    try (ProductServiceClient serviceClient = ProductServiceClient.create()) {
        Product updatedProduct = serviceClient.updateProduct(updateProductRequest);
        System.out.printf("Updated product: %s%n", updatedProduct);
    }
}
Also used : ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient) Product(com.google.cloud.retail.v2.Product) UpdateProductRequest(com.google.cloud.retail.v2.UpdateProductRequest)

Example 30 with Product

use of com.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-retail by googleapis.

the class CrudProduct method createProduct.

// call the Retail API to create product
public static Product createProduct(String productId, String branchName) throws IOException {
    CreateProductRequest createProductRequest = CreateProductRequest.newBuilder().setProduct(generateProduct()).setProductId(productId).setParent(branchName).build();
    System.out.printf("Create product request: %s%n", createProductRequest);
    Product createdProduct = ProductServiceClient.create().createProduct(createProductRequest);
    System.out.printf("Created product: %s%n", createdProduct);
    return createdProduct;
}
Also used : CreateProductRequest(com.google.cloud.retail.v2.CreateProductRequest) Product(com.google.cloud.retail.v2.Product)

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 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Test (org.junit.Test)4 Test (org.junit.jupiter.api.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 SvProduct (com.teachMeSkills.an15.VorobyovSergey.hwSix.Task3.models.SvProduct)3 PrintStream (java.io.PrintStream)3 Before (org.junit.Before)3