Search in sources :

Example 21 with Product

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

the class CreateProductTest 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 generatedProductId = UUID.randomUUID().toString();
    bout = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(bout);
    originalPrintStream = System.out;
    System.setOut(out);
    Product createdProduct = createProduct(generatedProductId, branchName);
    deleteProduct(createdProduct.getName());
}
Also used : PrintStream(java.io.PrintStream) CreateProduct.createProduct(product.CreateProduct.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.teachMeSkills.an15.MatveevArtyom.hw6.Inheritance.task3.Product in project java-retail by googleapis.

the class CrudProductTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException, ExecutionException {
    String projectId = ServiceOptions.getDefaultProjectId();
    String generatedProductId = UUID.randomUUID().toString();
    String branchName = String.format("projects/%s/locations/global/catalogs/default_catalog/branches/0", projectId);
    String productName = String.format("%s/products/%s", branchName, generatedProductId);
    bout = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(bout);
    originalPrintStream = System.out;
    System.setOut(out);
    Product createdProduct = createProduct(generatedProductId, branchName);
    getProduct(productName);
    updateProduct(createdProduct, productName);
    deleteProduct(productName);
}
Also used : PrintStream(java.io.PrintStream) CrudProduct.getProduct(product.CrudProduct.getProduct) CrudProduct.deleteProduct(product.CrudProduct.deleteProduct) CreateProduct.createProduct(product.CreateProduct.createProduct) Product(com.google.cloud.retail.v2.Product) CrudProduct.updateProduct(product.CrudProduct.updateProduct) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 23 with Product

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

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

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

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