Search in sources :

Example 56 with Product

use of com.google.cloud.vision.v1.Product in project java-vision by googleapis.

the class ITSystemTest method setUp.

@BeforeClass
public static void setUp() throws IOException {
    imageAnnotatorClient = ImageAnnotatorClient.create();
    /* create product */
    productSearchClient = ProductSearchClient.create();
    Product createProduct = Product.newBuilder().setName(PRODUCT_ID).setDisplayName(PRODUCT_DISPLAY_NAME).setProductCategory(PRODUCT_CATEGORY).build();
    CreateProductRequest productRequest = CreateProductRequest.newBuilder().setParent(LOCATION_NAME).setProduct(createProduct).build();
    product = productSearchClient.createProduct(productRequest);
    productName = getName(product.getName());
    formatProductName = ProductName.of(PROJECT_ID, COMPUTE_REGION, productName).toString();
    /* create product set */
    ProductSet createProductSet = ProductSet.newBuilder().setDisplayName(PRODUCT_SET_DISPLAY_NAME).build();
    CreateProductSetRequest productSetRequest = CreateProductSetRequest.newBuilder().setParent(LOCATION_NAME).setProductSet(createProductSet).setProductSetId(PRODUCT_SET_ID).build();
    productSet = productSearchClient.createProductSet(productSetRequest);
    productSetName = getName(productSet.getName());
    formatProductSetName = ProductSetName.of(PROJECT_ID, COMPUTE_REGION, productSetName).toString();
    /* add product to product set */
    AddProductToProductSetRequest productToProductSetRequest = AddProductToProductSetRequest.newBuilder().setName(formatProductSetName).setProduct(formatProductName).build();
    productSearchClient.addProductToProductSet(productToProductSetRequest);
    /* create reference image */
    ReferenceImage createReferenceImage = ReferenceImage.newBuilder().setUri(SAMPLE_BUCKET + "product_search/shoes_1.jpg").build();
    CreateReferenceImageRequest imageRequest = CreateReferenceImageRequest.newBuilder().setParent(formatProductName).setReferenceImage(createReferenceImage).build();
    referenceImage = productSearchClient.createReferenceImage(imageRequest);
    referenceImageName = getName(referenceImage.getName());
    formatReferenceImageName = ReferenceImageName.of(PROJECT_ID, COMPUTE_REGION, productName, referenceImageName).toString();
}
Also used : CreateProductRequest(com.google.cloud.vision.v1.CreateProductRequest) CreateReferenceImageRequest(com.google.cloud.vision.v1.CreateReferenceImageRequest) Product(com.google.cloud.vision.v1.Product) CreateProductSetRequest(com.google.cloud.vision.v1.CreateProductSetRequest) ProductSet(com.google.cloud.vision.v1.ProductSet) ReferenceImage(com.google.cloud.vision.v1.ReferenceImage) AddProductToProductSetRequest(com.google.cloud.vision.v1.AddProductToProductSetRequest) BeforeClass(org.junit.BeforeClass)

Example 57 with Product

use of com.google.cloud.vision.v1.Product in project java-vision by googleapis.

the class ITSystemTest method updateProductTest.

@Test
public void updateProductTest() {
    Product updateProduct = product.toBuilder().addProductLabels(KEY_VALUE).build();
    UpdateProductRequest request = UpdateProductRequest.newBuilder().setProduct(updateProduct).build();
    Product actualProduct = productSearchClient.updateProduct(request);
    assertEquals(product.getName(), actualProduct.getName());
    assertEquals(PRODUCT_DISPLAY_NAME, actualProduct.getDisplayName());
    assertEquals(PRODUCT_CATEGORY, actualProduct.getProductCategory());
    assertEquals(ImmutableList.of(KEY_VALUE), actualProduct.getProductLabelsList());
    assertEquals(1, actualProduct.getProductLabelsCount());
}
Also used : Product(com.google.cloud.vision.v1.Product) UpdateProductRequest(com.google.cloud.vision.v1.UpdateProductRequest) Test(org.junit.Test)

Example 58 with Product

use of com.google.cloud.vision.v1.Product in project java-vision by googleapis.

the class ITSystemTest method listProductsTest.

@Test
public void listProductsTest() {
    ListProductsRequest request = ListProductsRequest.newBuilder().setParent(LOCATION_NAME).build();
    for (Product actualProduct : productSearchClient.listProducts(request).iterateAll()) {
        if (product.getName().equals(actualProduct.getName())) {
            assertEquals(PRODUCT_DISPLAY_NAME, actualProduct.getDisplayName());
            assertEquals(PRODUCT_CATEGORY, actualProduct.getProductCategory());
        }
    }
}
Also used : ListProductsRequest(com.google.cloud.vision.v1.ListProductsRequest) Product(com.google.cloud.vision.v1.Product) Test(org.junit.Test)

Example 59 with Product

use of com.google.cloud.vision.v1.Product in project java-vision by googleapis.

the class ProductSearchClientTest method listProductsTest.

@Test
public void listProductsTest() throws Exception {
    Product responsesElement = Product.newBuilder().build();
    ListProductsResponse expectedResponse = ListProductsResponse.newBuilder().setNextPageToken("").addAllProducts(Arrays.asList(responsesElement)).build();
    mockProductSearch.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    ListProductsPagedResponse pagedListResponse = client.listProducts(parent);
    List<Product> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getProductsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockProductSearch.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListProductsRequest actualRequest = ((ListProductsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListProductsPagedResponse(com.google.cloud.vision.v1.ProductSearchClient.ListProductsPagedResponse) Test(org.junit.Test)

Example 60 with Product

use of com.google.cloud.vision.v1.Product in project java-vision by googleapis.

the class ProductSearchClientTest method listProductsInProductSetTest2.

@Test
public void listProductsInProductSetTest2() throws Exception {
    Product responsesElement = Product.newBuilder().build();
    ListProductsInProductSetResponse expectedResponse = ListProductsInProductSetResponse.newBuilder().setNextPageToken("").addAllProducts(Arrays.asList(responsesElement)).build();
    mockProductSearch.addResponse(expectedResponse);
    String name = "name3373707";
    ListProductsInProductSetPagedResponse pagedListResponse = client.listProductsInProductSet(name);
    List<Product> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getProductsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockProductSearch.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListProductsInProductSetRequest actualRequest = ((ListProductsInProductSetRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListProductsInProductSetPagedResponse(com.google.cloud.vision.v1.ProductSearchClient.ListProductsInProductSetPagedResponse) Test(org.junit.Test)

Aggregations

Product (com.google.cloud.retail.v2.Product)20 ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)19 Product (com.google.cloud.vision.v1.Product)10 Test (org.junit.Test)9 SetupCleanup.deleteProduct (setup.SetupCleanup.deleteProduct)9 ProductServiceClient (com.google.cloud.retail.v2.ProductServiceClient)8 SetupCleanup.createProduct (setup.SetupCleanup.createProduct)6 AbstractMessage (com.google.protobuf.AbstractMessage)5 ProductSet (com.google.cloud.vision.v1.ProductSet)4 ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)4 Product (com.haulmont.cuba.testmodel.sales_1.Product)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 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3