From 95c742a86f9385fe6416688f22a01a2edc12a595 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Wed, 11 Mar 2020 15:27:43 -0600 Subject: [PATCH] vision: update product search tests (#2378) * vision: update product search tests * update other broken tests --- .../vision/ProductSetManagementIT.java | 31 +++++-------------- .../ProductInProductSetManagementTests.java | 10 +++--- .../snippets/ProductManagementTests.java | 6 ++-- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/vision/product-search/cloud-client/src/test/java/com/example/vision/ProductSetManagementIT.java b/vision/product-search/cloud-client/src/test/java/com/example/vision/ProductSetManagementIT.java index 48b3325f08d..445df96938c 100644 --- a/vision/product-search/cloud-client/src/test/java/com/example/vision/ProductSetManagementIT.java +++ b/vision/product-search/cloud-client/src/test/java/com/example/vision/ProductSetManagementIT.java @@ -19,8 +19,9 @@ import static com.google.common.truth.Truth.assertThat; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.PrintStream; +import java.util.UUID; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -33,14 +34,15 @@ public class ProductSetManagementIT { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String COMPUTE_REGION = "us-west1"; - private static final String PRODUCT_SET_ID = "fake_prodt_set_id_for_testing"; + private static final String PRODUCT_SET_ID = + String.format("test_%s", UUID.randomUUID().toString()); private static final String PRODUCT_SET_DISPLAY_NAME = - "fake_prodt_set_display_name_for_testing"; + String.format("test_%s", UUID.randomUUID().toString()); private ByteArrayOutputStream bout; private PrintStream out; @Before - public void setUp() throws IOException { + public void setUp() { bout = new ByteArrayOutputStream(); out = new PrintStream(bout); System.setOut(out); @@ -48,37 +50,20 @@ public void setUp() throws IOException { @After public void tearDown() { - System.setOut(null); } @Test public void testCreateDeleteProductSet() throws Exception { - // Act - ProductSetManagement.listProductSets(PROJECT_ID, COMPUTE_REGION); - - // Assert - String got = bout.toString(); - assertThat(got).doesNotContain(PRODUCT_SET_ID); - - bout.reset(); - - // Act ProductSetManagement.createProductSet( - PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID, PRODUCT_SET_DISPLAY_NAME); - ProductSetManagement.listProductSets(PROJECT_ID, COMPUTE_REGION); - - // Assert - got = bout.toString(); + PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID, PRODUCT_SET_DISPLAY_NAME); + String got = bout.toString(); assertThat(got).contains(PRODUCT_SET_ID); bout.reset(); - // Act ProductSetManagement.deleteProductSet(PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID); ProductSetManagement.listProductSets(PROJECT_ID, COMPUTE_REGION); - - // Assert got = bout.toString(); assertThat(got).doesNotContain(PRODUCT_SET_ID); } diff --git a/vision/product-search/cloud-client/src/test/java/vision/snippets/ProductInProductSetManagementTests.java b/vision/product-search/cloud-client/src/test/java/vision/snippets/ProductInProductSetManagementTests.java index bb3b7b3f7ff..ff8aa163a8a 100644 --- a/vision/product-search/cloud-client/src/test/java/vision/snippets/ProductInProductSetManagementTests.java +++ b/vision/product-search/cloud-client/src/test/java/vision/snippets/ProductInProductSetManagementTests.java @@ -35,11 +35,13 @@ public class ProductInProductSetManagementTests { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String COMPUTE_REGION = "us-west1"; private static final String PRODUCT_SET_DISPLAY_NAME = - "fake_pdt_set_display_name_for_testing"; - private static final String PRODUCT_SET_ID = "fake_pdt_set_id_for_testing" + UUID.randomUUID(); - private static final String PRODUCT_DISPLAY_NAME = "fake_pdt_display_name_for_testing"; + String.format("test_%s", UUID.randomUUID().toString()); + private static final String PRODUCT_SET_ID = + String.format("test_%s", UUID.randomUUID().toString()); + private static final String PRODUCT_DISPLAY_NAME = + String.format("test_%s", UUID.randomUUID().toString()); private static final String PRODUCT_CATEGORY = "apparel"; - private static final String PRODUCT_ID = "fake_pdt_id_for_testing"; + private static final String PRODUCT_ID = String.format("test_%s", UUID.randomUUID().toString()); private ByteArrayOutputStream bout; private PrintStream out; diff --git a/vision/product-search/cloud-client/src/test/java/vision/snippets/ProductManagementTests.java b/vision/product-search/cloud-client/src/test/java/vision/snippets/ProductManagementTests.java index 73404ca13d3..35049f4ded0 100644 --- a/vision/product-search/cloud-client/src/test/java/vision/snippets/ProductManagementTests.java +++ b/vision/product-search/cloud-client/src/test/java/vision/snippets/ProductManagementTests.java @@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.UUID; import org.junit.After; import org.junit.Before; @@ -35,9 +36,10 @@ public class ProductManagementTests { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); private static final String COMPUTE_REGION = "us-west1"; - private static final String PRODUCT_DISPLAY_NAME = "fake_prod_display_name_for_testing"; + private static final String PRODUCT_DISPLAY_NAME = + String.format("test_%s", UUID.randomUUID().toString()); private static final String PRODUCT_CATEGORY = "homegoods"; - private static final String PRODUCT_ID = "fake_prod_id_for_testing"; + private static final String PRODUCT_ID = String.format("test_%s", UUID.randomUUID().toString()); private ByteArrayOutputStream bout; private PrintStream out;