From 6c3bf8dcb50ec54a7e16f75878a27c6fc4c1860b Mon Sep 17 00:00:00 2001 From: Nick Cook Date: Fri, 12 Jul 2024 14:00:27 -0700 Subject: [PATCH 1/7] feat: add VOD config samples and tests --- media/stitcher/pom.xml | 2 +- .../com/example/stitcher/CreateVodConfig.java | 72 ++++++++++++++ .../example/stitcher/CreateVodSession.java | 18 ++-- .../com/example/stitcher/DeleteVodConfig.java | 60 ++++++++++++ .../com/example/stitcher/GetVodConfig.java | 55 +++++++++++ .../com/example/stitcher/ListVodConfigs.java | 58 +++++++++++ .../com/example/stitcher/UpdateVodConfig.java | 74 ++++++++++++++ .../example/stitcher/CreateVodConfigTest.java | 89 +++++++++++++++++ .../stitcher/CreateVodSessionTest.java | 20 ++-- .../example/stitcher/DeleteVodConfigTest.java | 86 +++++++++++++++++ .../stitcher/GetVodAdTagDetailTest.java | 43 ++++++--- .../example/stitcher/GetVodConfigTest.java | 93 ++++++++++++++++++ .../example/stitcher/GetVodSessionTest.java | 36 +++++-- .../stitcher/GetVodStitchDetailTest.java | 43 ++++++--- .../stitcher/ListVodAdTagDetailsTest.java | 40 +++++--- .../example/stitcher/ListVodConfigsTest.java | 93 ++++++++++++++++++ .../stitcher/ListVodStitchDetailsTest.java | 40 +++++--- .../java/com/example/stitcher/TestUtils.java | 46 ++++++++- .../example/stitcher/UpdateVodConfigTest.java | 96 +++++++++++++++++++ 19 files changed, 986 insertions(+), 78 deletions(-) create mode 100644 media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java create mode 100644 media/stitcher/src/main/java/com/example/stitcher/DeleteVodConfig.java create mode 100644 media/stitcher/src/main/java/com/example/stitcher/GetVodConfig.java create mode 100644 media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java create mode 100644 media/stitcher/src/main/java/com/example/stitcher/UpdateVodConfig.java create mode 100644 media/stitcher/src/test/java/com/example/stitcher/CreateVodConfigTest.java create mode 100644 media/stitcher/src/test/java/com/example/stitcher/DeleteVodConfigTest.java create mode 100644 media/stitcher/src/test/java/com/example/stitcher/GetVodConfigTest.java create mode 100644 media/stitcher/src/test/java/com/example/stitcher/ListVodConfigsTest.java create mode 100644 media/stitcher/src/test/java/com/example/stitcher/UpdateVodConfigTest.java diff --git a/media/stitcher/pom.xml b/media/stitcher/pom.xml index 61c88e4baeb..6d6d5ee0f6b 100644 --- a/media/stitcher/pom.xml +++ b/media/stitcher/pom.xml @@ -42,7 +42,7 @@ com.google.cloud libraries-bom - 26.32.0 + 26.42.0 pom import diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java b/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java new file mode 100644 index 00000000000..a7e135db8a3 --- /dev/null +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java @@ -0,0 +1,72 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +// [START videostitcher_create_vod_config] + +import com.google.cloud.video.stitcher.v1.CreateVodConfigRequest; +import com.google.cloud.video.stitcher.v1.LocationName; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VodConfig; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class CreateVodConfig { + + private static final int TIMEOUT_IN_MINUTES = 2; + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String location = "us-central1"; + String vodConfigId = "my-vod-config-id"; + // URI of the VOD stream to stitch; this URI must reference either an MPEG-DASH + // manifest (.mpd) file or an M3U playlist manifest (.m3u8) file. + String sourceUri = "https://storage.googleapis.com/my-bucket/main.mpd"; + // See VMAP Pre-roll + // (https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/tags) + String adTagUri = "https://pubads.g.doubleclick.net/gampad/ads..."; + + createVodConfig(projectId, location, vodConfigId, sourceUri, adTagUri); + } + + public static void createVodConfig( + String projectId, String location, String vodConfigId, String sourceUri, String adTagUri) + throws IOException, ExecutionException, InterruptedException, TimeoutException { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create(); + CreateVodConfigRequest createVodConfigRequest = + CreateVodConfigRequest.newBuilder() + .setParent(LocationName.of(projectId, location).toString()) + .setVodConfigId(vodConfigId) + .setVodConfig( + VodConfig.newBuilder().setSourceUri(sourceUri).setAdTagUri(adTagUri).build()) + .build(); + + VodConfig response = + videoStitcherServiceClient + .createVodConfigAsync(createVodConfigRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Created new VOD config: " + response.getName()); + videoStitcherServiceClient.close(); + } +} +// [END videostitcher_create_vod_config] diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateVodSession.java b/media/stitcher/src/main/java/com/example/stitcher/CreateVodSession.java index 0e96d2b1dcf..1956e1a9033 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateVodSession.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateVodSession.java @@ -22,6 +22,7 @@ import com.google.cloud.video.stitcher.v1.CreateVodSessionRequest; import com.google.cloud.video.stitcher.v1.LocationName; import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VodConfigName; import com.google.cloud.video.stitcher.v1.VodSession; import java.io.IOException; @@ -31,17 +32,13 @@ public static void main(String[] args) throws Exception { // TODO(developer): Replace these variables before running the sample. String projectId = "my-project-id"; String location = "us-central1"; - // Uri of the media to stitch; this URI must reference either an MPEG-DASH - // manifest (.mpd) file or an M3U playlist manifest (.m3u8) file. - String sourceUri = "https://storage.googleapis.com/my-bucket/main.mpd"; - // See VMAP Pre-roll - // (https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/tags) - String adTagUri = "https://pubads.g.doubleclick.net/gampad/ads..."; - createVodSession(projectId, location, sourceUri, adTagUri); + String vodConfigId = "my-vod-config-id"; + + createVodSession(projectId, location, vodConfigId); } - public static void createVodSession( - String projectId, String location, String sourceUri, String adTagUri) throws IOException { + public static void createVodSession(String projectId, String location, String vodConfigId) + throws IOException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. In this example, try-with-resources is used // which automatically calls close() on the client to clean up resources. @@ -52,8 +49,7 @@ public static void createVodSession( .setParent(LocationName.of(projectId, location).toString()) .setVodSession( VodSession.newBuilder() - .setSourceUri(sourceUri) - .setAdTagUri(adTagUri) + .setVodConfig(VodConfigName.format(projectId, location, vodConfigId)) .setAdTracking(AdTracking.SERVER) .build()) .build(); diff --git a/media/stitcher/src/main/java/com/example/stitcher/DeleteVodConfig.java b/media/stitcher/src/main/java/com/example/stitcher/DeleteVodConfig.java new file mode 100644 index 00000000000..0c49987e95d --- /dev/null +++ b/media/stitcher/src/main/java/com/example/stitcher/DeleteVodConfig.java @@ -0,0 +1,60 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +// [START videostitcher_delete_vod_config] + +import com.google.cloud.video.stitcher.v1.DeleteVodConfigRequest; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VodConfigName; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class DeleteVodConfig { + + private static final int TIMEOUT_IN_MINUTES = 2; + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String location = "us-central1"; + String vodConfigId = "my-vod-config-id"; + + deleteVodConfig(projectId, location, vodConfigId); + } + + public static void deleteVodConfig(String projectId, String location, String vodConfigId) + throws IOException, ExecutionException, InterruptedException, TimeoutException { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create(); + DeleteVodConfigRequest deleteVodConfigRequest = + DeleteVodConfigRequest.newBuilder() + .setName(VodConfigName.of(projectId, location, vodConfigId).toString()) + .build(); + + videoStitcherServiceClient + .deleteVodConfigAsync(deleteVodConfigRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Deleted VOD config"); + videoStitcherServiceClient.close(); + } +} +// [END videostitcher_delete_vod_config] diff --git a/media/stitcher/src/main/java/com/example/stitcher/GetVodConfig.java b/media/stitcher/src/main/java/com/example/stitcher/GetVodConfig.java new file mode 100644 index 00000000000..19659f2de01 --- /dev/null +++ b/media/stitcher/src/main/java/com/example/stitcher/GetVodConfig.java @@ -0,0 +1,55 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +// [START videostitcher_get_vod_config] + +import com.google.cloud.video.stitcher.v1.GetVodConfigRequest; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VodConfig; +import com.google.cloud.video.stitcher.v1.VodConfigName; +import java.io.IOException; + +public class GetVodConfig { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String location = "us-central1"; + String vodConfigId = "my-vod-config-id"; + + getVodConfig(projectId, location, vodConfigId); + } + + public static void getVodConfig(String projectId, String location, String vodConfigId) + throws IOException { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. In this example, try-with-resources is used + // which automatically calls close() on the client to clean up resources. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + GetVodConfigRequest getVodConfigRequest = + GetVodConfigRequest.newBuilder() + .setName(VodConfigName.of(projectId, location, vodConfigId).toString()) + .build(); + + VodConfig response = videoStitcherServiceClient.getVodConfig(getVodConfigRequest); + System.out.println("VOD config: " + response.getName()); + } + } +} +// [END videostitcher_get_vod_config] diff --git a/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java b/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java new file mode 100644 index 00000000000..5ed0175a8d2 --- /dev/null +++ b/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java @@ -0,0 +1,58 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +// [START videostitcher_list_vod_configs] + +import com.google.cloud.video.stitcher.v1.ListVodConfigsRequest; +import com.google.cloud.video.stitcher.v1.LocationName; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VodConfig; +import java.io.IOException; + +public class ListVodConfigs { + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String location = "us-central1"; + + listVodConfigs(projectId, location); + } + + public static void listVodConfigs(String projectId, String location) throws IOException { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. In this example, try-with-resources is used + // which automatically calls close() on the client to clean up resources. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + ListVodConfigsRequest listVodConfigsRequest = + ListVodConfigsRequest.newBuilder() + .setParent(LocationName.of(projectId, location).toString()) + .build(); + + VideoStitcherServiceClient.ListVodConfigsPagedResponse response = + videoStitcherServiceClient.listVodConfigs(listVodConfigsRequest); + System.out.println("VOD configs:"); + + for (VodConfig vodConfig : response.iterateAll()) { + System.out.println(vodConfig.getName()); + } + } + } +} +// [END videostitcher_list_vod_configs] diff --git a/media/stitcher/src/main/java/com/example/stitcher/UpdateVodConfig.java b/media/stitcher/src/main/java/com/example/stitcher/UpdateVodConfig.java new file mode 100644 index 00000000000..45cc31c0ee1 --- /dev/null +++ b/media/stitcher/src/main/java/com/example/stitcher/UpdateVodConfig.java @@ -0,0 +1,74 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +// [START videostitcher_update_vod_config] + +import com.google.cloud.video.stitcher.v1.UpdateVodConfigRequest; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VodConfig; +import com.google.cloud.video.stitcher.v1.VodConfigName; +import com.google.protobuf.FieldMask; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class UpdateVodConfig { + + private static final int TIMEOUT_IN_MINUTES = 2; + + public static void main(String[] args) throws Exception { + // TODO(developer): Replace these variables before running the sample. + String projectId = "my-project-id"; + String location = "us-central1"; + String vodConfigId = "my-vod-config-id"; + // Updated URI of the VOD stream to stitch; this URI must reference either an MPEG-DASH + // manifest (.mpd) file or an M3U playlist manifest (.m3u8) file. + String sourceUri = "https://storage.googleapis.com/my-bucket/main.mpd"; + + updateVodConfig(projectId, location, vodConfigId, sourceUri); + } + + public static void updateVodConfig( + String projectId, String location, String vodConfigId, String sourceUri) + throws IOException, ExecutionException, InterruptedException, TimeoutException { + // Initialize client that will be used to send requests. This client only needs to be created + // once, and can be reused for multiple requests. After completing all of your requests, call + // the "close" method on the client to safely clean up any remaining background resources. + VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create(); + UpdateVodConfigRequest updateVodConfigRequest = + UpdateVodConfigRequest.newBuilder() + .setVodConfig( + VodConfig.newBuilder() + .setName(VodConfigName.of(projectId, location, vodConfigId).toString()) + .setSourceUri(sourceUri) + .build()) + // Set the update mask to the sourceUri field in the existing VOD config. You must set + // the mask to the field you want to update. + .setUpdateMask(FieldMask.newBuilder().addPaths("sourceUri").build()) + .build(); + + VodConfig response = + videoStitcherServiceClient + .updateVodConfigAsync(updateVodConfigRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Updated VOD config: " + response.getName()); + videoStitcherServiceClient.close(); + } +} +// [END videostitcher_update_vod_config] diff --git a/media/stitcher/src/test/java/com/example/stitcher/CreateVodConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/CreateVodConfigTest.java new file mode 100644 index 00000000000..3580fa647c5 --- /dev/null +++ b/media/stitcher/src/test/java/com/example/stitcher/CreateVodConfigTest.java @@ -0,0 +1,89 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class CreateVodConfigTest { + + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); + private static String PROJECT_ID; + private static String VOD_CONFIG_NAME; + private static PrintStream originalOut; + private ByteArrayOutputStream bout; + + private static String requireEnvVar(String varName) { + String varValue = System.getenv(varName); + assertNotNull( + String.format("Environment variable '%s' is required to perform these tests.", varName)); + return varValue; + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); + originalOut = System.out; + bout = new ByteArrayOutputStream(); + System.setOut(new PrintStream(bout)); + + VOD_CONFIG_NAME = String.format("locations/%s/vodConfigs/", TestUtils.LOCATION); + bout.reset(); + } + + @Test + public void test_CreateVodConfig() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); + String output = bout.toString(); + assertThat(output, containsString(VOD_CONFIG_NAME)); + bout.reset(); + } + + @After + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + System.setOut(originalOut); + bout.reset(); + } +} diff --git a/media/stitcher/src/test/java/com/example/stitcher/CreateVodSessionTest.java b/media/stitcher/src/test/java/com/example/stitcher/CreateVodSessionTest.java index a44a6748ae1..7b056264aef 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/CreateVodSessionTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/CreateVodSessionTest.java @@ -24,6 +24,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -35,8 +37,8 @@ @RunWith(JUnit4.class) public class CreateVodSessionTest { - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); private static String PROJECT_ID; private static String SESSION_NAME; private static PrintStream originalOut; @@ -56,26 +58,32 @@ public static void checkRequirements() { } @Before - public void beforeTest() throws IOException { + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); + // Project number is always returned in the VOD session name SESSION_NAME = String.format("locations/%s/vodSessions/", TestUtils.LOCATION); + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); bout.reset(); } @Test public void test_CreateVodSession() throws IOException { - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, TestUtils.VOD_URI, - TestUtils.VOD_AD_TAG_URI); + CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); String output = bout.toString(); assertThat(output, containsString(SESSION_NAME)); bout.reset(); } @After - public void tearDown() throws IOException { + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); // No delete method for a VOD session System.setOut(originalOut); bout.reset(); diff --git a/media/stitcher/src/test/java/com/example/stitcher/DeleteVodConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/DeleteVodConfigTest.java new file mode 100644 index 00000000000..14a2f5e5645 --- /dev/null +++ b/media/stitcher/src/test/java/com/example/stitcher/DeleteVodConfigTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class DeleteVodConfigTest { + + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); + private static String PROJECT_ID; + private static PrintStream originalOut; + private ByteArrayOutputStream bout; + + private static String requireEnvVar(String varName) { + String varValue = System.getenv(varName); + assertNotNull( + String.format("Environment variable '%s' is required to perform these tests.", varName)); + return varValue; + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); + originalOut = System.out; + bout = new ByteArrayOutputStream(); + System.setOut(new PrintStream(bout)); + + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); + bout.reset(); + } + + @Test + public void test_DeleteVodConfig() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + String output = bout.toString(); + assertThat(output, containsString("Deleted VOD config")); + bout.reset(); + } + + @After + public void tearDown() throws IOException { + System.setOut(originalOut); + bout.reset(); + } +} diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetVodAdTagDetailTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetVodAdTagDetailTest.java index 95227816fc5..5f8078acd4a 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/GetVodAdTagDetailTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/GetVodAdTagDetailTest.java @@ -24,6 +24,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.junit.After; @@ -37,8 +39,8 @@ @RunWith(JUnit4.class) public class GetVodAdTagDetailTest { - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); private static String PROJECT_ID; private static String SESSION_ID; private static String AD_TAG_DETAIL_ID; @@ -60,22 +62,33 @@ public static void checkRequirements() { } @Before - public void beforeTest() throws IOException { + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, TestUtils.VOD_URI, - TestUtils.VOD_AD_TAG_URI); - String output = bout.toString(); - String[] arr = output.split("/"); - SESSION_ID = arr[arr.length - 1].replace("\n", ""); - String sessionName = String.format("locations/%s/vodSessions/%s/", TestUtils.LOCATION, - SESSION_ID); + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); bout.reset(); - ListVodAdTagDetails.listVodAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); Matcher idMatcher = + Pattern.compile( + String.format( + "Created VOD session: projects/.*/locations/%s/vodSessions/(.*)", + TestUtils.LOCATION)) + .matcher(bout.toString()); + if (idMatcher.find()) { + SESSION_ID = idMatcher.group(1); + } + String sessionName = + String.format("locations/%s/vodSessions/%s/", TestUtils.LOCATION, SESSION_ID); + bout.reset(); + + ListVodAdTagDetails.listVodAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + idMatcher = Pattern.compile("name: \"projects/.*/" + sessionName + "vodAdTagDetails/(.*)\"") .matcher(bout.toString()); if (idMatcher.find()) { @@ -87,15 +100,17 @@ public void beforeTest() throws IOException { @Test public void test_GetVodAdTagDetailTest() throws IOException { - GetVodAdTagDetail.getVodAdTagDetail(PROJECT_ID, TestUtils.LOCATION, SESSION_ID, - AD_TAG_DETAIL_ID); + GetVodAdTagDetail.getVodAdTagDetail( + PROJECT_ID, TestUtils.LOCATION, SESSION_ID, AD_TAG_DETAIL_ID); String output = bout.toString(); assertThat(output, containsString(AD_TAG_DETAIL_NAME)); bout.reset(); } @After - public void tearDown() throws IOException { + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); // No delete method for a VOD session System.setOut(originalOut); bout.reset(); diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetVodConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetVodConfigTest.java new file mode 100644 index 00000000000..3b9406fb945 --- /dev/null +++ b/media/stitcher/src/test/java/com/example/stitcher/GetVodConfigTest.java @@ -0,0 +1,93 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class GetVodConfigTest { + + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); + + private static String PROJECT_ID; + private static String VOD_CONFIG_NAME; + private static PrintStream originalOut; + private ByteArrayOutputStream bout; + + private static String requireEnvVar(String varName) { + String varValue = System.getenv(varName); + assertNotNull( + String.format("Environment variable '%s' is required to perform these tests.", varName)); + return varValue; + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); + originalOut = System.out; + bout = new ByteArrayOutputStream(); + System.setOut(new PrintStream(bout)); + + VOD_CONFIG_NAME = + String.format( + "projects/%s/locations/%s/vodConfigs/%s", + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); + bout.reset(); + } + + @Test + public void test_GetVodConfig() throws IOException { + GetVodConfig.getVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + String output = bout.toString(); + assertThat(output, containsString(VOD_CONFIG_NAME)); + bout.reset(); + } + + @After + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + System.setOut(originalOut); + bout.reset(); + } +} diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetVodSessionTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetVodSessionTest.java index 8124805b7f7..414ee41b6fa 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/GetVodSessionTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/GetVodSessionTest.java @@ -24,6 +24,10 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -35,8 +39,8 @@ @RunWith(JUnit4.class) public class GetVodSessionTest { - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); private static String PROJECT_ID; private static String SESSION_ID; private static String SESSION_NAME; @@ -57,16 +61,28 @@ public static void checkRequirements() { } @Before - public void beforeTest() throws IOException { + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, TestUtils.VOD_URI, - TestUtils.VOD_AD_TAG_URI); - String output = bout.toString(); - String[] arr = output.split("/"); - SESSION_ID = arr[arr.length - 1].replace("\n", ""); + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); + bout.reset(); + + CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + Matcher idMatcher = + Pattern.compile( + String.format( + "Created VOD session: projects/.*/locations/%s/vodSessions/(.*)", + TestUtils.LOCATION)) + .matcher(bout.toString()); + if (idMatcher.find()) { + SESSION_ID = idMatcher.group(1); + } + // Project number is always returned in the VOD session name SESSION_NAME = String.format("locations/%s/vodSessions/%s", TestUtils.LOCATION, SESSION_ID); bout.reset(); } @@ -80,7 +96,9 @@ public void test_GetVodSession() throws IOException { } @After - public void tearDown() throws IOException { + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); // No delete method for a VOD session System.setOut(originalOut); bout.reset(); diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetVodStitchDetailTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetVodStitchDetailTest.java index 7bf52e05f47..4e2a1776606 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/GetVodStitchDetailTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/GetVodStitchDetailTest.java @@ -24,6 +24,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.junit.After; @@ -37,8 +39,8 @@ @RunWith(JUnit4.class) public class GetVodStitchDetailTest { - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); private static String PROJECT_ID; private static String SESSION_ID; private static String STITCH_DETAIL_ID; @@ -60,22 +62,33 @@ public static void checkRequirements() { } @Before - public void beforeTest() throws IOException { + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, TestUtils.VOD_URI, - TestUtils.VOD_AD_TAG_URI); - String output = bout.toString(); - String[] arr = output.split("/"); - SESSION_ID = arr[arr.length - 1].replace("\n", ""); - String sessionName = String.format("locations/%s/vodSessions/%s/", TestUtils.LOCATION, - SESSION_ID); + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); bout.reset(); - ListVodStitchDetails.listVodStitchDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); Matcher idMatcher = + Pattern.compile( + String.format( + "Created VOD session: projects/.*/locations/%s/vodSessions/(.*)", + TestUtils.LOCATION)) + .matcher(bout.toString()); + if (idMatcher.find()) { + SESSION_ID = idMatcher.group(1); + } + String sessionName = + String.format("locations/%s/vodSessions/%s/", TestUtils.LOCATION, SESSION_ID); + bout.reset(); + + ListVodStitchDetails.listVodStitchDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + idMatcher = Pattern.compile("name: \"projects/.*/" + sessionName + "vodStitchDetails/(.*)\"") .matcher(bout.toString()); if (idMatcher.find()) { @@ -87,15 +100,17 @@ public void beforeTest() throws IOException { @Test public void test_GetVodStitchDetailTest() throws IOException { - GetVodStitchDetail.getVodStitchDetail(PROJECT_ID, TestUtils.LOCATION, SESSION_ID, - STITCH_DETAIL_ID); + GetVodStitchDetail.getVodStitchDetail( + PROJECT_ID, TestUtils.LOCATION, SESSION_ID, STITCH_DETAIL_ID); String output = bout.toString(); assertThat(output, containsString(STITCH_DETAIL_NAME)); bout.reset(); } @After - public void tearDown() throws IOException { + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); // No delete method for a VOD session System.setOut(originalOut); bout.reset(); diff --git a/media/stitcher/src/test/java/com/example/stitcher/ListVodAdTagDetailsTest.java b/media/stitcher/src/test/java/com/example/stitcher/ListVodAdTagDetailsTest.java index a7eb10d3c6c..b219c0b38a1 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/ListVodAdTagDetailsTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/ListVodAdTagDetailsTest.java @@ -24,6 +24,10 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -35,8 +39,8 @@ @RunWith(JUnit4.class) public class ListVodAdTagDetailsTest { - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); private static String PROJECT_ID; private static String SESSION_ID; private static String SESSION_NAME; @@ -57,17 +61,29 @@ public static void checkRequirements() { } @Before - public void beforeTest() throws IOException { + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, TestUtils.VOD_URI, - TestUtils.VOD_AD_TAG_URI); - String output = bout.toString(); - String[] arr = output.split("/"); - SESSION_ID = arr[arr.length - 1].replace("\n", ""); - SESSION_NAME = String.format("locations/%s/vodSessions/%s/", TestUtils.LOCATION, SESSION_ID); + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); + bout.reset(); + + CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + Matcher idMatcher = + Pattern.compile( + String.format( + "Created VOD session: projects/.*/locations/%s/vodSessions/(.*)", + TestUtils.LOCATION)) + .matcher(bout.toString()); + if (idMatcher.find()) { + SESSION_ID = idMatcher.group(1); + } + // Project number is always returned in the VOD session name + SESSION_NAME = String.format("locations/%s/vodSessions/%s", TestUtils.LOCATION, SESSION_ID); bout.reset(); } @@ -75,12 +91,14 @@ public void beforeTest() throws IOException { public void test_ListVodAdTagDetailsTest() throws IOException { ListVodAdTagDetails.listVodAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); String output = bout.toString(); - assertThat(output, containsString(SESSION_NAME.concat("vodAdTagDetails/"))); + assertThat(output, containsString(SESSION_NAME.concat("/vodAdTagDetails/"))); bout.reset(); } @After - public void tearDown() throws IOException { + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); // No delete method for a VOD session System.setOut(originalOut); bout.reset(); diff --git a/media/stitcher/src/test/java/com/example/stitcher/ListVodConfigsTest.java b/media/stitcher/src/test/java/com/example/stitcher/ListVodConfigsTest.java new file mode 100644 index 00000000000..197d152eb75 --- /dev/null +++ b/media/stitcher/src/test/java/com/example/stitcher/ListVodConfigsTest.java @@ -0,0 +1,93 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class ListVodConfigsTest { + + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); + + private static String PROJECT_ID; + private static String VOD_CONFIG_NAME; + private static PrintStream originalOut; + private ByteArrayOutputStream bout; + + private static String requireEnvVar(String varName) { + String varValue = System.getenv(varName); + assertNotNull( + String.format("Environment variable '%s' is required to perform these tests.", varName)); + return varValue; + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); + originalOut = System.out; + bout = new ByteArrayOutputStream(); + System.setOut(new PrintStream(bout)); + + VOD_CONFIG_NAME = + String.format( + "projects/%s/locations/%s/vodConfigs/%s", + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); + bout.reset(); + } + + @Test + public void test_ListVodConfigs() throws IOException { + ListVodConfigs.listVodConfigs(PROJECT_ID, TestUtils.LOCATION); + String output = bout.toString(); + assertThat(output, containsString(VOD_CONFIG_NAME)); + bout.reset(); + } + + @After + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + System.setOut(originalOut); + bout.reset(); + } +} diff --git a/media/stitcher/src/test/java/com/example/stitcher/ListVodStitchDetailsTest.java b/media/stitcher/src/test/java/com/example/stitcher/ListVodStitchDetailsTest.java index 502b31f96f6..541310c0968 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/ListVodStitchDetailsTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/ListVodStitchDetailsTest.java @@ -24,6 +24,10 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -35,8 +39,8 @@ @RunWith(JUnit4.class) public class ListVodStitchDetailsTest { - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); private static String PROJECT_ID; private static String SESSION_ID; private static String SESSION_NAME; @@ -57,17 +61,29 @@ public static void checkRequirements() { } @Before - public void beforeTest() throws IOException { + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, TestUtils.VOD_URI, - TestUtils.VOD_AD_TAG_URI); - String output = bout.toString(); - String[] arr = output.split("/"); - SESSION_ID = arr[arr.length - 1].replace("\n", ""); - SESSION_NAME = String.format("locations/%s/vodSessions/%s/", TestUtils.LOCATION, SESSION_ID); + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); + bout.reset(); + + CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + Matcher idMatcher = + Pattern.compile( + String.format( + "Created VOD session: projects/.*/locations/%s/vodSessions/(.*)", + TestUtils.LOCATION)) + .matcher(bout.toString()); + if (idMatcher.find()) { + SESSION_ID = idMatcher.group(1); + } + // Project number is always returned in the VOD session name + SESSION_NAME = String.format("locations/%s/vodSessions/%s", TestUtils.LOCATION, SESSION_ID); bout.reset(); } @@ -75,12 +91,14 @@ public void beforeTest() throws IOException { public void test_ListVodStitchDetailsTest() throws IOException { ListVodStitchDetails.listVodStitchDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); String output = bout.toString(); - assertThat(output, containsString(SESSION_NAME.concat("vodStitchDetails/"))); + assertThat(output, containsString(SESSION_NAME.concat("/vodStitchDetails/"))); bout.reset(); } @After - public void tearDown() throws IOException { + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); // No delete method for a VOD session System.setOut(originalOut); bout.reset(); diff --git a/media/stitcher/src/test/java/com/example/stitcher/TestUtils.java b/media/stitcher/src/test/java/com/example/stitcher/TestUtils.java index fc91d964733..7cebbe7d176 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/TestUtils.java +++ b/media/stitcher/src/test/java/com/example/stitcher/TestUtils.java @@ -20,10 +20,12 @@ import com.google.cloud.video.stitcher.v1.ListCdnKeysRequest; import com.google.cloud.video.stitcher.v1.ListLiveConfigsRequest; import com.google.cloud.video.stitcher.v1.ListSlatesRequest; +import com.google.cloud.video.stitcher.v1.ListVodConfigsRequest; import com.google.cloud.video.stitcher.v1.LiveConfig; import com.google.cloud.video.stitcher.v1.LocationName; import com.google.cloud.video.stitcher.v1.Slate; import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VodConfig; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -41,6 +43,7 @@ public class TestUtils { public static final String SLATE_ID_PREFIX = "slate-"; public static final String CDN_KEY_ID_PREFIX = "cdn-key-"; public static final String LIVE_CONFIG_ID_PREFIX = "live-config-"; + public static final String VOD_CONFIG_ID_PREFIX = "vod-config-"; public static final String HOSTNAME = "cdn.example.com"; public static final String UPDATED_HOSTNAME = "updated.example.com"; @@ -142,7 +145,38 @@ public static void cleanStaleLiveConfigs(String projectId, String location) thro long createEpochSec = Long.parseLong(createTime); if (createEpochSec < Instant.now().getEpochSecond() - DELETION_THRESHOLD_TIME_HOURS_IN_SECONDS) { - videoStitcherServiceClient.deleteLiveConfigAsync(liveConfig.getName()) + videoStitcherServiceClient + .deleteLiveConfigAsync(liveConfig.getName()) + .get(2, TimeUnit.MINUTES); + } + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + // Clean up old test VOD configs. + public static void cleanStaleVodConfigs(String projectId, String location) throws IOException { + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + ListVodConfigsRequest listVodConfigsRequest = + ListVodConfigsRequest.newBuilder() + .setParent(LocationName.of(projectId, location).toString()) + .build(); + + VideoStitcherServiceClient.ListVodConfigsPagedResponse response = + videoStitcherServiceClient.listVodConfigs(listVodConfigsRequest); + + for (VodConfig vodConfig : response.iterateAll()) { + Matcher matcher = Pattern.compile(VOD_CONFIG_ID_PREFIX).matcher(vodConfig.getName()); + if (matcher.find()) { + String createTime = vodConfig.getName().substring(matcher.end()).trim(); + long createEpochSec = Long.parseLong(createTime); + if (createEpochSec + < Instant.now().getEpochSecond() - DELETION_THRESHOLD_TIME_HOURS_IN_SECONDS) { + videoStitcherServiceClient + .deleteVodConfigAsync(vodConfig.getName()) .get(2, TimeUnit.MINUTES); } } @@ -218,4 +252,14 @@ public static String getLiveConfigId() { LIVE_CONFIG_ID_PREFIX, Instant.now().getEpochSecond()); } + + // Get a VOD config ID that includes a creation timestamp. Add some randomness in case tests are + // run in parallel. + public static String getVodConfigId() { + return String.format( + "test-%s-%s%s", + UUID.randomUUID().toString().substring(0, 15), + VOD_CONFIG_ID_PREFIX, + Instant.now().getEpochSecond()); + } } diff --git a/media/stitcher/src/test/java/com/example/stitcher/UpdateVodConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/UpdateVodConfigTest.java new file mode 100644 index 00000000000..7f37e3483f4 --- /dev/null +++ b/media/stitcher/src/test/java/com/example/stitcher/UpdateVodConfigTest.java @@ -0,0 +1,96 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class UpdateVodConfigTest { + + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); + private static String PROJECT_ID; + private static String VOD_CONFIG_NAME; + + private static final String UPDATED_VOD_URI = + "https://storage.googleapis.com/cloud-samples-data/media/hls-vod/manifest.mpd"; + private static PrintStream originalOut; + private ByteArrayOutputStream bout; + + private static String requireEnvVar(String varName) { + String varValue = System.getenv(varName); + assertNotNull( + String.format("Environment variable '%s' is required to perform these tests.", varName)); + return varValue; + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); + originalOut = System.out; + bout = new ByteArrayOutputStream(); + System.setOut(new PrintStream(bout)); + + VOD_CONFIG_NAME = + String.format( + "projects/%s/locations/%s/vodConfigs/%s", + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + CreateVodConfig.createVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); + bout.reset(); + } + + @Test + public void test_UpdateVodConfig() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + UpdateVodConfig.updateVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, UPDATED_VOD_URI); + String output = bout.toString(); + assertThat(output, containsString(VOD_CONFIG_NAME)); + bout.reset(); + } + + @After + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + System.setOut(originalOut); + bout.reset(); + } +} From 2df4f4a7a6df633f7aa05d8ff897959c6467e8f3 Mon Sep 17 00:00:00 2001 From: Nicholas Cook Date: Wed, 17 Jul 2024 13:18:02 -0700 Subject: [PATCH 2/7] Update media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java Co-authored-by: Sita Lakshmi Sangameswaran --- .../src/main/java/com/example/stitcher/CreateVodConfig.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java b/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java index a7e135db8a3..b4a1d9b71d8 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java @@ -50,8 +50,7 @@ public static void createVodConfig( String projectId, String location, String vodConfigId, String sourceUri, String adTagUri) throws IOException, ExecutionException, InterruptedException, TimeoutException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. + // once, and can be reused for multiple requests. VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create(); CreateVodConfigRequest createVodConfigRequest = CreateVodConfigRequest.newBuilder() From fc8bc563a070ce8d1d4bffc01ccddf819458ca01 Mon Sep 17 00:00:00 2001 From: Nicholas Cook Date: Wed, 17 Jul 2024 13:18:22 -0700 Subject: [PATCH 3/7] Update media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java Co-authored-by: Sita Lakshmi Sangameswaran --- .../src/main/java/com/example/stitcher/CreateVodConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java b/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java index b4a1d9b71d8..f7f87b6be52 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java @@ -65,7 +65,6 @@ public static void createVodConfig( .createVodConfigAsync(createVodConfigRequest) .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); System.out.println("Created new VOD config: " + response.getName()); - videoStitcherServiceClient.close(); } } // [END videostitcher_create_vod_config] From b77d0f8cc1de990062d5be4b3d9e304407a0b231 Mon Sep 17 00:00:00 2001 From: Nicholas Cook Date: Wed, 17 Jul 2024 13:19:10 -0700 Subject: [PATCH 4/7] Update media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java Co-authored-by: Sita Lakshmi Sangameswaran --- .../src/main/java/com/example/stitcher/ListVodConfigs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java b/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java index 5ed0175a8d2..4710a1c1d14 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java +++ b/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java @@ -47,8 +47,8 @@ public static void listVodConfigs(String projectId, String location) throws IOEx VideoStitcherServiceClient.ListVodConfigsPagedResponse response = videoStitcherServiceClient.listVodConfigs(listVodConfigsRequest); - System.out.println("VOD configs:"); + System.out.println("VOD configs:"); for (VodConfig vodConfig : response.iterateAll()) { System.out.println(vodConfig.getName()); } From 4846ad74796ade253546eb8cbd23d3ac5866cf94 Mon Sep 17 00:00:00 2001 From: Nick Cook Date: Thu, 18 Jul 2024 14:43:03 -0700 Subject: [PATCH 5/7] address feedback and refactor VOD tests (configs and sessions) --- .../com/example/stitcher/CreateVodConfig.java | 34 ++-- .../example/stitcher/CreateVodSession.java | 7 +- .../com/example/stitcher/DeleteVodConfig.java | 27 +-- .../example/stitcher/GetVodAdTagDetail.java | 7 +- .../com/example/stitcher/GetVodConfig.java | 7 +- .../com/example/stitcher/GetVodSession.java | 7 +- .../example/stitcher/GetVodStitchDetail.java | 7 +- .../example/stitcher/ListVodAdTagDetails.java | 12 +- .../com/example/stitcher/ListVodConfigs.java | 9 +- .../stitcher/ListVodStitchDetails.java | 12 +- .../com/example/stitcher/UpdateVodConfig.java | 44 +++-- .../example/stitcher/CreateVodConfigTest.java | 89 --------- .../stitcher/CreateVodSessionTest.java | 91 --------- .../example/stitcher/DeleteVodConfigTest.java | 86 -------- .../stitcher/GetVodAdTagDetailTest.java | 118 ----------- .../example/stitcher/GetVodConfigTest.java | 93 --------- .../example/stitcher/GetVodSessionTest.java | 106 ---------- .../stitcher/GetVodStitchDetailTest.java | 118 ----------- .../stitcher/ListVodAdTagDetailsTest.java | 106 ---------- .../example/stitcher/ListVodConfigsTest.java | 93 --------- .../stitcher/ListVodStitchDetailsTest.java | 106 ---------- ...eVodConfigTest.java => VodConfigTest.java} | 60 ++++-- .../com/example/stitcher/VodSessionTest.java | 184 ++++++++++++++++++ 23 files changed, 326 insertions(+), 1097 deletions(-) delete mode 100644 media/stitcher/src/test/java/com/example/stitcher/CreateVodConfigTest.java delete mode 100644 media/stitcher/src/test/java/com/example/stitcher/CreateVodSessionTest.java delete mode 100644 media/stitcher/src/test/java/com/example/stitcher/DeleteVodConfigTest.java delete mode 100644 media/stitcher/src/test/java/com/example/stitcher/GetVodAdTagDetailTest.java delete mode 100644 media/stitcher/src/test/java/com/example/stitcher/GetVodConfigTest.java delete mode 100644 media/stitcher/src/test/java/com/example/stitcher/GetVodSessionTest.java delete mode 100644 media/stitcher/src/test/java/com/example/stitcher/GetVodStitchDetailTest.java delete mode 100644 media/stitcher/src/test/java/com/example/stitcher/ListVodAdTagDetailsTest.java delete mode 100644 media/stitcher/src/test/java/com/example/stitcher/ListVodConfigsTest.java delete mode 100644 media/stitcher/src/test/java/com/example/stitcher/ListVodStitchDetailsTest.java rename media/stitcher/src/test/java/com/example/stitcher/{UpdateVodConfigTest.java => VodConfigTest.java} (61%) create mode 100644 media/stitcher/src/test/java/com/example/stitcher/VodSessionTest.java diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java b/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java index f7f87b6be52..3a9ef21d58a 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateVodConfig.java @@ -46,25 +46,31 @@ public static void main(String[] args) throws Exception { createVodConfig(projectId, location, vodConfigId, sourceUri, adTagUri); } - public static void createVodConfig( + // Creates a video on demand (VOD) config. VOD configs are used to configure VOD + // sessions. For more information, see + // https://cloud.google.com/video-stitcher/docs/how-to/managing-vod-configs. + public static VodConfig createVodConfig( String projectId, String location, String vodConfigId, String sourceUri, String adTagUri) throws IOException, ExecutionException, InterruptedException, TimeoutException { // Initialize client that will be used to send requests. This client only needs to be created // once, and can be reused for multiple requests. - VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create(); - CreateVodConfigRequest createVodConfigRequest = - CreateVodConfigRequest.newBuilder() - .setParent(LocationName.of(projectId, location).toString()) - .setVodConfigId(vodConfigId) - .setVodConfig( - VodConfig.newBuilder().setSourceUri(sourceUri).setAdTagUri(adTagUri).build()) - .build(); + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + CreateVodConfigRequest createVodConfigRequest = + CreateVodConfigRequest.newBuilder() + .setParent(LocationName.of(projectId, location).toString()) + .setVodConfigId(vodConfigId) + .setVodConfig( + VodConfig.newBuilder().setSourceUri(sourceUri).setAdTagUri(adTagUri).build()) + .build(); - VodConfig response = - videoStitcherServiceClient - .createVodConfigAsync(createVodConfigRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Created new VOD config: " + response.getName()); + VodConfig response = + videoStitcherServiceClient + .createVodConfigAsync(createVodConfigRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Created new VOD config: " + response.getName()); + return response; + } } } // [END videostitcher_create_vod_config] diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateVodSession.java b/media/stitcher/src/main/java/com/example/stitcher/CreateVodSession.java index 1956e1a9033..7076c90835e 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateVodSession.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateVodSession.java @@ -37,11 +37,11 @@ public static void main(String[] args) throws Exception { createVodSession(projectId, location, vodConfigId); } - public static void createVodSession(String projectId, String location, String vodConfigId) + // Creates a video on demand (VOD) session using the parameters in the designated VOD config. + public static VodSession createVodSession(String projectId, String location, String vodConfigId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. In this example, try-with-resources is used - // which automatically calls close() on the client to clean up resources. + // once, and can be reused for multiple requests. try (VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create()) { CreateVodSessionRequest createVodSessionRequest = @@ -56,6 +56,7 @@ public static void createVodSession(String projectId, String location, String vo VodSession response = videoStitcherServiceClient.createVodSession(createVodSessionRequest); System.out.println("Created VOD session: " + response.getName()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/DeleteVodConfig.java b/media/stitcher/src/main/java/com/example/stitcher/DeleteVodConfig.java index 0c49987e95d..dc9a85baa40 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/DeleteVodConfig.java +++ b/media/stitcher/src/main/java/com/example/stitcher/DeleteVodConfig.java @@ -39,22 +39,23 @@ public static void main(String[] args) throws Exception { deleteVodConfig(projectId, location, vodConfigId); } + // Deletes a video on demand (VOD) config. public static void deleteVodConfig(String projectId, String location, String vodConfigId) throws IOException, ExecutionException, InterruptedException, TimeoutException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create(); - DeleteVodConfigRequest deleteVodConfigRequest = - DeleteVodConfigRequest.newBuilder() - .setName(VodConfigName.of(projectId, location, vodConfigId).toString()) - .build(); - - videoStitcherServiceClient - .deleteVodConfigAsync(deleteVodConfigRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Deleted VOD config"); - videoStitcherServiceClient.close(); + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + DeleteVodConfigRequest deleteVodConfigRequest = + DeleteVodConfigRequest.newBuilder() + .setName(VodConfigName.of(projectId, location, vodConfigId).toString()) + .build(); + + videoStitcherServiceClient + .deleteVodConfigAsync(deleteVodConfigRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Deleted VOD config"); + } } } // [END videostitcher_delete_vod_config] diff --git a/media/stitcher/src/main/java/com/example/stitcher/GetVodAdTagDetail.java b/media/stitcher/src/main/java/com/example/stitcher/GetVodAdTagDetail.java index c810372a710..cd876752737 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/GetVodAdTagDetail.java +++ b/media/stitcher/src/main/java/com/example/stitcher/GetVodAdTagDetail.java @@ -36,12 +36,12 @@ public static void main(String[] args) throws Exception { getVodAdTagDetail(projectId, location, sessionId, adTagDetailId); } - public static void getVodAdTagDetail( + // Gets an ad tag detail for a video on demand (VOD) session. + public static VodAdTagDetail getVodAdTagDetail( String projectId, String location, String sessionId, String adTagDetailId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. In this example, try-with-resources is used - // which automatically calls close() on the client to clean up resources. + // once, and can be reused for multiple requests. try (VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create()) { GetVodAdTagDetailRequest getVodAdTagDetailRequest = @@ -53,6 +53,7 @@ public static void getVodAdTagDetail( VodAdTagDetail response = videoStitcherServiceClient.getVodAdTagDetail(getVodAdTagDetailRequest); System.out.println("VOD ad tag detail: " + response.getName()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/GetVodConfig.java b/media/stitcher/src/main/java/com/example/stitcher/GetVodConfig.java index 19659f2de01..a89d24f8b71 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/GetVodConfig.java +++ b/media/stitcher/src/main/java/com/example/stitcher/GetVodConfig.java @@ -35,11 +35,11 @@ public static void main(String[] args) throws Exception { getVodConfig(projectId, location, vodConfigId); } - public static void getVodConfig(String projectId, String location, String vodConfigId) + // Gets a video on demand (VOD) config. + public static VodConfig getVodConfig(String projectId, String location, String vodConfigId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. In this example, try-with-resources is used - // which automatically calls close() on the client to clean up resources. + // once, and can be reused for multiple requests. try (VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create()) { GetVodConfigRequest getVodConfigRequest = @@ -49,6 +49,7 @@ public static void getVodConfig(String projectId, String location, String vodCon VodConfig response = videoStitcherServiceClient.getVodConfig(getVodConfigRequest); System.out.println("VOD config: " + response.getName()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/GetVodSession.java b/media/stitcher/src/main/java/com/example/stitcher/GetVodSession.java index 8d1a0c2416c..a0f19cf7614 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/GetVodSession.java +++ b/media/stitcher/src/main/java/com/example/stitcher/GetVodSession.java @@ -35,11 +35,11 @@ public static void main(String[] args) throws Exception { getVodSession(projectId, location, sessionId); } - public static void getVodSession(String projectId, String location, String sessionId) + // Gets a video on demand (VOD) session. + public static VodSession getVodSession(String projectId, String location, String sessionId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. In this example, try-with-resources is used - // which automatically calls close() on the client to clean up resources. + // once, and can be reused for multiple requests. try (VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create()) { GetVodSessionRequest getVodSessionRequest = @@ -49,6 +49,7 @@ public static void getVodSession(String projectId, String location, String sessi VodSession response = videoStitcherServiceClient.getVodSession(getVodSessionRequest); System.out.println("VOD session: " + response.getName()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/GetVodStitchDetail.java b/media/stitcher/src/main/java/com/example/stitcher/GetVodStitchDetail.java index 8c701f0e68e..e3518119364 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/GetVodStitchDetail.java +++ b/media/stitcher/src/main/java/com/example/stitcher/GetVodStitchDetail.java @@ -36,12 +36,12 @@ public static void main(String[] args) throws Exception { getVodStitchDetail(projectId, location, sessionId, stitchDetailId); } - public static void getVodStitchDetail( + // Gets a stitch detail for a video on demand (VOD) session. + public static VodStitchDetail getVodStitchDetail( String projectId, String location, String sessionId, String stitchDetailId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. In this example, try-with-resources is used - // which automatically calls close() on the client to clean up resources. + // once, and can be reused for multiple requests. try (VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create()) { GetVodStitchDetailRequest getVodStitchDetailRequest = @@ -53,6 +53,7 @@ public static void getVodStitchDetail( VodStitchDetail response = videoStitcherServiceClient.getVodStitchDetail(getVodStitchDetailRequest); System.out.println("VOD stitch detail: " + response.getName()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/ListVodAdTagDetails.java b/media/stitcher/src/main/java/com/example/stitcher/ListVodAdTagDetails.java index 5ebb865d228..c9325c995b5 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/ListVodAdTagDetails.java +++ b/media/stitcher/src/main/java/com/example/stitcher/ListVodAdTagDetails.java @@ -20,6 +20,7 @@ import com.google.cloud.video.stitcher.v1.ListVodAdTagDetailsRequest; import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListVodAdTagDetailsPagedResponse; import com.google.cloud.video.stitcher.v1.VodAdTagDetail; import com.google.cloud.video.stitcher.v1.VodSessionName; import java.io.IOException; @@ -35,11 +36,11 @@ public static void main(String[] args) throws Exception { listVodAdTagDetails(projectId, location, sessionId); } - public static void listVodAdTagDetails(String projectId, String location, String sessionId) - throws IOException { + // Lists the ad tag details for a video on demand (VOD) session. + public static ListVodAdTagDetailsPagedResponse listVodAdTagDetails( + String projectId, String location, String sessionId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. In this example, try-with-resources is used - // which automatically calls close() on the client to clean up resources. + // once, and can be reused for multiple requests. try (VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create()) { ListVodAdTagDetailsRequest listVodAdTagDetailsRequest = @@ -49,11 +50,12 @@ public static void listVodAdTagDetails(String projectId, String location, String VideoStitcherServiceClient.ListVodAdTagDetailsPagedResponse response = videoStitcherServiceClient.listVodAdTagDetails(listVodAdTagDetailsRequest); - System.out.println("VOD ad tag details:"); + System.out.println("VOD ad tag details:"); for (VodAdTagDetail adTagDetail : response.iterateAll()) { System.out.println(adTagDetail.toString()); } + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java b/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java index 4710a1c1d14..3e4678c929f 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java +++ b/media/stitcher/src/main/java/com/example/stitcher/ListVodConfigs.java @@ -21,6 +21,7 @@ import com.google.cloud.video.stitcher.v1.ListVodConfigsRequest; import com.google.cloud.video.stitcher.v1.LocationName; import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListVodConfigsPagedResponse; import com.google.cloud.video.stitcher.v1.VodConfig; import java.io.IOException; @@ -34,10 +35,11 @@ public static void main(String[] args) throws Exception { listVodConfigs(projectId, location); } - public static void listVodConfigs(String projectId, String location) throws IOException { + // Lists all the video on demand (VOD) configs for a given project and locatin. + public static ListVodConfigsPagedResponse listVodConfigs(String projectId, String location) + throws IOException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. In this example, try-with-resources is used - // which automatically calls close() on the client to clean up resources. + // once, and can be reused for multiple requests. try (VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create()) { ListVodConfigsRequest listVodConfigsRequest = @@ -52,6 +54,7 @@ public static void listVodConfigs(String projectId, String location) throws IOEx for (VodConfig vodConfig : response.iterateAll()) { System.out.println(vodConfig.getName()); } + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/ListVodStitchDetails.java b/media/stitcher/src/main/java/com/example/stitcher/ListVodStitchDetails.java index d73eb7bd3a7..c8ad79c1422 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/ListVodStitchDetails.java +++ b/media/stitcher/src/main/java/com/example/stitcher/ListVodStitchDetails.java @@ -20,6 +20,7 @@ import com.google.cloud.video.stitcher.v1.ListVodStitchDetailsRequest; import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListVodStitchDetailsPagedResponse; import com.google.cloud.video.stitcher.v1.VodSessionName; import com.google.cloud.video.stitcher.v1.VodStitchDetail; import java.io.IOException; @@ -35,11 +36,11 @@ public static void main(String[] args) throws Exception { listVodStitchDetails(projectId, location, sessionId); } - public static void listVodStitchDetails(String projectId, String location, String sessionId) - throws IOException { + // Lists the VOD stitch details for a video on demand (VOD) session. + public static ListVodStitchDetailsPagedResponse listVodStitchDetails( + String projectId, String location, String sessionId) throws IOException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. In this example, try-with-resources is used - // which automatically calls close() on the client to clean up resources. + // once, and can be reused for multiple requests. try (VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create()) { ListVodStitchDetailsRequest listVodStitchDetailsRequest = @@ -49,11 +50,12 @@ public static void listVodStitchDetails(String projectId, String location, Strin VideoStitcherServiceClient.ListVodStitchDetailsPagedResponse response = videoStitcherServiceClient.listVodStitchDetails(listVodStitchDetailsRequest); - System.out.println("VOD stitch details:"); + System.out.println("VOD stitch details:"); for (VodStitchDetail stitchDetail : response.iterateAll()) { System.out.println(stitchDetail.toString()); } + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/UpdateVodConfig.java b/media/stitcher/src/main/java/com/example/stitcher/UpdateVodConfig.java index 45cc31c0ee1..4bcd279e0ed 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/UpdateVodConfig.java +++ b/media/stitcher/src/main/java/com/example/stitcher/UpdateVodConfig.java @@ -44,31 +44,33 @@ public static void main(String[] args) throws Exception { updateVodConfig(projectId, location, vodConfigId, sourceUri); } - public static void updateVodConfig( + // Updates the source URI in a video on demand (VOD) config. + public static VodConfig updateVodConfig( String projectId, String location, String vodConfigId, String sourceUri) throws IOException, ExecutionException, InterruptedException, TimeoutException { // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient.create(); - UpdateVodConfigRequest updateVodConfigRequest = - UpdateVodConfigRequest.newBuilder() - .setVodConfig( - VodConfig.newBuilder() - .setName(VodConfigName.of(projectId, location, vodConfigId).toString()) - .setSourceUri(sourceUri) - .build()) - // Set the update mask to the sourceUri field in the existing VOD config. You must set - // the mask to the field you want to update. - .setUpdateMask(FieldMask.newBuilder().addPaths("sourceUri").build()) - .build(); + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + UpdateVodConfigRequest updateVodConfigRequest = + UpdateVodConfigRequest.newBuilder() + .setVodConfig( + VodConfig.newBuilder() + .setName(VodConfigName.of(projectId, location, vodConfigId).toString()) + .setSourceUri(sourceUri) + .build()) + // Set the update mask to the sourceUri field in the existing VOD config. You must set + // the mask to the field you want to update. + .setUpdateMask(FieldMask.newBuilder().addPaths("sourceUri").build()) + .build(); - VodConfig response = - videoStitcherServiceClient - .updateVodConfigAsync(updateVodConfigRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Updated VOD config: " + response.getName()); - videoStitcherServiceClient.close(); + VodConfig response = + videoStitcherServiceClient + .updateVodConfigAsync(updateVodConfigRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Updated VOD config: " + response.getName()); + return response; + } } } // [END videostitcher_update_vod_config] diff --git a/media/stitcher/src/test/java/com/example/stitcher/CreateVodConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/CreateVodConfigTest.java deleted file mode 100644 index 3580fa647c5..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/CreateVodConfigTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * 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.stitcher; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class CreateVodConfigTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - private static String PROJECT_ID; - private static String VOD_CONFIG_NAME; - private static PrintStream originalOut; - private ByteArrayOutputStream bout; - - private static String requireEnvVar(String varName) { - String varValue = System.getenv(varName); - assertNotNull( - String.format("Environment variable '%s' is required to perform these tests.", varName)); - return varValue; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - VOD_CONFIG_NAME = String.format("locations/%s/vodConfigs/", TestUtils.LOCATION); - bout.reset(); - } - - @Test - public void test_CreateVodConfig() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); - String output = bout.toString(); - assertThat(output, containsString(VOD_CONFIG_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/CreateVodSessionTest.java b/media/stitcher/src/test/java/com/example/stitcher/CreateVodSessionTest.java deleted file mode 100644 index 7b056264aef..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/CreateVodSessionTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * 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.stitcher; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class CreateVodSessionTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - private static String PROJECT_ID; - private static String SESSION_NAME; - private static PrintStream originalOut; - private ByteArrayOutputStream bout; - - private static String requireEnvVar(String varName) { - String varValue = System.getenv(varName); - assertNotNull( - String.format("Environment variable '%s' is required to perform these tests.", varName)); - return varValue; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - // Project number is always returned in the VOD session name - SESSION_NAME = String.format("locations/%s/vodSessions/", TestUtils.LOCATION); - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); - bout.reset(); - } - - @Test - public void test_CreateVodSession() throws IOException { - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - String output = bout.toString(); - assertThat(output, containsString(SESSION_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - // No delete method for a VOD session - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/DeleteVodConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/DeleteVodConfigTest.java deleted file mode 100644 index 14a2f5e5645..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/DeleteVodConfigTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * 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.stitcher; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class DeleteVodConfigTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - private static String PROJECT_ID; - private static PrintStream originalOut; - private ByteArrayOutputStream bout; - - private static String requireEnvVar(String varName) { - String varValue = System.getenv(varName); - assertNotNull( - String.format("Environment variable '%s' is required to perform these tests.", varName)); - return varValue; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); - bout.reset(); - } - - @Test - public void test_DeleteVodConfig() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - String output = bout.toString(); - assertThat(output, containsString("Deleted VOD config")); - bout.reset(); - } - - @After - public void tearDown() throws IOException { - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetVodAdTagDetailTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetVodAdTagDetailTest.java deleted file mode 100644 index 5f8078acd4a..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/GetVodAdTagDetailTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * 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.stitcher; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class GetVodAdTagDetailTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - private static String PROJECT_ID; - private static String SESSION_ID; - private static String AD_TAG_DETAIL_ID; - private static String AD_TAG_DETAIL_NAME; - private static PrintStream originalOut; - private ByteArrayOutputStream bout; - - private static String requireEnvVar(String varName) { - String varValue = System.getenv(varName); - assertNotNull( - String.format("Environment variable '%s' is required to perform these tests.", varName)); - return varValue; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); - bout.reset(); - - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - Matcher idMatcher = - Pattern.compile( - String.format( - "Created VOD session: projects/.*/locations/%s/vodSessions/(.*)", - TestUtils.LOCATION)) - .matcher(bout.toString()); - if (idMatcher.find()) { - SESSION_ID = idMatcher.group(1); - } - String sessionName = - String.format("locations/%s/vodSessions/%s/", TestUtils.LOCATION, SESSION_ID); - bout.reset(); - - ListVodAdTagDetails.listVodAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); - idMatcher = - Pattern.compile("name: \"projects/.*/" + sessionName + "vodAdTagDetails/(.*)\"") - .matcher(bout.toString()); - if (idMatcher.find()) { - AD_TAG_DETAIL_ID = idMatcher.group(1); - AD_TAG_DETAIL_NAME = sessionName + "vodAdTagDetails/" + AD_TAG_DETAIL_ID; - } - bout.reset(); - } - - @Test - public void test_GetVodAdTagDetailTest() throws IOException { - GetVodAdTagDetail.getVodAdTagDetail( - PROJECT_ID, TestUtils.LOCATION, SESSION_ID, AD_TAG_DETAIL_ID); - String output = bout.toString(); - assertThat(output, containsString(AD_TAG_DETAIL_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - // No delete method for a VOD session - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetVodConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetVodConfigTest.java deleted file mode 100644 index 3b9406fb945..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/GetVodConfigTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * 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.stitcher; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class GetVodConfigTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - - private static String PROJECT_ID; - private static String VOD_CONFIG_NAME; - private static PrintStream originalOut; - private ByteArrayOutputStream bout; - - private static String requireEnvVar(String varName) { - String varValue = System.getenv(varName); - assertNotNull( - String.format("Environment variable '%s' is required to perform these tests.", varName)); - return varValue; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - VOD_CONFIG_NAME = - String.format( - "projects/%s/locations/%s/vodConfigs/%s", - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); - bout.reset(); - } - - @Test - public void test_GetVodConfig() throws IOException { - GetVodConfig.getVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - String output = bout.toString(); - assertThat(output, containsString(VOD_CONFIG_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetVodSessionTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetVodSessionTest.java deleted file mode 100644 index 414ee41b6fa..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/GetVodSessionTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * 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.stitcher; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class GetVodSessionTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - private static String PROJECT_ID; - private static String SESSION_ID; - private static String SESSION_NAME; - private static PrintStream originalOut; - private ByteArrayOutputStream bout; - - private static String requireEnvVar(String varName) { - String varValue = System.getenv(varName); - assertNotNull( - String.format("Environment variable '%s' is required to perform these tests.", varName)); - return varValue; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); - bout.reset(); - - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - Matcher idMatcher = - Pattern.compile( - String.format( - "Created VOD session: projects/.*/locations/%s/vodSessions/(.*)", - TestUtils.LOCATION)) - .matcher(bout.toString()); - if (idMatcher.find()) { - SESSION_ID = idMatcher.group(1); - } - // Project number is always returned in the VOD session name - SESSION_NAME = String.format("locations/%s/vodSessions/%s", TestUtils.LOCATION, SESSION_ID); - bout.reset(); - } - - @Test - public void test_GetVodSession() throws IOException { - GetVodSession.getVodSession(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); - String output = bout.toString(); - assertThat(output, containsString(SESSION_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - // No delete method for a VOD session - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetVodStitchDetailTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetVodStitchDetailTest.java deleted file mode 100644 index 4e2a1776606..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/GetVodStitchDetailTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * 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.stitcher; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class GetVodStitchDetailTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - private static String PROJECT_ID; - private static String SESSION_ID; - private static String STITCH_DETAIL_ID; - private static String STITCH_DETAIL_NAME; - private static PrintStream originalOut; - private ByteArrayOutputStream bout; - - private static String requireEnvVar(String varName) { - String varValue = System.getenv(varName); - assertNotNull( - String.format("Environment variable '%s' is required to perform these tests.", varName)); - return varValue; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); - bout.reset(); - - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - Matcher idMatcher = - Pattern.compile( - String.format( - "Created VOD session: projects/.*/locations/%s/vodSessions/(.*)", - TestUtils.LOCATION)) - .matcher(bout.toString()); - if (idMatcher.find()) { - SESSION_ID = idMatcher.group(1); - } - String sessionName = - String.format("locations/%s/vodSessions/%s/", TestUtils.LOCATION, SESSION_ID); - bout.reset(); - - ListVodStitchDetails.listVodStitchDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); - idMatcher = - Pattern.compile("name: \"projects/.*/" + sessionName + "vodStitchDetails/(.*)\"") - .matcher(bout.toString()); - if (idMatcher.find()) { - STITCH_DETAIL_ID = idMatcher.group(1); - STITCH_DETAIL_NAME = sessionName + "vodStitchDetails/" + STITCH_DETAIL_ID; - } - bout.reset(); - } - - @Test - public void test_GetVodStitchDetailTest() throws IOException { - GetVodStitchDetail.getVodStitchDetail( - PROJECT_ID, TestUtils.LOCATION, SESSION_ID, STITCH_DETAIL_ID); - String output = bout.toString(); - assertThat(output, containsString(STITCH_DETAIL_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - // No delete method for a VOD session - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/ListVodAdTagDetailsTest.java b/media/stitcher/src/test/java/com/example/stitcher/ListVodAdTagDetailsTest.java deleted file mode 100644 index b219c0b38a1..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/ListVodAdTagDetailsTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * 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.stitcher; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class ListVodAdTagDetailsTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - private static String PROJECT_ID; - private static String SESSION_ID; - private static String SESSION_NAME; - private static PrintStream originalOut; - private ByteArrayOutputStream bout; - - private static String requireEnvVar(String varName) { - String varValue = System.getenv(varName); - assertNotNull( - String.format("Environment variable '%s' is required to perform these tests.", varName)); - return varValue; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); - bout.reset(); - - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - Matcher idMatcher = - Pattern.compile( - String.format( - "Created VOD session: projects/.*/locations/%s/vodSessions/(.*)", - TestUtils.LOCATION)) - .matcher(bout.toString()); - if (idMatcher.find()) { - SESSION_ID = idMatcher.group(1); - } - // Project number is always returned in the VOD session name - SESSION_NAME = String.format("locations/%s/vodSessions/%s", TestUtils.LOCATION, SESSION_ID); - bout.reset(); - } - - @Test - public void test_ListVodAdTagDetailsTest() throws IOException { - ListVodAdTagDetails.listVodAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); - String output = bout.toString(); - assertThat(output, containsString(SESSION_NAME.concat("/vodAdTagDetails/"))); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - // No delete method for a VOD session - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/ListVodConfigsTest.java b/media/stitcher/src/test/java/com/example/stitcher/ListVodConfigsTest.java deleted file mode 100644 index 197d152eb75..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/ListVodConfigsTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2024 Google LLC - * - * 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.stitcher; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class ListVodConfigsTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - - private static String PROJECT_ID; - private static String VOD_CONFIG_NAME; - private static PrintStream originalOut; - private ByteArrayOutputStream bout; - - private static String requireEnvVar(String varName) { - String varValue = System.getenv(varName); - assertNotNull( - String.format("Environment variable '%s' is required to perform these tests.", varName)); - return varValue; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - VOD_CONFIG_NAME = - String.format( - "projects/%s/locations/%s/vodConfigs/%s", - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); - bout.reset(); - } - - @Test - public void test_ListVodConfigs() throws IOException { - ListVodConfigs.listVodConfigs(PROJECT_ID, TestUtils.LOCATION); - String output = bout.toString(); - assertThat(output, containsString(VOD_CONFIG_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/ListVodStitchDetailsTest.java b/media/stitcher/src/test/java/com/example/stitcher/ListVodStitchDetailsTest.java deleted file mode 100644 index 541310c0968..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/ListVodStitchDetailsTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * 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.stitcher; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertNotNull; - -import com.google.cloud.testing.junit4.MultipleAttemptsRule; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class ListVodStitchDetailsTest { - - @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - private static String PROJECT_ID; - private static String SESSION_ID; - private static String SESSION_NAME; - private static PrintStream originalOut; - private ByteArrayOutputStream bout; - - private static String requireEnvVar(String varName) { - String varValue = System.getenv(varName); - assertNotNull( - String.format("Environment variable '%s' is required to perform these tests.", varName)); - return varValue; - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); - bout.reset(); - - CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - Matcher idMatcher = - Pattern.compile( - String.format( - "Created VOD session: projects/.*/locations/%s/vodSessions/(.*)", - TestUtils.LOCATION)) - .matcher(bout.toString()); - if (idMatcher.find()) { - SESSION_ID = idMatcher.group(1); - } - // Project number is always returned in the VOD session name - SESSION_NAME = String.format("locations/%s/vodSessions/%s", TestUtils.LOCATION, SESSION_ID); - bout.reset(); - } - - @Test - public void test_ListVodStitchDetailsTest() throws IOException { - ListVodStitchDetails.listVodStitchDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); - String output = bout.toString(); - assertThat(output, containsString(SESSION_NAME.concat("/vodStitchDetails/"))); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - // No delete method for a VOD session - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/UpdateVodConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java similarity index 61% rename from media/stitcher/src/test/java/com/example/stitcher/UpdateVodConfigTest.java rename to media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java index 7f37e3483f4..ae69f605480 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/UpdateVodConfigTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java @@ -21,6 +21,8 @@ import static org.junit.Assert.assertNotNull; import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListVodConfigsPagedResponse; +import com.google.cloud.video.stitcher.v1.VodConfig; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; @@ -35,15 +37,12 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) -public class UpdateVodConfigTest { +public class VodConfigTest { @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); - private static String PROJECT_ID; private static String VOD_CONFIG_NAME; - - private static final String UPDATED_VOD_URI = - "https://storage.googleapis.com/cloud-samples-data/media/hls-vod/manifest.mpd"; + private static String PROJECT_ID; private static PrintStream originalOut; private ByteArrayOutputStream bout; @@ -69,20 +68,49 @@ public void beforeTest() System.setOut(new PrintStream(bout)); VOD_CONFIG_NAME = - String.format( - "projects/%s/locations/%s/vodConfigs/%s", - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - CreateVodConfig.createVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); + String.format("locations/%s/vodConfigs/%s", TestUtils.LOCATION, VOD_CONFIG_ID); + VodConfig response = + CreateVodConfig.createVodConfig( + PROJECT_ID, + TestUtils.LOCATION, + VOD_CONFIG_ID, + TestUtils.VOD_URI, + TestUtils.VOD_AD_TAG_URI); + assertThat(response.getName(), containsString(VOD_CONFIG_NAME)); + bout.reset(); + } + + @Test + public void testGetVodConfig() throws IOException { + VodConfig response = GetVodConfig.getVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + assertThat(response.getName(), containsString(VOD_CONFIG_NAME)); bout.reset(); } @Test - public void test_UpdateVodConfig() + public void testListVodConfigs() throws IOException { + ListVodConfigsPagedResponse response = + ListVodConfigs.listVodConfigs(PROJECT_ID, TestUtils.LOCATION); + Boolean pass = false; + for (VodConfig vodConfig : response.iterateAll()) { + if (vodConfig.getName().contains(VOD_CONFIG_NAME)) { + pass = true; + } + } + assert (pass); + bout.reset(); + } + + @Test + public void testUpdateVodConfig() throws IOException, ExecutionException, InterruptedException, TimeoutException { - UpdateVodConfig.updateVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, UPDATED_VOD_URI); - String output = bout.toString(); - assertThat(output, containsString(VOD_CONFIG_NAME)); + String UPDATED_VOD_URI = + "https://storage.googleapis.com/cloud-samples-data/media/hls-vod/manifest.mpd"; + VodConfig response = + UpdateVodConfig.updateVodConfig( + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, UPDATED_VOD_URI); + assertThat(response.getName(), containsString(VOD_CONFIG_NAME)); + assertThat(response.getSourceUri(), containsString(UPDATED_VOD_URI)); bout.reset(); } @@ -90,7 +118,9 @@ public void test_UpdateVodConfig() public void tearDown() throws IOException, ExecutionException, InterruptedException, TimeoutException { DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - System.setOut(originalOut); + String output = bout.toString(); + assertThat(output, containsString("Deleted VOD config")); bout.reset(); + System.setOut(originalOut); } } diff --git a/media/stitcher/src/test/java/com/example/stitcher/VodSessionTest.java b/media/stitcher/src/test/java/com/example/stitcher/VodSessionTest.java new file mode 100644 index 00000000000..ce2b82bbc2b --- /dev/null +++ b/media/stitcher/src/test/java/com/example/stitcher/VodSessionTest.java @@ -0,0 +1,184 @@ +/* + * Copyright 2024 Google LLC + * + * 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.stitcher; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNotNull; + +import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListVodAdTagDetailsPagedResponse; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListVodStitchDetailsPagedResponse; +import com.google.cloud.video.stitcher.v1.VodAdTagDetail; +import com.google.cloud.video.stitcher.v1.VodConfig; +import com.google.cloud.video.stitcher.v1.VodSession; +import com.google.cloud.video.stitcher.v1.VodStitchDetail; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class VodSessionTest { + + @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); + private static final String VOD_CONFIG_ID = TestUtils.getVodConfigId(); + private static String VOD_CONFIG_NAME; + private static String VOD_SESSION_NAME_PREFIX; + private static String VOD_SESSION_NAME; + private static String SESSION_ID; + private static String AD_TAG_DETAIL_NAME; + private static String AD_TAG_DETAIL_ID; + private static String STITCH_DETAIL_NAME; + private static String STITCH_DETAIL_ID; + private static String PROJECT_ID; + private static PrintStream originalOut; + private ByteArrayOutputStream bout; + + private static String requireEnvVar(String varName) { + String varValue = System.getenv(varName); + assertNotNull( + String.format("Environment variable '%s' is required to perform these tests.", varName)); + return varValue; + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); + } + + @Before + public void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); + originalOut = System.out; + bout = new ByteArrayOutputStream(); + System.setOut(new PrintStream(bout)); + + VOD_CONFIG_NAME = + String.format("locations/%s/vodConfigs/%s", TestUtils.LOCATION, VOD_CONFIG_ID); + VodConfig configResponse = + CreateVodConfig.createVodConfig( + PROJECT_ID, + TestUtils.LOCATION, + VOD_CONFIG_ID, + TestUtils.VOD_URI, + TestUtils.VOD_AD_TAG_URI); + assertThat(configResponse.getName(), containsString(VOD_CONFIG_NAME)); + + // Session IDs are autogenerated. + VOD_SESSION_NAME_PREFIX = String.format("locations/%s/vodSessions/", TestUtils.LOCATION); + VodSession sessionResponse = + CreateVodSession.createVodSession(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + assertThat(sessionResponse.getName(), containsString(VOD_SESSION_NAME_PREFIX)); + + VOD_SESSION_NAME = sessionResponse.getName(); + String[] id = VOD_SESSION_NAME.split("/"); + SESSION_ID = id[id.length - 1]; + + ListVodAdTagDetailsPagedResponse adtagResponse = + ListVodAdTagDetails.listVodAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + for (VodAdTagDetail vodAdTagDetail : adtagResponse.iterateAll()) { + AD_TAG_DETAIL_NAME = vodAdTagDetail.getName(); + } + id = AD_TAG_DETAIL_NAME.split("/"); + AD_TAG_DETAIL_ID = id[id.length - 1]; + + ListVodStitchDetailsPagedResponse stitchResponse = + ListVodStitchDetails.listVodStitchDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + for (VodStitchDetail vodStitchDetail : stitchResponse.iterateAll()) { + STITCH_DETAIL_NAME = vodStitchDetail.getName(); + } + id = STITCH_DETAIL_NAME.split("/"); + STITCH_DETAIL_ID = id[id.length - 1]; + + bout.reset(); + } + + @Test + public void testGetVodSession() throws IOException { + VodSession response = GetVodSession.getVodSession(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + assertThat(response.getName(), containsString(VOD_SESSION_NAME)); + bout.reset(); + } + + @Test + public void testListVodAdTagDetailsTest() throws IOException { + ListVodAdTagDetailsPagedResponse response = + ListVodAdTagDetails.listVodAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + Boolean pass = false; + for (VodAdTagDetail vodAdTagDetail : response.iterateAll()) { + if (vodAdTagDetail.getName().contains(VOD_SESSION_NAME.concat("/vodAdTagDetails/"))) { + pass = true; + } + } + assert (pass); + bout.reset(); + } + + @Test + public void testGetVodAdTagDetailTest() throws IOException { + VodAdTagDetail response = + GetVodAdTagDetail.getVodAdTagDetail( + PROJECT_ID, TestUtils.LOCATION, SESSION_ID, AD_TAG_DETAIL_ID); + assertThat(response.getName(), containsString(AD_TAG_DETAIL_NAME)); + bout.reset(); + } + + @Test + public void testListVodStitchDetailsTest() throws IOException { + ListVodStitchDetailsPagedResponse response = + ListVodStitchDetails.listVodStitchDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + Boolean pass = false; + for (VodStitchDetail vodStitchDetail : response.iterateAll()) { + if (vodStitchDetail.getName().contains(VOD_SESSION_NAME.concat("/vodStitchDetails/"))) { + pass = true; + } + } + assert (pass); + bout.reset(); + } + + @Test + public void testGetVodStitchDetailTest() throws IOException { + VodStitchDetail response = + GetVodStitchDetail.getVodStitchDetail( + PROJECT_ID, TestUtils.LOCATION, SESSION_ID, STITCH_DETAIL_ID); + assertThat(response.getName(), containsString(STITCH_DETAIL_NAME)); + bout.reset(); + } + + @After + public void tearDown() + throws IOException, ExecutionException, InterruptedException, TimeoutException { + // No delete method for VOD sessions + DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); + String output = bout.toString(); + assertThat(output, containsString("Deleted VOD config")); + bout.reset(); + System.setOut(originalOut); + } +} From e2124fe5fb624c734611ca66d241ebb899fb4f97 Mon Sep 17 00:00:00 2001 From: Nick Cook Date: Thu, 18 Jul 2024 14:50:00 -0700 Subject: [PATCH 6/7] update local var to test var --- .../src/test/java/com/example/stitcher/TestUtils.java | 2 ++ .../src/test/java/com/example/stitcher/VodConfigTest.java | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/media/stitcher/src/test/java/com/example/stitcher/TestUtils.java b/media/stitcher/src/test/java/com/example/stitcher/TestUtils.java index 7cebbe7d176..ac66dbdbc72 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/TestUtils.java +++ b/media/stitcher/src/test/java/com/example/stitcher/TestUtils.java @@ -63,6 +63,8 @@ public class TestUtils { "https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_ad_samples&sz=640x480&cust_params=sample_ct%3Dlinear&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator="; public static final String VOD_URI = "https://storage.googleapis.com/cloud-samples-data/media/hls-vod/manifest.m3u8"; + public static final String UPDATED_VOD_URI = + "https://storage.googleapis.com/cloud-samples-data/media/hls-vod/manifest.mpd"; // VMAP Pre-roll // (https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/tags) public static final String VOD_AD_TAG_URI = diff --git a/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java index ae69f605480..2dfea844387 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java @@ -104,13 +104,11 @@ public void testListVodConfigs() throws IOException { @Test public void testUpdateVodConfig() throws IOException, ExecutionException, InterruptedException, TimeoutException { - String UPDATED_VOD_URI = - "https://storage.googleapis.com/cloud-samples-data/media/hls-vod/manifest.mpd"; VodConfig response = UpdateVodConfig.updateVodConfig( - PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, UPDATED_VOD_URI); + PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.UPDATED_VOD_URI); assertThat(response.getName(), containsString(VOD_CONFIG_NAME)); - assertThat(response.getSourceUri(), containsString(UPDATED_VOD_URI)); + assertThat(response.getSourceUri(), containsString(TestUtils.UPDATED_VOD_URI)); bout.reset(); } From 73c44785300ea9b08d68de15ccd127c194c90bc4 Mon Sep 17 00:00:00 2001 From: Nick Cook Date: Fri, 26 Jul 2024 20:16:17 -0700 Subject: [PATCH 7/7] refactor VOD tests --- .../com/example/stitcher/VodConfigTest.java | 32 ++++++++-------- .../com/example/stitcher/VodSessionTest.java | 37 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java index 2dfea844387..b72b75d2494 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java @@ -29,7 +29,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import org.junit.After; -import org.junit.Before; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -44,7 +44,7 @@ public class VodConfigTest { private static String VOD_CONFIG_NAME; private static String PROJECT_ID; private static PrintStream originalOut; - private ByteArrayOutputStream bout; + private static ByteArrayOutputStream bout; private static String requireEnvVar(String varName) { String varValue = System.getenv(varName); @@ -54,19 +54,17 @@ private static String requireEnvVar(String varName) { } @BeforeClass - public static void checkRequirements() { + public static void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); + VOD_CONFIG_NAME = String.format("locations/%s/vodConfigs/%s", TestUtils.LOCATION, VOD_CONFIG_ID); VodConfig response = @@ -77,14 +75,12 @@ public void beforeTest() TestUtils.VOD_URI, TestUtils.VOD_AD_TAG_URI); assertThat(response.getName(), containsString(VOD_CONFIG_NAME)); - bout.reset(); } @Test public void testGetVodConfig() throws IOException { VodConfig response = GetVodConfig.getVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); assertThat(response.getName(), containsString(VOD_CONFIG_NAME)); - bout.reset(); } @Test @@ -95,10 +91,10 @@ public void testListVodConfigs() throws IOException { for (VodConfig vodConfig : response.iterateAll()) { if (vodConfig.getName().contains(VOD_CONFIG_NAME)) { pass = true; + break; } } assert (pass); - bout.reset(); } @Test @@ -109,16 +105,20 @@ public void testUpdateVodConfig() PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID, TestUtils.UPDATED_VOD_URI); assertThat(response.getName(), containsString(VOD_CONFIG_NAME)); assertThat(response.getSourceUri(), containsString(TestUtils.UPDATED_VOD_URI)); - bout.reset(); } @After - public void tearDown() + public void tearDown() { + bout.reset(); + } + + @AfterClass + public static void afterTest() throws IOException, ExecutionException, InterruptedException, TimeoutException { DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - String output = bout.toString(); - assertThat(output, containsString("Deleted VOD config")); - bout.reset(); + String deleteResponse = bout.toString(); + assertThat(deleteResponse, containsString("Deleted VOD config")); + System.out.flush(); System.setOut(originalOut); } } diff --git a/media/stitcher/src/test/java/com/example/stitcher/VodSessionTest.java b/media/stitcher/src/test/java/com/example/stitcher/VodSessionTest.java index ce2b82bbc2b..fc1fd4bf82e 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/VodSessionTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/VodSessionTest.java @@ -33,7 +33,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import org.junit.After; -import org.junit.Before; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -55,7 +55,7 @@ public class VodSessionTest { private static String STITCH_DETAIL_ID; private static String PROJECT_ID; private static PrintStream originalOut; - private ByteArrayOutputStream bout; + private static ByteArrayOutputStream bout; private static String requireEnvVar(String varName) { String varValue = System.getenv(varName); @@ -65,19 +65,17 @@ private static String requireEnvVar(String varName) { } @BeforeClass - public static void checkRequirements() { + public static void beforeTest() + throws IOException, ExecutionException, InterruptedException, TimeoutException { requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - @Before - public void beforeTest() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); + TestUtils.cleanStaleVodConfigs(PROJECT_ID, TestUtils.LOCATION); + VOD_CONFIG_NAME = String.format("locations/%s/vodConfigs/%s", TestUtils.LOCATION, VOD_CONFIG_ID); VodConfig configResponse = @@ -114,29 +112,27 @@ public void beforeTest() } id = STITCH_DETAIL_NAME.split("/"); STITCH_DETAIL_ID = id[id.length - 1]; - - bout.reset(); } @Test public void testGetVodSession() throws IOException { VodSession response = GetVodSession.getVodSession(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); assertThat(response.getName(), containsString(VOD_SESSION_NAME)); - bout.reset(); } @Test public void testListVodAdTagDetailsTest() throws IOException { ListVodAdTagDetailsPagedResponse response = ListVodAdTagDetails.listVodAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + Boolean pass = false; for (VodAdTagDetail vodAdTagDetail : response.iterateAll()) { if (vodAdTagDetail.getName().contains(VOD_SESSION_NAME.concat("/vodAdTagDetails/"))) { pass = true; + break; } } assert (pass); - bout.reset(); } @Test @@ -145,7 +141,6 @@ public void testGetVodAdTagDetailTest() throws IOException { GetVodAdTagDetail.getVodAdTagDetail( PROJECT_ID, TestUtils.LOCATION, SESSION_ID, AD_TAG_DETAIL_ID); assertThat(response.getName(), containsString(AD_TAG_DETAIL_NAME)); - bout.reset(); } @Test @@ -156,10 +151,10 @@ public void testListVodStitchDetailsTest() throws IOException { for (VodStitchDetail vodStitchDetail : response.iterateAll()) { if (vodStitchDetail.getName().contains(VOD_SESSION_NAME.concat("/vodStitchDetails/"))) { pass = true; + break; } } assert (pass); - bout.reset(); } @Test @@ -168,17 +163,21 @@ public void testGetVodStitchDetailTest() throws IOException { GetVodStitchDetail.getVodStitchDetail( PROJECT_ID, TestUtils.LOCATION, SESSION_ID, STITCH_DETAIL_ID); assertThat(response.getName(), containsString(STITCH_DETAIL_NAME)); - bout.reset(); } @After - public void tearDown() + public void tearDown() { + bout.reset(); + } + + @AfterClass + public static void afterTest() throws IOException, ExecutionException, InterruptedException, TimeoutException { // No delete method for VOD sessions DeleteVodConfig.deleteVodConfig(PROJECT_ID, TestUtils.LOCATION, VOD_CONFIG_ID); - String output = bout.toString(); - assertThat(output, containsString("Deleted VOD config")); - bout.reset(); + String deleteResponse = bout.toString(); + assertThat(deleteResponse, containsString("Deleted VOD config")); + System.out.flush(); System.setOut(originalOut); } }