Search in sources :

Example 1 with ListProductsRequest

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

the class ProductServiceClientTest method listProductsTest2.

@Test
public void listProductsTest2() throws Exception {
    Product responsesElement = Product.newBuilder().build();
    ListProductsResponse expectedResponse = ListProductsResponse.newBuilder().setNextPageToken("").addAllProducts(Arrays.asList(responsesElement)).build();
    mockProductService.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 = mockProductService.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.retail.v2.ProductServiceClient.ListProductsPagedResponse) Test(org.junit.Test)

Example 2 with ListProductsRequest

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

the class RemoveTestResources method deleteAllProducts.

public static void deleteAllProducts() throws IOException {
    System.out.println("Deleting products in process, please wait...");
    try (ProductServiceClient productServiceClient = ProductServiceClient.create()) {
        ListProductsRequest listRequest = ListProductsRequest.newBuilder().setParent(DEFAULT_CATALOG).build();
        ListProductsPagedResponse products = productServiceClient.listProducts(listRequest);
        int deleteCount = 0;
        for (Product product : products.iterateAll()) {
            DeleteProductRequest deleteRequest = DeleteProductRequest.newBuilder().setName(product.getName()).build();
            try {
                productServiceClient.deleteProduct(deleteRequest);
                deleteCount++;
            } catch (PermissionDeniedException e) {
                System.out.println("Ignore PermissionDenied in case the product does not exist " + "at time of deletion.");
            }
        }
        System.out.printf("%s products were deleted from %s%n", deleteCount, DEFAULT_CATALOG);
    }
}
Also used : DeleteProductRequest(com.google.cloud.retail.v2.DeleteProductRequest) ListProductsRequest(com.google.cloud.retail.v2.ListProductsRequest) ProductServiceClient(com.google.cloud.retail.v2.ProductServiceClient) Product(com.google.cloud.retail.v2.Product) PermissionDeniedException(com.google.api.gax.rpc.PermissionDeniedException) ListProductsPagedResponse(com.google.cloud.retail.v2.ProductServiceClient.ListProductsPagedResponse)

Example 3 with ListProductsRequest

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

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

the class ProductServiceClientTest method listProductsTest.

@Test
public void listProductsTest() throws Exception {
    Product responsesElement = Product.newBuilder().build();
    ListProductsResponse expectedResponse = ListProductsResponse.newBuilder().setNextPageToken("").addAllProducts(Arrays.asList(responsesElement)).build();
    mockProductService.addResponse(expectedResponse);
    BranchName parent = BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]");
    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 = mockProductService.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.retail.v2.ProductServiceClient.ListProductsPagedResponse) Test(org.junit.Test)

Aggregations

ListProductsPagedResponse (com.google.cloud.retail.v2.ProductServiceClient.ListProductsPagedResponse)3 Test (org.junit.Test)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 PermissionDeniedException (com.google.api.gax.rpc.PermissionDeniedException)1 DeleteProductRequest (com.google.cloud.retail.v2.DeleteProductRequest)1 ListProductsRequest (com.google.cloud.retail.v2.ListProductsRequest)1 Product (com.google.cloud.retail.v2.Product)1 ProductServiceClient (com.google.cloud.retail.v2.ProductServiceClient)1 ListProductsRequest (com.google.cloud.vision.v1.ListProductsRequest)1 Product (com.google.cloud.vision.v1.Product)1