Search in sources :

Example 31 with Product

use of com.google.cloud.retail.v2.Product in project java-retail by googleapis.

the class ImportProductsBigQueryTableTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException, ExecutionException {
    String projectId = ServiceOptions.getDefaultProjectId();
    String branchName = String.format("projects/%s/locations/global/catalogs/default_catalog/branches/0", projectId);
    String datasetId = "products";
    String tableId = "products";
    String dataSchema = "product";
    ReconciliationMode reconciliationMode = ReconciliationMode.INCREMENTAL;
    bout = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(bout);
    originalPrintStream = System.out;
    System.setOut(out);
    ProductsCreateBigqueryTable.main();
    ImportProductsRequest importBigQueryRequest = getImportProductsBigQueryRequest(reconciliationMode, projectId, datasetId, tableId, dataSchema, branchName);
    waitForOperationCompletion(importBigQueryRequest);
}
Also used : ImportProductsRequest(com.google.cloud.retail.v2.ImportProductsRequest) PrintStream(java.io.PrintStream) ReconciliationMode(com.google.cloud.retail.v2.ImportProductsRequest.ReconciliationMode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 32 with Product

use of com.google.cloud.retail.v2.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 33 with Product

use of com.google.cloud.retail.v2.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 34 with Product

use of com.google.cloud.retail.v2.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 35 with Product

use of com.google.cloud.retail.v2.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 ProductServiceClient (com.google.cloud.retail.v2.ProductServiceClient)12 Product (com.google.cloud.vision.v1.Product)10 SetupCleanup.deleteProduct (setup.SetupCleanup.deleteProduct)9 PriceInfo (com.google.cloud.retail.v2.PriceInfo)7 Test (org.junit.Test)6 SetupCleanup.createProduct (setup.SetupCleanup.createProduct)6 DeleteProductRequest (com.google.cloud.retail.v2.DeleteProductRequest)5 ImportProductsRequest (com.google.cloud.retail.v2.ImportProductsRequest)5 ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)5 Product (com.haulmont.cuba.testmodel.sales_1.Product)5 ListProductsPagedResponse (com.google.cloud.retail.v2.ProductServiceClient.ListProductsPagedResponse)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 PrintStream (java.io.PrintStream)4 Before (org.junit.Before)4 Test (org.junit.jupiter.api.Test)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 CreateProductRequest (com.google.cloud.retail.v2.CreateProductRequest)3 FulfillmentInfo (com.google.cloud.retail.v2.FulfillmentInfo)3 GetProductRequest (com.google.cloud.retail.v2.GetProductRequest)3