Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class ITSystemTest {
private static final String GCS_BUCKET_ENV_VAR = "GOOGLE_CLOUD_TESTS_VISION_BUCKET";
private static final String SAMPLE_BUCKET;
private static final String SAMPLE_URI;
private static final int MAX_RESULTS = 15;

static {
String GCS_BUCKET;
Expand Down Expand Up @@ -465,8 +466,18 @@ public void detectSafeSearchGcsTest() throws IOException {

@Test
public void detectWebEntitiesGcsTest() throws IOException {
List<AnnotateImageResponse> responses =
getResponsesList("landmark/pofa.jpg", Type.WEB_DETECTION, true);
ImageSource imgSource =
ImageSource.newBuilder().setGcsImageUri(SAMPLE_BUCKET + "landmark/pofa.jpg").build();
Image img = Image.newBuilder().setSource(imgSource).build();
Feature feat =
Feature.newBuilder().setType(Type.WEB_DETECTION).setMaxResults(MAX_RESULTS).build();

AnnotateImageRequest request =
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();

BatchAnnotateImagesResponse response =
imageAnnotatorClient.batchAnnotateImages(ImmutableList.of(request));
List<AnnotateImageResponse> responses = response.getResponsesList();
List<String> actual = new ArrayList<>();
for (AnnotateImageResponse imgResponse : responses) {
for (WebDetection.WebEntity entity : imgResponse.getWebDetection().getWebEntitiesList()) {
Expand All @@ -480,7 +491,8 @@ public void detectWebEntitiesGcsTest() throws IOException {
public void detectWebEntitiesIncludeGeoResultsTest() throws IOException {
ByteString imgBytes = ByteString.readFrom(new FileInputStream(RESOURCES + "city.jpg"));
Image img = Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Type.WEB_DETECTION).build();
Feature feat =
Feature.newBuilder().setType(Type.WEB_DETECTION).setMaxResults(MAX_RESULTS).build();
WebDetectionParams webDetectionParams =
WebDetectionParams.newBuilder().setIncludeGeoResults(true).build();
ImageContext imageContext =
Expand Down Expand Up @@ -511,7 +523,8 @@ public void detectWebEntitiesIncludeGeoResultsGcsTest() {
ImageSource imgSource =
ImageSource.newBuilder().setGcsImageUri(SAMPLE_BUCKET + "landmark/pofa.jpg").build();
Image img = Image.newBuilder().setSource(imgSource).build();
Feature feat = Feature.newBuilder().setType(Type.WEB_DETECTION).build();
Feature feat =
Feature.newBuilder().setType(Type.WEB_DETECTION).setMaxResults(MAX_RESULTS).build();
WebDetectionParams webDetectionParams =
WebDetectionParams.newBuilder().setIncludeGeoResults(true).build();
ImageContext imageContext =
Expand All @@ -526,6 +539,8 @@ public void detectWebEntitiesIncludeGeoResultsGcsTest() {
imageAnnotatorClient.batchAnnotateImages(ImmutableList.of(request));
List<AnnotateImageResponse> responses = response.getResponsesList();
List<String> actual = new ArrayList<>();
System.out.println("WebEntitiesGeo SIZE");
System.out.println(actual.size());
for (AnnotateImageResponse imgResponse : responses) {
for (WebDetection.WebEntity entity : imgResponse.getWebDetection().getWebEntitiesList()) {
actual.add(entity.getDescription());
Expand Down