Search in sources :

Example 11 with Product

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

the class ITSystemTest method listProductsInProductSetTest.

@Test
public void listProductsInProductSetTest() {
    ListProductsInProductSetRequest request = ListProductsInProductSetRequest.newBuilder().setName(formatProductSetName).build();
    for (Product actualProduct : productSearchClient.listProductsInProductSet(request).iterateAll()) {
        assertEquals(product.getName(), actualProduct.getName());
        assertEquals(PRODUCT_DISPLAY_NAME, actualProduct.getDisplayName());
        assertEquals(PRODUCT_CATEGORY, actualProduct.getProductCategory());
    }
}
Also used : ListProductsInProductSetRequest(com.google.cloud.vision.v1.ListProductsInProductSetRequest) Product(com.google.cloud.vision.v1.Product) Test(org.junit.Test)

Example 12 with Product

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

the class PurgeProductsInProductSet method purgeProductsInProductSet.

// Delete all products in a product set.
public static void purgeProductsInProductSet(String projectId, String location, String productSetId) throws Exception {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        String parent = LocationName.format(projectId, location);
        ProductSetPurgeConfig productSetPurgeConfig = ProductSetPurgeConfig.newBuilder().setProductSetId(productSetId).build();
        PurgeProductsRequest request = PurgeProductsRequest.newBuilder().setParent(parent).setProductSetPurgeConfig(productSetPurgeConfig).setForce(true).build();
        OperationFuture<Empty, BatchOperationMetadata> response = client.purgeProductsAsync(request);
        response.getPollingFuture().get(180, TimeUnit.SECONDS);
        System.out.println("Products removed from product set.");
    }
}
Also used : Empty(com.google.protobuf.Empty) PurgeProductsRequest(com.google.cloud.vision.v1.PurgeProductsRequest) ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) ProductSetPurgeConfig(com.google.cloud.vision.v1.ProductSetPurgeConfig) BatchOperationMetadata(com.google.cloud.vision.v1.BatchOperationMetadata)

Example 13 with Product

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

the class ProductSearchClientTest method listProductsInProductSetTest.

@Test
public void listProductsInProductSetTest() throws Exception {
    Product responsesElement = Product.newBuilder().build();
    ListProductsInProductSetResponse expectedResponse = ListProductsInProductSetResponse.newBuilder().setNextPageToken("").addAllProducts(Arrays.asList(responsesElement)).build();
    mockProductSearch.addResponse(expectedResponse);
    ProductSetName name = ProductSetName.of("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]");
    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.toString(), 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)

Example 14 with Product

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

the class ProductSearchClientTest method listReferenceImagesTest.

@Test
public void listReferenceImagesTest() throws Exception {
    ReferenceImage responsesElement = ReferenceImage.newBuilder().build();
    ListReferenceImagesResponse expectedResponse = ListReferenceImagesResponse.newBuilder().setNextPageToken("").addAllReferenceImages(Arrays.asList(responsesElement)).build();
    mockProductSearch.addResponse(expectedResponse);
    ProductName parent = ProductName.of("[PROJECT]", "[LOCATION]", "[PRODUCT]");
    ListReferenceImagesPagedResponse pagedListResponse = client.listReferenceImages(parent);
    List<ReferenceImage> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getReferenceImagesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockProductSearch.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListReferenceImagesRequest actualRequest = ((ListReferenceImagesRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListReferenceImagesPagedResponse(com.google.cloud.vision.v1.ProductSearchClient.ListReferenceImagesPagedResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 15 with Product

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

the class ProductSearchClientTest method listProductsTest2.

@Test
public void listProductsTest2() throws Exception {
    Product responsesElement = Product.newBuilder().build();
    ListProductsResponse expectedResponse = ListProductsResponse.newBuilder().setNextPageToken("").addAllProducts(Arrays.asList(responsesElement)).build();
    mockProductSearch.addResponse(expectedResponse);
    String parent = "parent-995424086";
    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, 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)

Aggregations

ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)19 Product (com.google.cloud.retail.v2.Product)14 Product (com.google.cloud.vision.v1.Product)10 Test (org.junit.Test)9 SetupCleanup.deleteProduct (setup.SetupCleanup.deleteProduct)6 ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 ProductSet (com.google.cloud.vision.v1.ProductSet)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 Assertions (org.junit.jupiter.api.Assertions)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)3