diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateCdnKey.java b/media/stitcher/src/main/java/com/example/stitcher/CreateCdnKey.java index 5c33e45e49b..7bdee260d98 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateCdnKey.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateCdnKey.java @@ -51,7 +51,7 @@ public static void main(String[] args) throws Exception { // createCdnKey creates a Media CDN key or a Cloud CDN key. A CDN key is used to retrieve // protected media. - public static void createCdnKey( + public static CdnKey createCdnKey( String projectId, String location, String cdnKeyId, @@ -61,45 +61,46 @@ public static void createCdnKey( Boolean isMediaCdn) 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(); - CdnKey cdnKey; - if (isMediaCdn) { - cdnKey = - CdnKey.newBuilder() - .setHostname(hostname) - .setMediaCdnKey( - MediaCdnKey.newBuilder() - .setKeyName(keyName) - .setPrivateKey(ByteString.copyFromUtf8(privateKey)) - .build()) - .build(); - } else { - cdnKey = - CdnKey.newBuilder() - .setHostname(hostname) - .setGoogleCdnKey( - GoogleCdnKey.newBuilder() - .setKeyName(keyName) - .setPrivateKey(ByteString.copyFromUtf8(privateKey)) - .build()) - .build(); - } + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + CdnKey cdnKey; + if (isMediaCdn) { + cdnKey = + CdnKey.newBuilder() + .setHostname(hostname) + .setMediaCdnKey( + MediaCdnKey.newBuilder() + .setKeyName(keyName) + .setPrivateKey(ByteString.copyFromUtf8(privateKey)) + .build()) + .build(); + } else { + cdnKey = + CdnKey.newBuilder() + .setHostname(hostname) + .setGoogleCdnKey( + GoogleCdnKey.newBuilder() + .setKeyName(keyName) + .setPrivateKey(ByteString.copyFromUtf8(privateKey)) + .build()) + .build(); + } - CreateCdnKeyRequest createCdnKeyRequest = - CreateCdnKeyRequest.newBuilder() - .setParent(LocationName.of(projectId, location).toString()) - .setCdnKeyId(cdnKeyId) - .setCdnKey(cdnKey) - .build(); + CreateCdnKeyRequest createCdnKeyRequest = + CreateCdnKeyRequest.newBuilder() + .setParent(LocationName.of(projectId, location).toString()) + .setCdnKeyId(cdnKeyId) + .setCdnKey(cdnKey) + .build(); - CdnKey result = - videoStitcherServiceClient - .createCdnKeyAsync(createCdnKeyRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Created new CDN key: " + result.getName()); - videoStitcherServiceClient.close(); + CdnKey result = + videoStitcherServiceClient + .createCdnKeyAsync(createCdnKeyRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Created new CDN key: " + result.getName()); + return result; + } } } // [END videostitcher_create_cdn_key] diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateCdnKeyAkamai.java b/media/stitcher/src/main/java/com/example/stitcher/CreateCdnKeyAkamai.java index 35932096be9..bc1bfbde318 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateCdnKeyAkamai.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateCdnKeyAkamai.java @@ -45,35 +45,36 @@ public static void main(String[] args) throws Exception { } // createCdnKeyAkamai creates an Akamai CDN key. A CDN key is used to retrieve protected media. - public static void createCdnKeyAkamai( + public static CdnKey createCdnKeyAkamai( String projectId, String location, String cdnKeyId, String hostname, String akamaiTokenKey) 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(); - CdnKey cdnKey = - CdnKey.newBuilder() - .setHostname(hostname) - .setAkamaiCdnKey( - AkamaiCdnKey.newBuilder() - .setTokenKey(ByteString.copyFromUtf8(akamaiTokenKey)) - .build()) - .build(); + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + CdnKey cdnKey = + CdnKey.newBuilder() + .setHostname(hostname) + .setAkamaiCdnKey( + AkamaiCdnKey.newBuilder() + .setTokenKey(ByteString.copyFromUtf8(akamaiTokenKey)) + .build()) + .build(); - CreateCdnKeyRequest createCdnKeyRequest = - CreateCdnKeyRequest.newBuilder() - .setParent(LocationName.of(projectId, location).toString()) - .setCdnKeyId(cdnKeyId) - .setCdnKey(cdnKey) - .build(); + CreateCdnKeyRequest createCdnKeyRequest = + CreateCdnKeyRequest.newBuilder() + .setParent(LocationName.of(projectId, location).toString()) + .setCdnKeyId(cdnKeyId) + .setCdnKey(cdnKey) + .build(); - CdnKey result = - videoStitcherServiceClient - .createCdnKeyAsync(createCdnKeyRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Created new CDN key: " + result.getName()); - videoStitcherServiceClient.close(); + CdnKey result = + videoStitcherServiceClient + .createCdnKeyAsync(createCdnKeyRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Created new CDN key: " + result.getName()); + return result; + } } } // [END videostitcher_create_cdn_key_akamai] diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateLiveConfig.java b/media/stitcher/src/main/java/com/example/stitcher/CreateLiveConfig.java index 1ce28a71553..6b5500cd02e 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateLiveConfig.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateLiveConfig.java @@ -50,7 +50,10 @@ public static void main(String[] args) throws Exception { createLiveConfig(projectId, location, liveConfigId, sourceUri, adTagUri, slateId); } - public static void createLiveConfig( + // Creates a live config. Live configs are used to configure live sessions. + // For more information, see + // https://cloud.google.com/video-stitcher/docs/how-to/managing-live-configs. + public static LiveConfig createLiveConfig( String projectId, String location, String liveConfigId, @@ -59,29 +62,30 @@ public static void createLiveConfig( String slateId) 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(); - CreateLiveConfigRequest createLiveConfigRequest = - CreateLiveConfigRequest.newBuilder() - .setParent(LocationName.of(projectId, location).toString()) - .setLiveConfigId(liveConfigId) - .setLiveConfig( - LiveConfig.newBuilder() - .setSourceUri(sourceUri) - .setAdTagUri(adTagUri) - .setDefaultSlate(SlateName.format(projectId, location, slateId)) - .setAdTracking(AdTracking.SERVER) - .setStitchingPolicy(StitchingPolicy.CUT_CURRENT) - .build()) - .build(); + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + CreateLiveConfigRequest createLiveConfigRequest = + CreateLiveConfigRequest.newBuilder() + .setParent(LocationName.of(projectId, location).toString()) + .setLiveConfigId(liveConfigId) + .setLiveConfig( + LiveConfig.newBuilder() + .setSourceUri(sourceUri) + .setAdTagUri(adTagUri) + .setDefaultSlate(SlateName.format(projectId, location, slateId)) + .setAdTracking(AdTracking.SERVER) + .setStitchingPolicy(StitchingPolicy.CUT_CURRENT) + .build()) + .build(); - LiveConfig response = - videoStitcherServiceClient - .createLiveConfigAsync(createLiveConfigRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Created new live config: " + response.getName()); - videoStitcherServiceClient.close(); + LiveConfig response = + videoStitcherServiceClient + .createLiveConfigAsync(createLiveConfigRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Created new live config: " + response.getName()); + return response; + } } } // [END videostitcher_create_live_config] diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateLiveSession.java b/media/stitcher/src/main/java/com/example/stitcher/CreateLiveSession.java index cc0b3020ba0..7e84d8d02af 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateLiveSession.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateLiveSession.java @@ -36,11 +36,13 @@ public static void main(String[] args) throws Exception { createLiveSession(projectId, location, liveConfigId); } - public static void createLiveSession(String projectId, String location, String liveConfigId) - throws IOException { + // Creates a live session given the parameters in the supplied live config. + // For more information, see + // https://cloud.google.com/video-stitcher/docs/how-to/managing-live-sessions. + public static LiveSession createLiveSession( + String projectId, String location, String liveConfigId) 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()) { CreateLiveSessionRequest createLiveSessionRequest = @@ -54,6 +56,7 @@ public static void createLiveSession(String projectId, String location, String l LiveSession response = videoStitcherServiceClient.createLiveSession(createLiveSessionRequest); System.out.println("Created live session: " + response.getName()); System.out.println("Play URI: " + response.getPlayUri()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/CreateSlate.java b/media/stitcher/src/main/java/com/example/stitcher/CreateSlate.java index 31e2a26099d..c051507d7ac 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateSlate.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateSlate.java @@ -42,25 +42,30 @@ public static void main(String[] args) throws Exception { createSlate(projectId, location, slateId, slateUri); } - public static void createSlate(String projectId, String location, String slateId, String slateUri) + // Creates a slate. Slates are content that can be served when there are gaps in a livestream + // ad break that cannot be filled with a dynamically served ad. For more information, see + // https://cloud.google.com/video-stitcher/docs/how-to/managing-slates. + public static Slate createSlate( + String projectId, String location, String slateId, String slateUri) 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(); - CreateSlateRequest createSlateRequest = - CreateSlateRequest.newBuilder() - .setParent(LocationName.of(projectId, location).toString()) - .setSlateId(slateId) - .setSlate(Slate.newBuilder().setUri(slateUri).build()) - .build(); + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + CreateSlateRequest createSlateRequest = + CreateSlateRequest.newBuilder() + .setParent(LocationName.of(projectId, location).toString()) + .setSlateId(slateId) + .setSlate(Slate.newBuilder().setUri(slateUri).build()) + .build(); - Slate response = - videoStitcherServiceClient - .createSlateAsync(createSlateRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Created new slate: " + response.getName()); - videoStitcherServiceClient.close(); + Slate response = + videoStitcherServiceClient + .createSlateAsync(createSlateRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Created new slate: " + response.getName()); + return response; + } } } // [END videostitcher_create_slate] 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 7076c90835e..c85e2ae263f 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/CreateVodSession.java +++ b/media/stitcher/src/main/java/com/example/stitcher/CreateVodSession.java @@ -38,6 +38,8 @@ public static void main(String[] args) throws Exception { } // Creates a video on demand (VOD) session using the parameters in the designated VOD config. + // For more information, see + // https://cloud.google.com/video-stitcher/docs/how-to/creating-vod-sessions. 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 diff --git a/media/stitcher/src/main/java/com/example/stitcher/DeleteCdnKey.java b/media/stitcher/src/main/java/com/example/stitcher/DeleteCdnKey.java index 98311e33fb1..bc97822710d 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/DeleteCdnKey.java +++ b/media/stitcher/src/main/java/com/example/stitcher/DeleteCdnKey.java @@ -39,22 +39,23 @@ public static void main(String[] args) throws Exception { deleteCdnKey(projectId, location, cdnKeyId); } + // Deletes a CDN key. public static void deleteCdnKey(String projectId, String location, String cdnKeyId) throws InterruptedException, ExecutionException, TimeoutException, 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. 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(); - DeleteCdnKeyRequest deleteCdnKeyRequest = - DeleteCdnKeyRequest.newBuilder() - .setName(CdnKeyName.of(projectId, location, cdnKeyId).toString()) - .build(); - - videoStitcherServiceClient - .deleteCdnKeyAsync(deleteCdnKeyRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Deleted CDN key"); - videoStitcherServiceClient.close(); + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + DeleteCdnKeyRequest deleteCdnKeyRequest = + DeleteCdnKeyRequest.newBuilder() + .setName(CdnKeyName.of(projectId, location, cdnKeyId).toString()) + .build(); + + videoStitcherServiceClient + .deleteCdnKeyAsync(deleteCdnKeyRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Deleted CDN key"); + } } } // [END videostitcher_delete_cdn_key] diff --git a/media/stitcher/src/main/java/com/example/stitcher/DeleteLiveConfig.java b/media/stitcher/src/main/java/com/example/stitcher/DeleteLiveConfig.java index efe30973446..69d3f04cbd2 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/DeleteLiveConfig.java +++ b/media/stitcher/src/main/java/com/example/stitcher/DeleteLiveConfig.java @@ -39,22 +39,23 @@ public static void main(String[] args) throws Exception { deleteLiveConfig(projectId, location, liveConfigId); } + // Deletes a live config. public static void deleteLiveConfig(String projectId, String location, String liveConfigId) 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(); - DeleteLiveConfigRequest deleteLiveConfigRequest = - DeleteLiveConfigRequest.newBuilder() - .setName(LiveConfigName.of(projectId, location, liveConfigId).toString()) - .build(); - - videoStitcherServiceClient - .deleteLiveConfigAsync(deleteLiveConfigRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Deleted live config"); - videoStitcherServiceClient.close(); + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + DeleteLiveConfigRequest deleteLiveConfigRequest = + DeleteLiveConfigRequest.newBuilder() + .setName(LiveConfigName.of(projectId, location, liveConfigId).toString()) + .build(); + + videoStitcherServiceClient + .deleteLiveConfigAsync(deleteLiveConfigRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Deleted live config"); + } } } // [END videostitcher_delete_live_config] diff --git a/media/stitcher/src/main/java/com/example/stitcher/DeleteSlate.java b/media/stitcher/src/main/java/com/example/stitcher/DeleteSlate.java index faf5ab091ab..875ff4dd2dc 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/DeleteSlate.java +++ b/media/stitcher/src/main/java/com/example/stitcher/DeleteSlate.java @@ -39,22 +39,23 @@ public static void main(String[] args) throws Exception { deleteSlate(projectId, location, slateId); } + // Deletes a slate. public static void deleteSlate(String projectId, String location, String slateId) 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(); - DeleteSlateRequest deleteSlateRequest = - DeleteSlateRequest.newBuilder() - .setName(SlateName.of(projectId, location, slateId).toString()) - .build(); - - videoStitcherServiceClient - .deleteSlateAsync(deleteSlateRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Deleted slate"); - videoStitcherServiceClient.close(); + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + DeleteSlateRequest deleteSlateRequest = + DeleteSlateRequest.newBuilder() + .setName(SlateName.of(projectId, location, slateId).toString()) + .build(); + + videoStitcherServiceClient + .deleteSlateAsync(deleteSlateRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Deleted slate"); + } } } // [END videostitcher_delete_slate] diff --git a/media/stitcher/src/main/java/com/example/stitcher/GetCdnKey.java b/media/stitcher/src/main/java/com/example/stitcher/GetCdnKey.java index 9b6c7f0401f..10ca42cfe62 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/GetCdnKey.java +++ b/media/stitcher/src/main/java/com/example/stitcher/GetCdnKey.java @@ -35,11 +35,11 @@ public static void main(String[] args) throws Exception { getCdnKey(projectId, location, cdnKeyId); } - public static void getCdnKey(String projectId, String location, String cdnKeyId) + // Gets a CDN key. + public static CdnKey getCdnKey(String projectId, String location, String cdnKeyId) 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()) { GetCdnKeyRequest getCdnKeyRequest = @@ -49,6 +49,7 @@ public static void getCdnKey(String projectId, String location, String cdnKeyId) CdnKey response = videoStitcherServiceClient.getCdnKey(getCdnKeyRequest); System.out.println("CDN key: " + response.getName()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/GetLiveAdTagDetail.java b/media/stitcher/src/main/java/com/example/stitcher/GetLiveAdTagDetail.java index 50fb910c940..482dc74f85c 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/GetLiveAdTagDetail.java +++ b/media/stitcher/src/main/java/com/example/stitcher/GetLiveAdTagDetail.java @@ -36,12 +36,12 @@ public static void main(String[] args) throws Exception { getLiveAdTagDetail(projectId, location, sessionId, adTagDetailId); } - public static void getLiveAdTagDetail( + // Gets a live ad tag detail in a live session. + public static LiveAdTagDetail getLiveAdTagDetail( 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()) { GetLiveAdTagDetailRequest getLiveAdTagDetailRequest = @@ -53,6 +53,7 @@ public static void getLiveAdTagDetail( LiveAdTagDetail response = videoStitcherServiceClient.getLiveAdTagDetail(getLiveAdTagDetailRequest); System.out.println("Live ad tag detail: " + response.getName()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/GetLiveConfig.java b/media/stitcher/src/main/java/com/example/stitcher/GetLiveConfig.java index ef608dc2fd2..1acaca23ee3 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/GetLiveConfig.java +++ b/media/stitcher/src/main/java/com/example/stitcher/GetLiveConfig.java @@ -35,11 +35,11 @@ public static void main(String[] args) throws Exception { getLiveConfig(projectId, location, liveConfigId); } - public static void getLiveConfig(String projectId, String location, String liveConfigId) + // Gets a live config. + public static LiveConfig getLiveConfig(String projectId, String location, String liveConfigId) 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()) { GetLiveConfigRequest getLiveConfigRequest = @@ -49,6 +49,7 @@ public static void getLiveConfig(String projectId, String location, String liveC LiveConfig response = videoStitcherServiceClient.getLiveConfig(getLiveConfigRequest); System.out.println("Live config: " + response.getName()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/GetLiveSession.java b/media/stitcher/src/main/java/com/example/stitcher/GetLiveSession.java index 04d77ec8b9e..3f6df3f7fdc 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/GetLiveSession.java +++ b/media/stitcher/src/main/java/com/example/stitcher/GetLiveSession.java @@ -35,11 +35,11 @@ public static void main(String[] args) throws Exception { getLiveSession(projectId, location, sessionId); } - public static void getLiveSession(String projectId, String location, String sessionId) + // Gets a live session. + public static LiveSession getLiveSession(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()) { GetLiveSessionRequest getLiveSessionRequest = @@ -49,6 +49,7 @@ public static void getLiveSession(String projectId, String location, String sess LiveSession response = videoStitcherServiceClient.getLiveSession(getLiveSessionRequest); System.out.println("Live session: " + response.getName()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/GetSlate.java b/media/stitcher/src/main/java/com/example/stitcher/GetSlate.java index 7ae993860ee..6897cda5c92 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/GetSlate.java +++ b/media/stitcher/src/main/java/com/example/stitcher/GetSlate.java @@ -35,11 +35,11 @@ public static void main(String[] args) throws Exception { getSlate(projectId, location, slateId); } - public static void getSlate(String projectId, String location, String slateId) + // Gets a slate. + public static Slate getSlate(String projectId, String location, String slateId) 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()) { GetSlateRequest getSlateRequest = @@ -49,6 +49,7 @@ public static void getSlate(String projectId, String location, String slateId) Slate response = videoStitcherServiceClient.getSlate(getSlateRequest); System.out.println("Slate: " + response.getName()); + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/ListCdnKeys.java b/media/stitcher/src/main/java/com/example/stitcher/ListCdnKeys.java index 3bd40e02ae4..dfd9d407b81 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/ListCdnKeys.java +++ b/media/stitcher/src/main/java/com/example/stitcher/ListCdnKeys.java @@ -22,6 +22,7 @@ import com.google.cloud.video.stitcher.v1.ListCdnKeysRequest; import com.google.cloud.video.stitcher.v1.LocationName; import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListCdnKeysPagedResponse; import java.io.IOException; public class ListCdnKeys { @@ -34,10 +35,11 @@ public static void main(String[] args) throws Exception { listCdnKeys(projectId, location); } - public static void listCdnKeys(String projectId, String location) throws IOException { + // Lists the CDN keys for a given project and location. + public static ListCdnKeysPagedResponse listCdnKeys(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()) { ListCdnKeysRequest listCdnKeysRequest = @@ -47,11 +49,12 @@ public static void listCdnKeys(String projectId, String location) throws IOExcep VideoStitcherServiceClient.ListCdnKeysPagedResponse response = videoStitcherServiceClient.listCdnKeys(listCdnKeysRequest); - System.out.println("CDN keys:"); + System.out.println("CDN keys:"); for (CdnKey cdnKey : response.iterateAll()) { System.out.println(cdnKey.getName()); } + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/ListLiveAdTagDetails.java b/media/stitcher/src/main/java/com/example/stitcher/ListLiveAdTagDetails.java index 9dae004ad1d..a03ef0b1b3a 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/ListLiveAdTagDetails.java +++ b/media/stitcher/src/main/java/com/example/stitcher/ListLiveAdTagDetails.java @@ -22,6 +22,7 @@ import com.google.cloud.video.stitcher.v1.LiveAdTagDetail; import com.google.cloud.video.stitcher.v1.LiveSessionName; import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListLiveAdTagDetailsPagedResponse; import java.io.IOException; public class ListLiveAdTagDetails { @@ -35,11 +36,11 @@ public static void main(String[] args) throws Exception { listLiveAdTagDetails(projectId, location, sessionId); } - public static void listLiveAdTagDetails(String projectId, String location, String sessionId) - throws IOException { + // Lists the live ad tag details for a given live session. + public static ListLiveAdTagDetailsPagedResponse listLiveAdTagDetails( + 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()) { ListLiveAdTagDetailsRequest listLiveAdTagDetailsRequest = @@ -49,11 +50,12 @@ public static void listLiveAdTagDetails(String projectId, String location, Strin VideoStitcherServiceClient.ListLiveAdTagDetailsPagedResponse response = videoStitcherServiceClient.listLiveAdTagDetails(listLiveAdTagDetailsRequest); - System.out.println("Live ad tag details:"); + System.out.println("Live ad tag details:"); for (LiveAdTagDetail adTagDetail : response.iterateAll()) { System.out.println(adTagDetail.toString()); } + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/ListLiveConfigs.java b/media/stitcher/src/main/java/com/example/stitcher/ListLiveConfigs.java index a6fb12e20aa..557c0fab8be 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/ListLiveConfigs.java +++ b/media/stitcher/src/main/java/com/example/stitcher/ListLiveConfigs.java @@ -22,6 +22,7 @@ import com.google.cloud.video.stitcher.v1.LiveConfig; import com.google.cloud.video.stitcher.v1.LocationName; import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListLiveConfigsPagedResponse; import java.io.IOException; public class ListLiveConfigs { @@ -34,10 +35,11 @@ public static void main(String[] args) throws Exception { listLiveConfigs(projectId, location); } - public static void listLiveConfigs(String projectId, String location) throws IOException { + // Lists the live configs for a given project and location. + public static ListLiveConfigsPagedResponse listLiveConfigs(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()) { ListLiveConfigsRequest listLiveConfigsRequest = @@ -47,11 +49,12 @@ public static void listLiveConfigs(String projectId, String location) throws IOE VideoStitcherServiceClient.ListLiveConfigsPagedResponse response = videoStitcherServiceClient.listLiveConfigs(listLiveConfigsRequest); - System.out.println("Live configs:"); + System.out.println("Live configs:"); for (LiveConfig liveConfig : response.iterateAll()) { System.out.println(liveConfig.getName()); } + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/ListSlates.java b/media/stitcher/src/main/java/com/example/stitcher/ListSlates.java index af8bd7c46e1..c3a5c4fe721 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/ListSlates.java +++ b/media/stitcher/src/main/java/com/example/stitcher/ListSlates.java @@ -22,6 +22,7 @@ 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.VideoStitcherServiceClient.ListSlatesPagedResponse; import java.io.IOException; public class ListSlates { @@ -34,10 +35,11 @@ public static void main(String[] args) throws Exception { listSlates(projectId, location); } - public static void listSlates(String projectId, String location) throws IOException { + // Lists the slates for a given project and location. + public static ListSlatesPagedResponse listSlates(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()) { ListSlatesRequest listSlatesRequest = @@ -47,11 +49,12 @@ public static void listSlates(String projectId, String location) throws IOExcept VideoStitcherServiceClient.ListSlatesPagedResponse response = videoStitcherServiceClient.listSlates(listSlatesRequest); - System.out.println("Slates:"); + System.out.println("Slates:"); for (Slate slate : response.iterateAll()) { System.out.println(slate.getName()); } + return response; } } } diff --git a/media/stitcher/src/main/java/com/example/stitcher/UpdateCdnKey.java b/media/stitcher/src/main/java/com/example/stitcher/UpdateCdnKey.java index 9743d937464..ae158fa57e8 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/UpdateCdnKey.java +++ b/media/stitcher/src/main/java/com/example/stitcher/UpdateCdnKey.java @@ -52,7 +52,7 @@ public static void main(String[] args) throws Exception { // updateCdnKey updates the hostname and key fields for an existing Media CDN key or Cloud // CDN key. - public static void updateCdnKey( + public static CdnKey updateCdnKey( String projectId, String location, String cdnKeyId, @@ -62,51 +62,52 @@ public static void updateCdnKey( Boolean isMediaCdn) 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(); - CdnKey cdnKey; - String path; - if (isMediaCdn) { - path = "media_cdn_key"; - cdnKey = - CdnKey.newBuilder() - .setName(CdnKeyName.of(projectId, location, cdnKeyId).toString()) - .setHostname(hostname) - .setMediaCdnKey( - MediaCdnKey.newBuilder() - .setKeyName(keyName) - .setPrivateKey(ByteString.copyFromUtf8(privateKey)) - .build()) - .build(); - } else { - path = "google_cdn_key"; - cdnKey = - CdnKey.newBuilder() - .setName(CdnKeyName.of(projectId, location, cdnKeyId).toString()) - .setHostname(hostname) - .setGoogleCdnKey( - GoogleCdnKey.newBuilder() - .setKeyName(keyName) - .setPrivateKey(ByteString.copyFromUtf8(privateKey)) - .build()) - .build(); - } + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + CdnKey cdnKey; + String path; + if (isMediaCdn) { + path = "media_cdn_key"; + cdnKey = + CdnKey.newBuilder() + .setName(CdnKeyName.of(projectId, location, cdnKeyId).toString()) + .setHostname(hostname) + .setMediaCdnKey( + MediaCdnKey.newBuilder() + .setKeyName(keyName) + .setPrivateKey(ByteString.copyFromUtf8(privateKey)) + .build()) + .build(); + } else { + path = "google_cdn_key"; + cdnKey = + CdnKey.newBuilder() + .setName(CdnKeyName.of(projectId, location, cdnKeyId).toString()) + .setHostname(hostname) + .setGoogleCdnKey( + GoogleCdnKey.newBuilder() + .setKeyName(keyName) + .setPrivateKey(ByteString.copyFromUtf8(privateKey)) + .build()) + .build(); + } - UpdateCdnKeyRequest updateCdnKeyRequest = - UpdateCdnKeyRequest.newBuilder() - .setCdnKey(cdnKey) - // Update the hostname field and the fields for the specific key type (Media CDN - // or Cloud CDN). You must set the mask to the fields you want to update. - .setUpdateMask(FieldMask.newBuilder().addPaths("hostname").addPaths(path).build()) - .build(); + UpdateCdnKeyRequest updateCdnKeyRequest = + UpdateCdnKeyRequest.newBuilder() + .setCdnKey(cdnKey) + // Update the hostname field and the fields for the specific key type (Media CDN + // or Cloud CDN). You must set the mask to the fields you want to update. + .setUpdateMask(FieldMask.newBuilder().addPaths("hostname").addPaths(path).build()) + .build(); - CdnKey response = - videoStitcherServiceClient - .updateCdnKeyAsync(updateCdnKeyRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Updated CDN key: " + response.getName()); - videoStitcherServiceClient.close(); + CdnKey response = + videoStitcherServiceClient + .updateCdnKeyAsync(updateCdnKeyRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Updated CDN key: " + response.getName()); + return response; + } } } // [END videostitcher_update_cdn_key] diff --git a/media/stitcher/src/main/java/com/example/stitcher/UpdateCdnKeyAkamai.java b/media/stitcher/src/main/java/com/example/stitcher/UpdateCdnKeyAkamai.java index a3192857124..af73df72ca9 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/UpdateCdnKeyAkamai.java +++ b/media/stitcher/src/main/java/com/example/stitcher/UpdateCdnKeyAkamai.java @@ -45,39 +45,40 @@ public static void main(String[] args) throws Exception { updateCdnKeyAkamai(projectId, location, cdnKeyId, hostname, akamaiTokenKey); } - // updateCdnKeyAkamai u/**/pdates the hostname and key fields for an existing CDN key. - public static void updateCdnKeyAkamai( + // updateCdnKeyAkamai updates the hostname and key fields for an existing CDN key. + public static CdnKey updateCdnKeyAkamai( String projectId, String location, String cdnKeyId, String hostname, String akamaiTokenKey) 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(); - CdnKey cdnKey = - CdnKey.newBuilder() - .setName(CdnKeyName.of(projectId, location, cdnKeyId).toString()) - .setHostname(hostname) - .setAkamaiCdnKey( - AkamaiCdnKey.newBuilder() - .setTokenKey(ByteString.copyFromUtf8(akamaiTokenKey)) - .build()) - .build(); + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + CdnKey cdnKey = + CdnKey.newBuilder() + .setName(CdnKeyName.of(projectId, location, cdnKeyId).toString()) + .setHostname(hostname) + .setAkamaiCdnKey( + AkamaiCdnKey.newBuilder() + .setTokenKey(ByteString.copyFromUtf8(akamaiTokenKey)) + .build()) + .build(); - UpdateCdnKeyRequest updateCdnKeyRequest = - UpdateCdnKeyRequest.newBuilder() - .setCdnKey(cdnKey) - // Update the hostname field and token key field. You must set the mask to the fields - // you want to update. - .setUpdateMask( - FieldMask.newBuilder().addPaths("hostname").addPaths("akamai_cdn_key").build()) - .build(); + UpdateCdnKeyRequest updateCdnKeyRequest = + UpdateCdnKeyRequest.newBuilder() + .setCdnKey(cdnKey) + // Update the hostname field and token key field. You must set the mask to the fields + // you want to update. + .setUpdateMask( + FieldMask.newBuilder().addPaths("hostname").addPaths("akamai_cdn_key").build()) + .build(); - CdnKey response = - videoStitcherServiceClient - .updateCdnKeyAsync(updateCdnKeyRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Updated CDN key: " + response.getName()); - videoStitcherServiceClient.close(); + CdnKey response = + videoStitcherServiceClient + .updateCdnKeyAsync(updateCdnKeyRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Updated CDN key: " + response.getName()); + return response; + } } } // [END videostitcher_update_cdn_key_akamai] diff --git a/media/stitcher/src/main/java/com/example/stitcher/UpdateSlate.java b/media/stitcher/src/main/java/com/example/stitcher/UpdateSlate.java index b851e5ed150..c0f3fbca7ba 100644 --- a/media/stitcher/src/main/java/com/example/stitcher/UpdateSlate.java +++ b/media/stitcher/src/main/java/com/example/stitcher/UpdateSlate.java @@ -44,30 +44,32 @@ public static void main(String[] args) throws Exception { } // updateSlate updates the slate URI for an existing slate. - public static void updateSlate(String projectId, String location, String slateId, String slateUri) + public static Slate updateSlate( + String projectId, String location, String slateId, String slateUri) 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(); - UpdateSlateRequest updateSlateRequest = - UpdateSlateRequest.newBuilder() - .setSlate( - Slate.newBuilder() - .setName(SlateName.of(projectId, location, slateId).toString()) - .setUri(slateUri) - .build()) - // Set the update mask to the uri field in the existing slate. You must set the mask - // to the field you want to update. - .setUpdateMask(FieldMask.newBuilder().addPaths("uri").build()) - .build(); + // once, and can be reused for multiple requests. + try (VideoStitcherServiceClient videoStitcherServiceClient = + VideoStitcherServiceClient.create()) { + UpdateSlateRequest updateSlateRequest = + UpdateSlateRequest.newBuilder() + .setSlate( + Slate.newBuilder() + .setName(SlateName.of(projectId, location, slateId).toString()) + .setUri(slateUri) + .build()) + // Set the update mask to the uri field in the existing slate. You must set the mask + // to the field you want to update. + .setUpdateMask(FieldMask.newBuilder().addPaths("uri").build()) + .build(); - Slate response = - videoStitcherServiceClient - .updateSlateAsync(updateSlateRequest) - .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); - System.out.println("Updated slate: " + response.getName()); - videoStitcherServiceClient.close(); + Slate response = + videoStitcherServiceClient + .updateSlateAsync(updateSlateRequest) + .get(TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + System.out.println("Updated slate: " + response.getName()); + return response; + } } } // [END videostitcher_update_slate] diff --git a/media/stitcher/src/test/java/com/example/stitcher/UpdateCdnKeyTest.java b/media/stitcher/src/test/java/com/example/stitcher/CdnKeyTest.java similarity index 53% rename from media/stitcher/src/test/java/com/example/stitcher/UpdateCdnKeyTest.java rename to media/stitcher/src/test/java/com/example/stitcher/CdnKeyTest.java index f1da6b0c793..4c847bb312e 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/UpdateCdnKeyTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/CdnKeyTest.java @@ -21,13 +21,15 @@ import static org.junit.Assert.assertNotNull; import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import com.google.cloud.video.stitcher.v1.CdnKey; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListCdnKeysPagedResponse; 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.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -35,22 +37,27 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) -public class UpdateCdnKeyTest { +public class CdnKeyTest { @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); private static final String CLOUD_CDN_KEY_ID = TestUtils.getCdnKeyId(); private static final String MEDIA_CDN_KEY_ID = TestUtils.getCdnKeyId(); + private static final String AKAMAI_KEY_ID = TestUtils.getCdnKeyId(); + private static String PROJECT_ID; + private static String CLOUD_CDN_KEY_NAME; // resource name for the Cloud CDN key + private static String MEDIA_CDN_KEY_NAME; // resource name for the Media CDN key + private static String AKAMAI_KEY_NAME; // resource name for the Akamai CDN key private static final String UPDATED_CLOUD_CDN_PRIVATE_KEY = "VGhpcyBpcyBhbiB1cGRhdGVkIHRlc3Qgc3RyaW5nLg=="; private static final String UPDATED_MEDIA_CDN_PRIVATE_KEY = "ZZZzNDU2Nzg5MDEyMzQ1Njc4OTAxzg5MDEyMzQ1Njc4OTAxMjM0NTY3DkwMTIZZZ"; + private static final String UPDATED_AKAMAI_TOKEN_KEY = + "VGhpcyBpcyBhbiB1cGRhdGVkIHRlc3Qgc3RyaW5nLg=="; - private static String PROJECT_ID; - private static String CLOUD_CDN_KEY_NAME; // resource name for the Cloud CDN key - private static String MEDIA_CDN_KEY_NAME; // resource name for the Media CDN key private static PrintStream originalOut; - private ByteArrayOutputStream bout; + private static ByteArrayOutputStream bout; + private static String requireEnvVar(String varName) { String varValue = System.getenv(varName); @@ -60,41 +67,86 @@ 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.cleanStaleCdnKeys(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); + TestUtils.cleanStaleCdnKeys(PROJECT_ID, TestUtils.LOCATION); + // Cloud CDN key CLOUD_CDN_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, CLOUD_CDN_KEY_ID); - CreateCdnKey.createCdnKey( + // Media CDN key + MEDIA_CDN_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, + MEDIA_CDN_KEY_ID); + // Akamai CDN key + AKAMAI_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, AKAMAI_KEY_ID); + + // Cloud CDN key + CdnKey response = CreateCdnKey.createCdnKey( PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID, TestUtils.HOSTNAME, TestUtils.KEYNAME, TestUtils.CLOUD_CDN_PRIVATE_KEY, false); + assertThat(response.getName(), containsString(CLOUD_CDN_KEY_NAME)); // Media CDN key - MEDIA_CDN_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, - MEDIA_CDN_KEY_ID); - CreateCdnKey.createCdnKey( + response = CreateCdnKey.createCdnKey( PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID, TestUtils.HOSTNAME, TestUtils.KEYNAME, TestUtils.MEDIA_CDN_PRIVATE_KEY, true); + assertThat(response.getName(), containsString(MEDIA_CDN_KEY_NAME)); - bout.reset(); + // Akamai CDN key + response = CreateCdnKeyAkamai.createCdnKeyAkamai( + PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID, TestUtils.HOSTNAME, + TestUtils.AKAMAI_TOKEN_KEY); + assertThat(response.getName(), containsString(AKAMAI_KEY_NAME)); } @Test - public void test_UpdateCdnKey() + public void testGetCdnKey() throws IOException { + // Cloud CDN key + CdnKey response = GetCdnKey.getCdnKey(PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID); + assertThat(response.getName(), containsString(CLOUD_CDN_KEY_NAME)); + + // Media CDN key + response = GetCdnKey.getCdnKey(PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID); + assertThat(response.getName(), containsString(MEDIA_CDN_KEY_NAME)); + + // Akamai CDN key + response = GetCdnKey.getCdnKey(PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID); + assertThat(response.getName(), containsString(AKAMAI_KEY_NAME)); + } + + @Test + public void testListCdnKeys() throws IOException { + // Cloud, Media, and Akamai CDN keys should be present + ListCdnKeysPagedResponse response = + ListCdnKeys.listCdnKeys(PROJECT_ID, TestUtils.LOCATION); + Boolean cloud = false; + Boolean media = false; + Boolean akamai = false; + + for (CdnKey cdnKey : response.iterateAll()) { + if (cdnKey.getName().contains(CLOUD_CDN_KEY_NAME)) { + cloud = true; + } else if (cdnKey.getName().contains(MEDIA_CDN_KEY_NAME)) { + media = true; + } else if (cdnKey.getName().contains(AKAMAI_KEY_NAME)) { + akamai = true; + } + } + assert (cloud && media && akamai); + } + + @Test + public void testUpdateCdnKey() throws IOException, ExecutionException, InterruptedException, TimeoutException { // Cloud CDN key - UpdateCdnKey.updateCdnKey( + CdnKey response = UpdateCdnKey.updateCdnKey( PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID, @@ -102,12 +154,10 @@ public void test_UpdateCdnKey() TestUtils.KEYNAME, UPDATED_CLOUD_CDN_PRIVATE_KEY, false); - String output = bout.toString(); - assertThat(output, containsString(CLOUD_CDN_KEY_NAME)); - bout.reset(); + assertThat(response.getName(), containsString(CLOUD_CDN_KEY_NAME)); // Media CDN key - UpdateCdnKey.updateCdnKey( + response = UpdateCdnKey.updateCdnKey( PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID, @@ -115,19 +165,41 @@ public void test_UpdateCdnKey() TestUtils.KEYNAME, UPDATED_MEDIA_CDN_PRIVATE_KEY, true); - output = bout.toString(); - assertThat(output, containsString(MEDIA_CDN_KEY_NAME)); - bout.reset(); + assertThat(response.getName(), containsString(MEDIA_CDN_KEY_NAME)); + + // Akamai CDN key + response = UpdateCdnKeyAkamai.updateCdnKeyAkamai( + PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID, TestUtils.UPDATED_HOSTNAME, + UPDATED_AKAMAI_TOKEN_KEY); + assertThat(response.getName(), containsString(AKAMAI_KEY_NAME)); } @After - public void tearDown() + public void tearDown() { + bout.reset(); + } + + @AfterClass + public static void afterTest() throws IOException, ExecutionException, InterruptedException, TimeoutException { // Cloud CDN key DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID); + String deleteResponse = bout.toString(); + assertThat(deleteResponse, containsString("Deleted CDN key")); + bout.reset(); + // Media CDN key DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID); - System.setOut(originalOut); + deleteResponse = bout.toString(); + assertThat(deleteResponse, containsString("Deleted CDN key")); bout.reset(); + + // Akamai CDN key + DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID); + deleteResponse = bout.toString(); + assertThat(deleteResponse, containsString("Deleted CDN key")); + + System.out.flush(); + System.setOut(originalOut); } } diff --git a/media/stitcher/src/test/java/com/example/stitcher/CreateCdnKeyAkamaiTest.java b/media/stitcher/src/test/java/com/example/stitcher/CreateCdnKeyAkamaiTest.java deleted file mode 100644 index adb7fb70a2b..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/CreateCdnKeyAkamaiTest.java +++ /dev/null @@ -1,89 +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 CreateCdnKeyAkamaiTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String AKAMAI_KEY_ID = TestUtils.getCdnKeyId(); - private static String PROJECT_ID; - private static String AKAMAI_KEY_NAME; // resource name for the Akamai CDN key - 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 { - TestUtils.cleanStaleCdnKeys(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - AKAMAI_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, AKAMAI_KEY_ID); - bout.reset(); - } - - @Test - public void test_CreateCdnKeyAkamai() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - CreateCdnKeyAkamai.createCdnKeyAkamai( - PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID, TestUtils.HOSTNAME, - TestUtils.AKAMAI_TOKEN_KEY); - String output = bout.toString(); - assertThat(output, containsString(AKAMAI_KEY_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/CreateCdnKeyTest.java b/media/stitcher/src/test/java/com/example/stitcher/CreateCdnKeyTest.java deleted file mode 100644 index a9428c60a70..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/CreateCdnKeyTest.java +++ /dev/null @@ -1,108 +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 CreateCdnKeyTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String CLOUD_CDN_KEY_ID = TestUtils.getCdnKeyId(); - private static final String MEDIA_CDN_KEY_ID = TestUtils.getCdnKeyId(); - private static String PROJECT_ID; - private static String CLOUD_CDN_KEY_NAME; // resource name for the Cloud CDN key - private static String MEDIA_CDN_KEY_NAME; // resource name for the Media CDN key - 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 { - TestUtils.cleanStaleCdnKeys(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - // Cloud CDN key - CLOUD_CDN_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, - CLOUD_CDN_KEY_ID); - // Media CDN key - MEDIA_CDN_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, - MEDIA_CDN_KEY_ID); - bout.reset(); - } - - @Test - public void test_CreateCdnKey() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - // Cloud CDN key - CreateCdnKey.createCdnKey( - PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID, TestUtils.HOSTNAME, TestUtils.KEYNAME, - TestUtils.CLOUD_CDN_PRIVATE_KEY, false); - String output = bout.toString(); - assertThat(output, containsString(CLOUD_CDN_KEY_NAME)); - bout.reset(); - - // Media CDN key - CreateCdnKey.createCdnKey( - PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID, TestUtils.HOSTNAME, TestUtils.KEYNAME, - TestUtils.MEDIA_CDN_PRIVATE_KEY, true); - output = bout.toString(); - assertThat(output, containsString(MEDIA_CDN_KEY_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - // Cloud CDN key - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID); - // Media CDN key - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/CreateLiveConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/CreateLiveConfigTest.java deleted file mode 100644 index 2770dd24249..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/CreateLiveConfigTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2023 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 CreateLiveConfigTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String SLATE_ID = TestUtils.getSlateId(); - private static final String LIVE_CONFIG_ID = TestUtils.getLiveConfigId(); - private static String PROJECT_ID; - private static String LIVE_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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - TestUtils.cleanStaleLiveConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - LIVE_CONFIG_NAME = String.format("locations/%s/liveConfigs/", TestUtils.LOCATION); - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - bout.reset(); - } - - @Test - public void test_CreateLiveConfig() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - CreateLiveConfig.createLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID, - TestUtils.LIVE_URI, - TestUtils.LIVE_AD_TAG_URI, SLATE_ID); - String output = bout.toString(); - assertThat(output, containsString(LIVE_CONFIG_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteLiveConfig.deleteLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/CreateLiveSessionTest.java b/media/stitcher/src/test/java/com/example/stitcher/CreateLiveSessionTest.java deleted file mode 100644 index 17e374a5f8e..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/CreateLiveSessionTest.java +++ /dev/null @@ -1,96 +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 CreateLiveSessionTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String SLATE_ID = TestUtils.getSlateId(); - private static final String LIVE_CONFIG_ID = TestUtils.getLiveConfigId(); - 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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - TestUtils.cleanStaleLiveConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - // Project number is always returned in the live session name - SESSION_NAME = String.format("locations/%s/liveSessions/", TestUtils.LOCATION); - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - CreateLiveConfig.createLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID, - TestUtils.LIVE_URI, TestUtils.LIVE_AD_TAG_URI, SLATE_ID); - bout.reset(); - } - - @Test - public void test_CreateLiveSession() throws IOException { - CreateLiveSession.createLiveSession(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - String output = bout.toString(); - assertThat(output, containsString(SESSION_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - DeleteLiveConfig.deleteLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - // No delete method for a live session - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/CreateSlateTest.java b/media/stitcher/src/test/java/com/example/stitcher/CreateSlateTest.java deleted file mode 100644 index c9a4bf89922..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/CreateSlateTest.java +++ /dev/null @@ -1,88 +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 CreateSlateTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String SLATE_ID = TestUtils.getSlateId(); - private static String PROJECT_ID; - private static String SLATE_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 { - TestUtils.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - // Project number is always returned in the slate name - SLATE_NAME = String.format("/locations/%s/slates/%s", TestUtils.LOCATION, SLATE_ID); - bout.reset(); - } - - @Test - public void test_CreateSlate() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - String output = bout.toString(); - assertThat(output, containsString(SLATE_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/DeleteCdnKeyTest.java b/media/stitcher/src/test/java/com/example/stitcher/DeleteCdnKeyTest.java deleted file mode 100644 index 11ad3987d60..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/DeleteCdnKeyTest.java +++ /dev/null @@ -1,115 +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 DeleteCdnKeyTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String CLOUD_CDN_KEY_ID = TestUtils.getCdnKeyId(); - private static final String MEDIA_CDN_KEY_ID = TestUtils.getCdnKeyId(); - private static final String AKAMAI_KEY_ID = TestUtils.getCdnKeyId(); - 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.cleanStaleCdnKeys(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - // Cloud CDN key - CreateCdnKey.createCdnKey( - PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID, TestUtils.HOSTNAME, TestUtils.KEYNAME, - TestUtils.CLOUD_CDN_PRIVATE_KEY, false); - - // Media CDN key - CreateCdnKey.createCdnKey( - PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID, TestUtils.HOSTNAME, TestUtils.KEYNAME, - TestUtils.MEDIA_CDN_PRIVATE_KEY, true); - - // Akamai CDN key - CreateCdnKeyAkamai.createCdnKeyAkamai( - PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID, TestUtils.HOSTNAME, - TestUtils.AKAMAI_TOKEN_KEY); - - bout.reset(); - } - - @Test - public void test_DeleteCdnKey() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - // Cloud CDN key - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID); - String output = bout.toString(); - assertThat(output, containsString("Deleted CDN key")); - bout.reset(); - - // Media CDN key - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID); - output = bout.toString(); - assertThat(output, containsString("Deleted CDN key")); - bout.reset(); - - // Aakamai CDN key - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID); - output = bout.toString(); - assertThat(output, containsString("Deleted CDN key")); - bout.reset(); - } - - @After - public void tearDown() throws IOException { - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/DeleteLiveConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/DeleteLiveConfigTest.java deleted file mode 100644 index 121edd20e65..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/DeleteLiveConfigTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2023 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 DeleteLiveConfigTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String SLATE_ID = TestUtils.getSlateId(); - private static final String LIVE_CONFIG_ID = TestUtils.getLiveConfigId(); - 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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - TestUtils.cleanStaleLiveConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - CreateLiveConfig.createLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID, - TestUtils.LIVE_URI, TestUtils.LIVE_AD_TAG_URI, SLATE_ID); - bout.reset(); - } - - @Test - public void test_DeleteLiveConfig() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteLiveConfig.deleteLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - String output = bout.toString(); - assertThat(output, containsString("Deleted live config")); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/DeleteSlateTest.java b/media/stitcher/src/test/java/com/example/stitcher/DeleteSlateTest.java deleted file mode 100644 index 5f2a87d00d5..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/DeleteSlateTest.java +++ /dev/null @@ -1,86 +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 DeleteSlateTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String SLATE_ID = TestUtils.getSlateId(); - 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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - bout.reset(); - } - - @Test - public void test_DeleteSlate() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - String output = bout.toString(); - assertThat(output, containsString("Deleted slate")); - bout.reset(); - } - - @After - public void tearDown() throws IOException { - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetCdnKeyTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetCdnKeyTest.java deleted file mode 100644 index b4ed5edcc5d..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/GetCdnKeyTest.java +++ /dev/null @@ -1,129 +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 GetCdnKeyTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String CLOUD_CDN_KEY_ID = TestUtils.getCdnKeyId(); - private static final String MEDIA_CDN_KEY_ID = TestUtils.getCdnKeyId(); - private static final String AKAMAI_KEY_ID = TestUtils.getCdnKeyId(); - private static String PROJECT_ID; - private static String CLOUD_CDN_KEY_NAME; // resource name for the Cloud CDN key - private static String MEDIA_CDN_KEY_NAME; // resource name for the Media CDN key - private static String AKAMAI_KEY_NAME; // resource name for the Akamai CDN key - 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.cleanStaleCdnKeys(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - // Cloud CDN key - CLOUD_CDN_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, - CLOUD_CDN_KEY_ID); - CreateCdnKey.createCdnKey( - PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID, TestUtils.HOSTNAME, TestUtils.KEYNAME, - TestUtils.CLOUD_CDN_PRIVATE_KEY, false); - - // Media CDN key - MEDIA_CDN_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, - MEDIA_CDN_KEY_ID); - CreateCdnKey.createCdnKey( - PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID, TestUtils.HOSTNAME, TestUtils.KEYNAME, - TestUtils.MEDIA_CDN_PRIVATE_KEY, true); - - // Akamai CDN key - AKAMAI_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, AKAMAI_KEY_ID); - CreateCdnKeyAkamai.createCdnKeyAkamai( - PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID, TestUtils.HOSTNAME, - TestUtils.AKAMAI_TOKEN_KEY); - - bout.reset(); - } - - @Test - public void test_GetCdnKey() throws IOException { - // Cloud CDN key - GetCdnKey.getCdnKey(PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID); - String output = bout.toString(); - assertThat(output, containsString(CLOUD_CDN_KEY_NAME)); - bout.reset(); - - // Media CDN key - GetCdnKey.getCdnKey(PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID); - output = bout.toString(); - assertThat(output, containsString(MEDIA_CDN_KEY_NAME)); - bout.reset(); - - // Akamai CDN key - GetCdnKey.getCdnKey(PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID); - output = bout.toString(); - assertThat(output, containsString(AKAMAI_KEY_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - // Cloud CDN key - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID); - // Media CDN key - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID); - // Akamai CDN key - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetLiveSessionTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetLiveSessionTest.java deleted file mode 100644 index 49d899db0d3..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/GetLiveSessionTest.java +++ /dev/null @@ -1,111 +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 GetLiveSessionTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String SLATE_ID = TestUtils.getSlateId(); - private static final String LIVE_CONFIG_ID = TestUtils.getLiveConfigId(); - 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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - TestUtils.cleanStaleLiveConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - CreateLiveConfig.createLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID, - TestUtils.LIVE_URI, TestUtils.LIVE_AD_TAG_URI, SLATE_ID); - bout.reset(); - - CreateLiveSession.createLiveSession(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - Matcher idMatcher = - Pattern.compile( - String.format( - "Created live session: projects/.*/locations/%s/liveSessions/(.*)", - TestUtils.LOCATION)) - .matcher(bout.toString()); - if (idMatcher.find()) { - SESSION_ID = idMatcher.group(1); - } - // Project number is always returned in the live session name - SESSION_NAME = String.format("locations/%s/liveSessions/%s", TestUtils.LOCATION, SESSION_ID); - bout.reset(); - } - - @Test - public void test_GetLiveSession() throws IOException { - GetLiveSession.getLiveSession(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 { - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - DeleteLiveConfig.deleteLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - // No delete method for a live session - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetSlateTest.java b/media/stitcher/src/test/java/com/example/stitcher/GetSlateTest.java deleted file mode 100644 index d2c10e36b3d..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/GetSlateTest.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 GetSlateTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String SLATE_ID = TestUtils.getSlateId(); - private static String PROJECT_ID; - private static String SLATE_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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - SLATE_NAME = - String.format("projects/%s/locations/%s/slates/%s", PROJECT_ID, TestUtils.LOCATION, - SLATE_ID); - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - bout.reset(); - } - - @Test - public void test_GetSlate() throws IOException { - GetSlate.getSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - String output = bout.toString(); - assertThat(output, containsString(SLATE_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/ListCdnKeysTest.java b/media/stitcher/src/test/java/com/example/stitcher/ListCdnKeysTest.java deleted file mode 100644 index 4cbdef91b34..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/ListCdnKeysTest.java +++ /dev/null @@ -1,116 +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 ListCdnKeysTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String CLOUD_CDN_KEY_ID = TestUtils.getCdnKeyId(); - private static final String MEDIA_CDN_KEY_ID = TestUtils.getCdnKeyId(); - private static final String AKAMAI_KEY_ID = TestUtils.getCdnKeyId(); - private static String PROJECT_ID; - private static String CLOUD_CDN_KEY_NAME; // resource name for the Cloud CDN key - private static String MEDIA_CDN_KEY_NAME; // resource name for the Media CDN key - private static String AKAMAI_KEY_NAME; // resource name for the Akamai CDN key - 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.cleanStaleCdnKeys(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - // Cloud CDN key - CLOUD_CDN_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, - CLOUD_CDN_KEY_ID); - CreateCdnKey.createCdnKey( - PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID, TestUtils.HOSTNAME, TestUtils.KEYNAME, - TestUtils.CLOUD_CDN_PRIVATE_KEY, false); - - // Media CDN key - MEDIA_CDN_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, - MEDIA_CDN_KEY_ID); - CreateCdnKey.createCdnKey( - PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID, TestUtils.HOSTNAME, TestUtils.KEYNAME, - TestUtils.MEDIA_CDN_PRIVATE_KEY, true); - - // Akamai CDN key - AKAMAI_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, AKAMAI_KEY_ID); - CreateCdnKeyAkamai.createCdnKeyAkamai( - PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID, TestUtils.HOSTNAME, - TestUtils.AKAMAI_TOKEN_KEY); - - bout.reset(); - } - - @Test - public void test_ListCdnKeys() throws IOException { - // Cloud, Media, and Akamai CDN keys should be present - ListCdnKeys.listCdnKeys(PROJECT_ID, TestUtils.LOCATION); - String output = bout.toString(); - assertThat(output, containsString(CLOUD_CDN_KEY_NAME)); - assertThat(output, containsString(MEDIA_CDN_KEY_NAME)); - assertThat(output, containsString(AKAMAI_KEY_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, CLOUD_CDN_KEY_ID); - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, MEDIA_CDN_KEY_ID); - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/ListLiveAdTagDetailsTest.java b/media/stitcher/src/test/java/com/example/stitcher/ListLiveAdTagDetailsTest.java deleted file mode 100644 index 414514e0c81..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/ListLiveAdTagDetailsTest.java +++ /dev/null @@ -1,133 +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 ListLiveAdTagDetailsTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String SLATE_ID = TestUtils.getSlateId(); - private static final String LIVE_CONFIG_ID = TestUtils.getLiveConfigId(); - private static String PROJECT_ID; - private static String SESSION_ID; - private static String AD_TAG_DETAILS_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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - TestUtils.cleanStaleLiveConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - CreateLiveConfig.createLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID, - TestUtils.LIVE_URI, TestUtils.LIVE_AD_TAG_URI, SLATE_ID); - bout.reset(); - - CreateLiveSession.createLiveSession(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - String output = bout.toString(); - Matcher idMatcher = - Pattern.compile( - String.format( - "Created live session: projects/.*/locations/%s/liveSessions/(.*)", - TestUtils.LOCATION)) - .matcher(output); - if (idMatcher.find()) { - SESSION_ID = idMatcher.group(1); - } - // Project number is always returned in the live session name - AD_TAG_DETAILS_NAME = - String.format("locations/%s/liveSessions/%s/liveAdTagDetails/", TestUtils.LOCATION, - SESSION_ID); - - // To get ad tag details, you need to curl the main manifest and - // a rendition first. This supplies media player information to the API. - // - // Curl the playUri first. The last line of the response will contain a - // renditions location. Curl the live session name with the rendition - // location appended. - - String playUri = TestUtils.getPlayUri(output); - assertNotNull(playUri); - String renditions = TestUtils.getRenditions(playUri); - assertNotNull(renditions); - - // playUri will be in the following format: - // https://videostitcher.googleapis.com/v1/projects/{project}/locations/{location}/liveSessions/{session-id}/manifest.m3u8?signature=... - // Replace manifest.m3u8?signature=... with the renditions location. - String renditionsUri = - String.format("%s/%s", playUri.substring(0, playUri.lastIndexOf("/")), renditions); - TestUtils.connectToRenditionsUrl(renditionsUri); - bout.reset(); - } - - @Test - public void test_ListLiveAdTagDetails() throws IOException { - ListLiveAdTagDetails.listLiveAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); - String output = bout.toString(); - assertThat(output, containsString(AD_TAG_DETAILS_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - DeleteLiveConfig.deleteLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - // No delete method for a live session - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/ListLiveConfigsTest.java b/media/stitcher/src/test/java/com/example/stitcher/ListLiveConfigsTest.java deleted file mode 100644 index cc84097abcf..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/ListLiveConfigsTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2023 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 ListLiveConfigsTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String SLATE_ID = TestUtils.getSlateId(); - private static final String LIVE_CONFIG_ID = TestUtils.getLiveConfigId(); - - private static String PROJECT_ID; - private static String LIVE_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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - TestUtils.cleanStaleLiveConfigs(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - LIVE_CONFIG_NAME = - String.format("projects/%s/locations/%s/liveConfigs/%s", PROJECT_ID, TestUtils.LOCATION, - LIVE_CONFIG_ID); - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - CreateLiveConfig.createLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID, - TestUtils.LIVE_URI, TestUtils.LIVE_AD_TAG_URI, SLATE_ID); - bout.reset(); - } - - @Test - public void test_ListLiveConfigs() throws IOException { - ListLiveConfigs.listLiveConfigs(PROJECT_ID, TestUtils.LOCATION); - String output = bout.toString(); - assertThat(output, containsString(LIVE_CONFIG_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteLiveConfig.deleteLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/ListSlatesTest.java b/media/stitcher/src/test/java/com/example/stitcher/ListSlatesTest.java deleted file mode 100644 index 4492661eff9..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/ListSlatesTest.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 ListSlatesTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String SLATE_ID = TestUtils.getSlateId(); - private static String PROJECT_ID; - private static String SLATE_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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - SLATE_NAME = - String.format("projects/%s/locations/%s/slates/%s", PROJECT_ID, TestUtils.LOCATION, - SLATE_ID); - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - bout.reset(); - } - - @Test - public void test_ListSlates() throws IOException { - ListSlates.listSlates(PROJECT_ID, TestUtils.LOCATION); - String output = bout.toString(); - assertThat(output, containsString(SLATE_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); - System.setOut(originalOut); - bout.reset(); - } -} diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetLiveConfigTest.java b/media/stitcher/src/test/java/com/example/stitcher/LiveConfigTest.java similarity index 63% rename from media/stitcher/src/test/java/com/example/stitcher/GetLiveConfigTest.java rename to media/stitcher/src/test/java/com/example/stitcher/LiveConfigTest.java index c0671a39ab2..a1d34bcd091 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/GetLiveConfigTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/LiveConfigTest.java @@ -21,13 +21,15 @@ import static org.junit.Assert.assertNotNull; import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import com.google.cloud.video.stitcher.v1.LiveConfig; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListLiveConfigsPagedResponse; 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.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -35,17 +37,16 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) -public class GetLiveConfigTest { +public class LiveConfigTest { @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); private static final String SLATE_ID = TestUtils.getSlateId(); private static final String LIVE_CONFIG_ID = TestUtils.getLiveConfigId(); - - private static String PROJECT_ID; private static String LIVE_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); @@ -55,43 +56,68 @@ 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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - TestUtils.cleanStaleLiveConfigs(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); - LIVE_CONFIG_NAME = - String.format("projects/%s/locations/%s/liveConfigs/%s", PROJECT_ID, TestUtils.LOCATION, - LIVE_CONFIG_ID); + TestUtils.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); + TestUtils.cleanStaleLiveConfigs(PROJECT_ID, TestUtils.LOCATION); + CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - CreateLiveConfig.createLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID, - TestUtils.LIVE_URI, TestUtils.LIVE_AD_TAG_URI, SLATE_ID); - bout.reset(); + + LIVE_CONFIG_NAME = + String.format("locations/%s/liveConfigs/%s", TestUtils.LOCATION, LIVE_CONFIG_ID); + LiveConfig response = + CreateLiveConfig.createLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID, + TestUtils.LIVE_URI, + TestUtils.LIVE_AD_TAG_URI, SLATE_ID); + assertThat(response.getName(), containsString(LIVE_CONFIG_NAME)); } @Test - public void test_GetLiveConfig() throws IOException { - GetLiveConfig.getLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - String output = bout.toString(); - assertThat(output, containsString(LIVE_CONFIG_NAME)); - bout.reset(); + public void testGetLiveConfig() throws IOException { + LiveConfig response = GetLiveConfig.getLiveConfig(PROJECT_ID, TestUtils.LOCATION, + LIVE_CONFIG_ID); + assertThat(response.getName(), containsString(LIVE_CONFIG_NAME)); + } + + @Test + public void testListLiveConfigs() throws IOException { + ListLiveConfigsPagedResponse response = + ListLiveConfigs.listLiveConfigs(PROJECT_ID, TestUtils.LOCATION); + Boolean pass = false; + for (LiveConfig liveConfig : response.iterateAll()) { + if (liveConfig.getName().contains(LIVE_CONFIG_NAME)) { + pass = true; + break; + } + } + assert (pass); } @After - public void tearDown() + public void tearDown() { + bout.reset(); + } + + @AfterClass + public static void afterTest() throws IOException, ExecutionException, InterruptedException, TimeoutException { DeleteLiveConfig.deleteLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); + String deleteResponse = bout.toString(); + assertThat(deleteResponse, containsString("Deleted live config")); + bout.reset(); + DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); + deleteResponse = bout.toString(); + assertThat(deleteResponse, containsString("Deleted slate")); + + System.out.flush(); System.setOut(originalOut); - bout.reset(); } } diff --git a/media/stitcher/src/test/java/com/example/stitcher/GetLiveAdTagDetailTest.java b/media/stitcher/src/test/java/com/example/stitcher/LiveSessionTest.java similarity index 57% rename from media/stitcher/src/test/java/com/example/stitcher/GetLiveAdTagDetailTest.java rename to media/stitcher/src/test/java/com/example/stitcher/LiveSessionTest.java index f4aeaa69bdf..1c160796913 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/GetLiveAdTagDetailTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/LiveSessionTest.java @@ -21,15 +21,16 @@ import static org.junit.Assert.assertNotNull; import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import com.google.cloud.video.stitcher.v1.LiveAdTagDetail; +import com.google.cloud.video.stitcher.v1.LiveSession; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListLiveAdTagDetailsPagedResponse; 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.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -37,18 +38,23 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) -public class GetLiveAdTagDetailTest { +public class LiveSessionTest { @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); private static final String SLATE_ID = TestUtils.getSlateId(); private static final String LIVE_CONFIG_ID = TestUtils.getLiveConfigId(); - private static String PROJECT_ID; + private static String LIVE_CONFIG_NAME; + private static String LIVE_SESSION_NAME_PREFIX; + private static String LIVE_SESSION_NAME; private static String SESSION_ID; - private static String AD_TAG_DETAIL_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 ByteArrayOutputStream bout; private static String requireEnvVar(String varName) { String varValue = System.getenv(varName); @@ -58,36 +64,33 @@ 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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); - TestUtils.cleanStaleLiveConfigs(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); + TestUtils.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); + TestUtils.cleanStaleLiveConfigs(PROJECT_ID, TestUtils.LOCATION); + + // Project number is always returned in the live session name + LIVE_SESSION_NAME = String.format("locations/%s/liveSessions/", TestUtils.LOCATION); CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); CreateLiveConfig.createLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID, TestUtils.LIVE_URI, TestUtils.LIVE_AD_TAG_URI, SLATE_ID); - bout.reset(); - CreateLiveSession.createLiveSession(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - String output = bout.toString(); - Matcher idMatcher = - Pattern.compile( - String.format( - "Created live session: projects/.*/locations/%s/liveSessions/(.*)", - TestUtils.LOCATION)) - .matcher(output); - if (idMatcher.find()) { - SESSION_ID = idMatcher.group(1); - } + // Session IDs are autogenerated. + LIVE_SESSION_NAME_PREFIX = String.format("locations/%s/liveSessions/", TestUtils.LOCATION); + LiveSession sessionResponse = + CreateLiveSession.createLiveSession(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); + assertThat(sessionResponse.getName(), containsString(LIVE_SESSION_NAME_PREFIX)); + + LIVE_SESSION_NAME = sessionResponse.getName(); + String[] id = LIVE_SESSION_NAME.split("/"); + SESSION_ID = id[id.length - 1]; // To get ad tag details, you need to curl the main manifest and // a rendition first. This supplies media player information to the API. @@ -96,7 +99,7 @@ public void beforeTest() // renditions location. Curl the live session name with the rendition // location appended. - String playUri = TestUtils.getPlayUri(output); + String playUri = sessionResponse.getPlayUri(); assertNotNull(playUri); String renditions = TestUtils.getRenditions(playUri); assertNotNull(renditions); @@ -107,40 +110,65 @@ public void beforeTest() String renditionsUri = String.format("%s/%s", playUri.substring(0, playUri.lastIndexOf("/")), renditions); TestUtils.connectToRenditionsUrl(renditionsUri); - bout.reset(); - // Project number is always returned in the live session name - String adTagDetailPrefix = - String.format("locations/%s/liveSessions/%s/liveAdTagDetails/", TestUtils.LOCATION, - SESSION_ID); - ListLiveAdTagDetails.listLiveAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); - idMatcher = - Pattern.compile(String.format("name: \"projects/.*/%s(.*)\"", adTagDetailPrefix)) - .matcher(bout.toString()); - if (idMatcher.find()) { - AD_TAG_DETAIL_ID = idMatcher.group(1); - AD_TAG_DETAIL_NAME = adTagDetailPrefix + AD_TAG_DETAIL_ID; + ListLiveAdTagDetailsPagedResponse adtagResponse = + ListLiveAdTagDetails.listLiveAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + for (LiveAdTagDetail liveAdTagDetail : adtagResponse.iterateAll()) { + AD_TAG_DETAIL_NAME = liveAdTagDetail.getName(); } + id = AD_TAG_DETAIL_NAME.split("/"); + AD_TAG_DETAIL_ID = id[id.length - 1]; + } - bout.reset(); + @Test + public void testGetLiveSession() throws IOException { + LiveSession response = GetLiveSession.getLiveSession(PROJECT_ID, TestUtils.LOCATION, + SESSION_ID); + assertThat(response.getName(), containsString(LIVE_SESSION_NAME)); } @Test - public void test_GetLiveAdTagDetail() throws IOException { - GetLiveAdTagDetail.getLiveAdTagDetail(PROJECT_ID, TestUtils.LOCATION, SESSION_ID, - AD_TAG_DETAIL_ID); - String output = bout.toString(); - assertThat(output, containsString(AD_TAG_DETAIL_NAME)); - bout.reset(); + public void testListLiveAdTagDetailsTest() throws IOException { + ListLiveAdTagDetailsPagedResponse response = + ListLiveAdTagDetails.listLiveAdTagDetails(PROJECT_ID, TestUtils.LOCATION, SESSION_ID); + + Boolean pass = false; + for (LiveAdTagDetail liveAdTagDetail : response.iterateAll()) { + if (liveAdTagDetail.getName().contains(LIVE_SESSION_NAME.concat("/liveAdTagDetails/"))) { + pass = true; + break; + } + } + assert (pass); + } + + @Test + public void testGetLiveAdTagDetailTest() throws IOException { + LiveAdTagDetail response = + GetLiveAdTagDetail.getLiveAdTagDetail( + PROJECT_ID, TestUtils.LOCATION, SESSION_ID, AD_TAG_DETAIL_ID); + assertThat(response.getName(), containsString(AD_TAG_DETAIL_NAME)); } @After - public void tearDown() + public void tearDown() { + bout.reset(); + } + + @AfterClass + public static void afterTest() throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); + // No delete method for live sessions DeleteLiveConfig.deleteLiveConfig(PROJECT_ID, TestUtils.LOCATION, LIVE_CONFIG_ID); - // No delete method for a live session or ad tag detail - System.setOut(originalOut); + String deleteResponse = bout.toString(); + assertThat(deleteResponse, containsString("Deleted live config")); bout.reset(); + + DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); + deleteResponse = bout.toString(); + assertThat(deleteResponse, containsString("Deleted slate")); + + System.out.flush(); + System.setOut(originalOut); } } diff --git a/media/stitcher/src/test/java/com/example/stitcher/UpdateSlateTest.java b/media/stitcher/src/test/java/com/example/stitcher/SlateTest.java similarity index 61% rename from media/stitcher/src/test/java/com/example/stitcher/UpdateSlateTest.java rename to media/stitcher/src/test/java/com/example/stitcher/SlateTest.java index 4fcda493fb1..62f7e98f773 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/UpdateSlateTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/SlateTest.java @@ -21,13 +21,15 @@ import static org.junit.Assert.assertNotNull; import com.google.cloud.testing.junit4.MultipleAttemptsRule; +import com.google.cloud.video.stitcher.v1.Slate; +import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient.ListSlatesPagedResponse; 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.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; @@ -35,18 +37,17 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) -public class UpdateSlateTest { +public class SlateTest { @Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); private static final String SLATE_ID = TestUtils.getSlateId(); - private static String PROJECT_ID; private static String SLATE_NAME; - private static final String UPDATED_SLATE_URI = "https://storage.googleapis.com/cloud-samples-data/media/ForBiggerJoyrides.mp4"; + 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); @@ -56,40 +57,70 @@ 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.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); originalOut = System.out; bout = new ByteArrayOutputStream(); System.setOut(new PrintStream(bout)); + TestUtils.cleanStaleSlates(PROJECT_ID, TestUtils.LOCATION); + SLATE_NAME = - String.format("projects/%s/locations/%s/slates/%s", PROJECT_ID, TestUtils.LOCATION, - SLATE_ID); - CreateSlate.createSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, TestUtils.SLATE_URI); - bout.reset(); + String.format("locations/%s/slates/%s", TestUtils.LOCATION, SLATE_ID); + Slate response = + CreateSlate.createSlate( + PROJECT_ID, + TestUtils.LOCATION, + SLATE_ID, + TestUtils.SLATE_URI); + assertThat(response.getName(), containsString(SLATE_NAME)); } @Test - public void test_UpdateSlate() + public void testGetSlate() throws IOException { + Slate response = GetSlate.getSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); + assertThat(response.getName(), containsString(SLATE_NAME)); + } + + @Test + public void testListSlates() throws IOException { + ListSlatesPagedResponse response = + ListSlates.listSlates(PROJECT_ID, TestUtils.LOCATION); + Boolean pass = false; + for (Slate slate : response.iterateAll()) { + if (slate.getName().contains(SLATE_NAME)) { + pass = true; + break; + } + } + assert (pass); + } + + @Test + public void testUpdateSlate() throws IOException, ExecutionException, InterruptedException, TimeoutException { - UpdateSlate.updateSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID, UPDATED_SLATE_URI); - String output = bout.toString(); - assertThat(output, containsString(SLATE_NAME)); - bout.reset(); + Slate response = + UpdateSlate.updateSlate( + PROJECT_ID, TestUtils.LOCATION, SLATE_ID, UPDATED_SLATE_URI); + assertThat(response.getName(), containsString(SLATE_NAME)); + assertThat(response.getUri(), containsString(UPDATED_SLATE_URI)); } @After - public void tearDown() + public void tearDown() { + bout.reset(); + } + + @AfterClass + public static void afterTest() throws IOException, ExecutionException, InterruptedException, TimeoutException { DeleteSlate.deleteSlate(PROJECT_ID, TestUtils.LOCATION, SLATE_ID); + String deleteResponse = bout.toString(); + assertThat(deleteResponse, containsString("Deleted slate")); + System.out.flush(); 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 ac66dbdbc72..d95241b004f 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/TestUtils.java +++ b/media/stitcher/src/test/java/com/example/stitcher/TestUtils.java @@ -188,16 +188,6 @@ public static void cleanStaleVodConfigs(String projectId, String location) throw } } - // Finds the play URI in the given output. - public static String getPlayUri(String output) { - Matcher uriMatcher = Pattern.compile("Play URI: (.*)").matcher(output); - String playUri = null; - if (uriMatcher.find()) { - playUri = uriMatcher.group(1); - } - return playUri; - } - // Connects to the play URI and returns the renditions information. public static String getRenditions(String playUri) throws IOException { URL url = new URL(playUri); diff --git a/media/stitcher/src/test/java/com/example/stitcher/UpdateCdnKeyAkamaiTest.java b/media/stitcher/src/test/java/com/example/stitcher/UpdateCdnKeyAkamaiTest.java deleted file mode 100644 index 7cf248c9278..00000000000 --- a/media/stitcher/src/test/java/com/example/stitcher/UpdateCdnKeyAkamaiTest.java +++ /dev/null @@ -1,96 +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 UpdateCdnKeyAkamaiTest { - - @Rule - public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(5); - private static final String AKAMAI_KEY_ID = TestUtils.getCdnKeyId(); - private static final String UPDATED_AKAMAI_TOKEN_KEY = - "VGhpcyBpcyBhbiB1cGRhdGVkIHRlc3Qgc3RyaW5nLg=="; - private static String PROJECT_ID; - private static String AKAMAI_KEY_NAME; // resource name for the Akamai CDN key - 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.cleanStaleCdnKeys(PROJECT_ID, TestUtils.LOCATION); - originalOut = System.out; - bout = new ByteArrayOutputStream(); - System.setOut(new PrintStream(bout)); - - AKAMAI_KEY_NAME = String.format("/locations/%s/cdnKeys/%s", TestUtils.LOCATION, AKAMAI_KEY_ID); - CreateCdnKeyAkamai.createCdnKeyAkamai( - PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID, TestUtils.HOSTNAME, - TestUtils.AKAMAI_TOKEN_KEY); - bout.reset(); - } - - @Test - public void test_UpdateCdnKeyAkamai() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - UpdateCdnKeyAkamai.updateCdnKeyAkamai( - PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID, TestUtils.UPDATED_HOSTNAME, - UPDATED_AKAMAI_TOKEN_KEY); - String output = bout.toString(); - assertThat(output, containsString(AKAMAI_KEY_NAME)); - bout.reset(); - } - - @After - public void tearDown() - throws IOException, ExecutionException, InterruptedException, TimeoutException { - DeleteCdnKey.deleteCdnKey(PROJECT_ID, TestUtils.LOCATION, AKAMAI_KEY_ID); - System.setOut(originalOut); - bout.reset(); - } -} 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 b72b75d2494..5ed9e20f6a5 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/VodConfigTest.java @@ -39,7 +39,8 @@ @RunWith(JUnit4.class) public class VodConfigTest { - @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 VOD_CONFIG_NAME; private static String PROJECT_ID; 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 fc1fd4bf82e..007c666b1b2 100644 --- a/media/stitcher/src/test/java/com/example/stitcher/VodSessionTest.java +++ b/media/stitcher/src/test/java/com/example/stitcher/VodSessionTest.java @@ -43,7 +43,8 @@ @RunWith(JUnit4.class) public class VodSessionTest { - @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 VOD_CONFIG_NAME; private static String VOD_SESSION_NAME_PREFIX;