Search in sources :

Example 26 with Product

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

the class SetupCleanup method createProduct.

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

Example 27 with Product

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

the class SetupCleanup method getProduct.

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 28 with Product

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

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

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

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