Skip to content

Commit

Permalink
samples: Fix broken sample and add test for sample (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnegrey authored and chingor13 committed Feb 24, 2021
1 parent ab7d443 commit fd74bbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 1 addition & 3 deletions video/src/main/java/com/example/video/Detect.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,11 @@ public static void analyzeLabelsFile(String filePath) throws Exception {
// Read file and encode into Base64
Path path = Paths.get(filePath);
byte[] data = Files.readAllBytes(path);
byte[] encodedBytes = Base64.encodeBase64(data);

AnnotateVideoRequest request = AnnotateVideoRequest.newBuilder()
.setInputContent(ByteString.copyFrom(encodedBytes))
.setInputContent(ByteString.copyFrom(data))
.addFeatures(Feature.LABEL_DETECTION)
.build();

// Create an operation that will contain the response when the operation completes.
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
client.annotateVideoAsync(request);
Expand Down
14 changes: 12 additions & 2 deletions video/src/test/java/com/example/video/DetectIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class DetectIT {
private ByteArrayOutputStream bout;
private PrintStream out;

static final String LABEL_FILE_LOCATION = "gs://demomaker/cat.mp4";
static final String LABEL_GCS_LOCATION = "gs://demomaker/cat.mp4";
static final String LABEL_FILE_LOCATION = "./resources/cat.mp4";
static final String SHOTS_FILE_LOCATION = "gs://demomaker/gbikes_dinosaur.mp4";
static final String EXPLICIT_CONTENT_LOCATION = "gs://demomaker/cat.mp4";

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

@Test
public void testLabels() throws Exception {
String[] args = {"labels", LABEL_FILE_LOCATION};
String[] args = {"labels", LABEL_GCS_LOCATION};
Detect.argsHelper(args);
String got = bout.toString();
// Test that the video with a cat has the whiskers label (may change).
assertThat(got.toUpperCase()).contains("WHISKERS");
}

@Test
public void testLabelsFile() throws Exception {
String[] args = {"labels-file", LABEL_FILE_LOCATION};
Detect.argsHelper(args);
String got = bout.toString();
// Test that the video with a cat has the whiskers label (may change).
Expand Down

0 comments on commit fd74bbe

Please sign in to comment.