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()));
}
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);
}
}
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());
}
}
}
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()));
}
Aggregations