GCloudVisionUtil { public static String getAnnotateImagePayload(FileEntry fileEntry) throws Exception { FileVersion fileVersion = fileEntry.getFileVersion(); JSONObject jsonObject = JSONUtil.put( "requests", JSONUtil.put( JSONUtil.put( "features", JSONUtil.put(JSONUtil.put("type", "LABEL_DETECTION")) ).put( "image", JSONUtil.put( "content", Base64.encode( FileUtil.getBytes( fileVersion.getContentStream(false)))) ))); return jsonObject.toString(); }  static String getAnnotateImagePayload(FileEntry fileEntry);  }
@Test public void testGetAnnotateImagePayload() throws Exception { Mockito.when( _fileEntry.getFileVersion() ).thenReturn( _fileVersion ); String randomString = RandomTestUtil.randomString(); Mockito.when( _fileVersion.getContentStream(false) ).thenReturn( new ByteArrayInputStream(randomString.getBytes()) ); Assert.assertEquals( StringBundler.concat( "{\"requests\":[{\"features\":", "[{\"type\":\"LABEL_DETECTION\"}],\"image\":{\"content\":\"", Base64.encode(randomString.getBytes()), "\"}}]}"), GCloudVisionUtil.getAnnotateImagePayload(_fileEntry)); }