Skip to content

Commit 7e48fb7

Browse files
authored
Fix broken sample and add test for sample (#1216)
1 parent 633b9d6 commit 7e48fb7

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

video/cloud-client/resources/cat.mp4

6.1 MB
Binary file not shown.

video/cloud-client/src/main/java/com/example/video/Detect.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,11 @@ public static void analyzeLabelsFile(String filePath) throws Exception {
179179
// Read file and encode into Base64
180180
Path path = Paths.get(filePath);
181181
byte[] data = Files.readAllBytes(path);
182-
byte[] encodedBytes = Base64.encodeBase64(data);
183182

184183
AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
185-
.setInputContent(ByteString.copyFrom(encodedBytes))
184+
.setInputContent(ByteString.copyFrom(data))
186185
.addFeatures(Feature.LABEL_DETECTION)
187186
.build();
188-
189187
// Create an operation that will contain the response when the operation completes.
190188
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
191189
client.annotateVideoAsync(request);

video/cloud-client/src/test/java/com/example/video/DetectIT.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public class DetectIT {
3333
private ByteArrayOutputStream bout;
3434
private PrintStream out;
3535

36-
static final String LABEL_FILE_LOCATION = "gs://demomaker/cat.mp4";
36+
static final String LABEL_GCS_LOCATION = "gs://demomaker/cat.mp4";
37+
static final String LABEL_FILE_LOCATION = "./resources/cat.mp4";
3738
static final String SHOTS_FILE_LOCATION = "gs://demomaker/gbikes_dinosaur.mp4";
3839
static final String EXPLICIT_CONTENT_LOCATION = "gs://demomaker/cat.mp4";
3940

@@ -51,7 +52,16 @@ public void tearDown() {
5152

5253
@Test
5354
public void testLabels() throws Exception {
54-
String[] args = {"labels", LABEL_FILE_LOCATION};
55+
String[] args = {"labels", LABEL_GCS_LOCATION};
56+
Detect.argsHelper(args);
57+
String got = bout.toString();
58+
// Test that the video with a cat has the whiskers label (may change).
59+
assertThat(got.toUpperCase()).contains("WHISKERS");
60+
}
61+
62+
@Test
63+
public void testLabelsFile() throws Exception {
64+
String[] args = {"labels-file", LABEL_FILE_LOCATION};
5565
Detect.argsHelper(args);
5666
String got = bout.toString();
5767
// Test that the video with a cat has the whiskers label (may change).

0 commit comments

Comments
 (0)