-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Added the Product Search tests and the src file updates #1196
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
Merged
nnegrey
merged 8 commits into
GoogleCloudPlatform:master
from
nirupa-kumar:vision-product-search-tests
Aug 27, 2018
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8719cf9
Adding the Product Search tests.
nirupa-kumar 6f83ab5
Fixing review issues.
nirupa-kumar f728415
Product Search tests and src file updates to include GCS image file.
nirupa-kumar eded98c
Merge branch 'master' into vision-product-search-tests
nnegrey 818eb1c
Merge branch 'master' of https://github.com/GoogleCloudPlatform/java-…
nirupa-kumar 3372088
Fixing issues after review.
nirupa-kumar 6a68881
Merge remote-tracking branch 'origin/vision-product-search-tests' int…
nirupa-kumar ab2ef41
Inc. to LLC
nirupa-kumar 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 hidden or 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
118 changes: 118 additions & 0 deletions
118
vision/product-search/cloud-client/src/test/java/com/example/vision/ProductSearchIT.java
This file contains hidden or 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,118 @@ | ||
/* | ||
* 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 java.util.List; | ||
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 ProductSearch}. */ | ||
@RunWith(JUnit4.class) | ||
@SuppressWarnings("checkstyle:abbreviationaswordinname") | ||
public class ProductSearchIT { | ||
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); | ||
private static final String COMPUTE_REGION = "us-west1"; | ||
private static final String GCS_URI = | ||
"gs://java-docs-samples-testing/product-search/indexed_product_sets.csv"; | ||
private static final String PRODUCT_SET_ID = "indexed_product_set_id_for_testing"; | ||
private static final String PRODUCT_CATEGORY = "apparel"; | ||
private static final String PRODUCT_ID_1 = "indexed_product_id_for_testing_1"; | ||
private static final String PRODUCT_ID_2 = "indexed_product_id_for_testing_2"; | ||
private static final String IMAGE_URI_1 = | ||
"gs://java-docs-samples-testing/product-search/shoes_1.jpg"; | ||
private static final String FILE_PATH_1 = "./resources/shoes_1.jpg"; | ||
private static final String FILTER = "style=womens"; | ||
private static final String BUCKET = "java-docs-samples-testing"; | ||
private ByteArrayOutputStream bout; | ||
private PrintStream out; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
|
||
bout = new ByteArrayOutputStream(); | ||
out = new PrintStream(bout); | ||
System.setOut(out); | ||
ImportProductSets.importProductSets(PROJECT_ID, COMPUTE_REGION, GCS_URI); | ||
bout.reset(); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
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 testGetSimilarProductsFile() throws Exception { | ||
// Act | ||
ProductSearch.getSimilarProductsFile( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID, PRODUCT_CATEGORY, FILE_PATH_1, ""); | ||
|
||
// Assert | ||
String got = bout.toString(); | ||
assertThat(got).contains(PRODUCT_ID_1); | ||
assertThat(got).contains(PRODUCT_ID_2); | ||
} | ||
|
||
@Test | ||
public void testGetSimilarProductsGcs() throws Exception { | ||
// Act | ||
ProductSearch.getSimilarProductsGcs( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID, PRODUCT_CATEGORY, IMAGE_URI_1, ""); | ||
|
||
// Assert | ||
String got = bout.toString(); | ||
assertThat(got).contains(PRODUCT_ID_1); | ||
assertThat(got).contains(PRODUCT_ID_2); | ||
} | ||
|
||
@Test | ||
public void testGetSimilarProductsFileWithFilter() throws Exception { | ||
// Act | ||
ProductSearch.getSimilarProductsFile( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID, PRODUCT_CATEGORY, FILE_PATH_1, FILTER); | ||
|
||
// Assert | ||
String got = bout.toString(); | ||
assertThat(got).contains(PRODUCT_ID_1); | ||
assertThat(got).doesNotContain(PRODUCT_ID_2); | ||
} | ||
|
||
@Test | ||
public void testGetSimilarProductsGcsWithFilter() throws Exception { | ||
// Act | ||
//ImportProductSets.importProductSets(PROJECT_ID, COMPUTE_REGION, GCS_URI); | ||
//bout.reset(); | ||
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. Are these comments supposed to be commented or just deleted? 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. Should be deleted. Fixing that now. |
||
ProductSearch.getSimilarProductsGcs( | ||
PROJECT_ID, COMPUTE_REGION, PRODUCT_SET_ID, PRODUCT_CATEGORY, IMAGE_URI_1, FILTER); | ||
|
||
// Assert | ||
String got = bout.toString(); | ||
assertThat(got).contains(PRODUCT_ID_1); | ||
assertThat(got).doesNotContain(PRODUCT_ID_2); | ||
} | ||
} |
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.
Add the
// [END vision_product_search_get_similar_products_gcs]