-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding the Product Search tests. #1195
Merged
nnegrey
merged 2 commits into
GoogleCloudPlatform:master
from
nirupa-kumar:vision-product-search-tests
Aug 27, 2018
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
vision/product-search/cloud-client/src/test/java/com/example/vision/ImportProductSetsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright 2018 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.vision; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** Integration (system) tests for {@link ImportProductSets}. */ | ||
@RunWith(JUnit4.class) | ||
@SuppressWarnings("checkstyle:abbreviationaswordinname") | ||
public class ImportProductSetsIT { | ||
private static final String PROJECT_ID = "java-docs-samples-testing"; | ||
private static final String COMPUTE_REGION = "us-west1"; | ||
private static final String GCS_URI = | ||
"gs://java-docs-samples-testing/product-search/product_sets.csv"; | ||
private static final String PRODUCT_SET_ID = "fake_product_set_id_for_testing"; | ||
private static final String PRODUCT_ID_1 = "fake_product_id_for_testing_1"; | ||
private static final String PRODUCT_ID_2 = "fake_product_id_for_testing_2"; | ||
private static final String IMAGE_URI_1 = "shoes_1.jpg"; | ||
private static final String IMAGE_URI_2 = "shoes_2.jpg"; | ||
private ByteArrayOutputStream bout; | ||
private PrintStream out; | ||
|
||
@Before | ||
public void setUp() { | ||
bout = new ByteArrayOutputStream(); | ||
out = new PrintStream(bout); | ||
System.setOut(out); | ||
} | ||
|
||
@After | ||
public void tearDown() throws IOException { | ||
ProductManagement.deleteProduct(PROJECT_ID,COMPUTE_REGION,PRODUCT_ID_1); | ||
ProductManagement.deleteProduct(PROJECT_ID,COMPUTE_REGION,PRODUCT_ID_2); | ||
ProductSetManagement.deleteProductSet(PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID); | ||
System.setOut(null); | ||
} | ||
|
||
@Test | ||
public void testImportProductSets() throws Exception { | ||
// Act | ||
ProductSetManagement.listProductSets(PROJECT_ID, COMPUTE_REGION); | ||
|
||
// Assert | ||
String got = bout.toString(); | ||
assertThat(got).doesNotContain(PRODUCT_SET_ID); | ||
|
||
// Act | ||
ProductManagement.listProducts(PROJECT_ID, COMPUTE_REGION); | ||
|
||
// Assert | ||
assertThat(got).doesNotContain(PRODUCT_ID_1); | ||
assertThat(got).doesNotContain(PRODUCT_ID_2); | ||
|
||
// Act | ||
ProductInProductSetManagement.listProductsInProductSet( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID); | ||
|
||
// Assert | ||
assertThat(got).doesNotContain(PRODUCT_ID_1); | ||
assertThat(got).doesNotContain(PRODUCT_ID_2); | ||
|
||
// Act | ||
ReferenceImageManagement.listReferenceImagesOfProduct(PROJECT_ID, COMPUTE_REGION, PRODUCT_ID_1); | ||
|
||
// Assert | ||
assertThat(got).doesNotContain(IMAGE_URI_1); | ||
|
||
// Act | ||
ReferenceImageManagement.listReferenceImagesOfProduct(PROJECT_ID, COMPUTE_REGION, PRODUCT_ID_2); | ||
|
||
// Assert | ||
assertThat(got).doesNotContain(IMAGE_URI_2); | ||
|
||
// Act | ||
ImportProductSets.importProductSets(PROJECT_ID, COMPUTE_REGION, GCS_URI); | ||
ProductSetManagement.listProductSets(PROJECT_ID, COMPUTE_REGION); | ||
|
||
// Assert | ||
got = bout.toString(); | ||
assertThat(got).contains(PRODUCT_SET_ID); | ||
|
||
// Act | ||
ProductManagement.listProducts(PROJECT_ID, COMPUTE_REGION); | ||
|
||
// Assert | ||
assertThat(got).contains(PRODUCT_ID_1); | ||
assertThat(got).contains(PRODUCT_ID_2); | ||
|
||
// Act | ||
ProductInProductSetManagement.listProductsInProductSet( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID); | ||
|
||
// Assert | ||
assertThat(got).contains(PRODUCT_ID_1); | ||
assertThat(got).contains(PRODUCT_ID_2); | ||
|
||
// Act | ||
ReferenceImageManagement.listReferenceImagesOfProduct(PROJECT_ID, COMPUTE_REGION, PRODUCT_ID_1); | ||
|
||
// Assert | ||
assertThat(got).contains(IMAGE_URI_1); | ||
|
||
// Act | ||
ReferenceImageManagement.listReferenceImagesOfProduct(PROJECT_ID, COMPUTE_REGION, PRODUCT_ID_2); | ||
|
||
// Assert | ||
assertThat(got).contains(IMAGE_URI_2); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
...search/cloud-client/src/test/java/com/example/vision/ProductInProductSetManagementIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright 2018 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.vision; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** Integration (system) tests for {@link ProductInProductSetManagement}. */ | ||
@RunWith(JUnit4.class) | ||
@SuppressWarnings("checkstyle:abbreviationaswordinname") | ||
public class ProductInProductSetManagementIT { | ||
private static final String PROJECT_ID = "java-docs-samples-testing"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
private static final String COMPUTE_REGION = "us-west1"; | ||
private static final String PRODUCT_SET_DISPLAY_NAME = | ||
"fake_product_set_display_name_for_testing"; | ||
private static final String PRODUCT_SET_ID = "fake_product_set_id_for_testing"; | ||
private static final String PRODUCT_DISPLAY_NAME = "fake_product_display_name_for_testing"; | ||
private static final String PRODUCT_CATEGORY = "apparel"; | ||
private static final String PRODUCT_ID = "fake_product_id_for_testing"; | ||
private ByteArrayOutputStream bout; | ||
private PrintStream out; | ||
|
||
@Before | ||
public void setUp() throws IOException { | ||
bout = new ByteArrayOutputStream(); | ||
out = new PrintStream(bout); | ||
System.setOut(out); | ||
ProductSetManagement.createProductSet( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID, PRODUCT_SET_DISPLAY_NAME); | ||
ProductManagement.createProduct( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_ID, PRODUCT_DISPLAY_NAME, PRODUCT_CATEGORY); | ||
bout.reset(); | ||
} | ||
|
||
@After | ||
public void tearDown() throws IOException { | ||
ProductManagement.deleteProduct(PROJECT_ID, COMPUTE_REGION, PRODUCT_ID); | ||
ProductSetManagement.deleteProductSet(PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID); | ||
System.setOut(null); | ||
} | ||
|
||
@Test | ||
public void testAddProductToProductSet() throws Exception { | ||
// Act | ||
ProductInProductSetManagement.listProductsInProductSet( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID); | ||
|
||
// Assert | ||
String got = bout.toString(); | ||
assertThat(got).doesNotContain(PRODUCT_ID); | ||
|
||
bout.reset(); | ||
|
||
// Act | ||
ProductInProductSetManagement.addProductToProductSet( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_ID, PRODUCT_SET_ID); | ||
|
||
// Assert | ||
got = bout.toString(); | ||
assertThat(got).contains("Product added to product set."); | ||
} | ||
|
||
@Test | ||
public void testRemoveProductFromProductSet() throws Exception { | ||
// Act | ||
ProductInProductSetManagement.addProductToProductSet( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_ID, PRODUCT_SET_ID); | ||
ProductInProductSetManagement.listProductsInProductSet( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID); | ||
|
||
// Assert | ||
String got = bout.toString(); | ||
assertThat(got).contains(PRODUCT_ID); | ||
|
||
bout.reset(); | ||
|
||
// Act | ||
ProductInProductSetManagement.removeProductFromProductSet( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_ID, PRODUCT_SET_ID); | ||
ProductInProductSetManagement.listProductsInProductSet( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID); | ||
|
||
// Assert | ||
got = bout.toString(); | ||
assertThat(got).doesNotContain(PRODUCT_ID); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch "java-docs-samples-testing" to
System.getenv("GOOGLE_CLOUD_PROJECT");