From 866f9a79fcb4da5e89ba24be6457b86774f01723 Mon Sep 17 00:00:00 2001 From: Shweta Murthy <78512904+shwetamurthy20@users.noreply.github.com> Date: Mon, 1 Nov 2021 11:57:44 -0700 Subject: [PATCH] Add remaining clients (#20) * add clients, update vpb client to pb client * add tests * fix test name * modify changelog * leave vpb as is,add new pb client * upgrade version, fix javadocs * fix javadoc * add all clients * Update CHANGELOG.md Co-authored-by: Matt Wisniewski Co-authored-by: Matt Wisniewski --- CHANGELOG.md | 5 + pom.xml | 2 +- .../client/MediaRenditionClient.java | 119 ++++++++++++ .../jwplatform/client/OriginalClient.java | 139 ++++++++++++++ .../client/PlayerBiddingConfigClient.java | 144 +++++++++++++++ .../jwplatform/client/PlaylistsClient.java | 70 +++++++ .../jwplatform/client/TagsClient.java | 79 ++++++++ .../jwplatform/client/TextTracksClient.java | 171 ++++++++++++++++++ .../jwplatform/client/ThumbnailsClient.java | 134 ++++++++++++++ .../jwplatform/client/UsageClient.java | 77 ++++++++ .../jwplatform/client/VPBConfigsClient.java | 2 +- .../jwplatform/client/MediaRenditionTest.java | 70 +++++++ .../jwplatform/client/OriginalClientTest.java | 71 ++++++++ .../client/PlayerBiddingConfigClientTest.java | 73 ++++++++ .../client/PlaylistsClientTest.java | 6 +- .../jwplatform/client/TagsClientTest.java | 54 ++++++ .../client/TextTracksClientTest.java | 115 ++++++++++++ .../client/ThumbnailsClientTest.java | 69 +++++++ .../jwplatform/client/UsageClientTest.java | 54 ++++++ .../client/VPBConfigsClientTest.java | 2 +- 20 files changed, 1452 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/jwplayer/jwplatform/client/MediaRenditionClient.java create mode 100644 src/main/java/com/jwplayer/jwplatform/client/OriginalClient.java create mode 100644 src/main/java/com/jwplayer/jwplatform/client/PlayerBiddingConfigClient.java create mode 100644 src/main/java/com/jwplayer/jwplatform/client/TagsClient.java create mode 100644 src/main/java/com/jwplayer/jwplatform/client/TextTracksClient.java create mode 100644 src/main/java/com/jwplayer/jwplatform/client/ThumbnailsClient.java create mode 100644 src/main/java/com/jwplayer/jwplatform/client/UsageClient.java create mode 100644 src/test/java/com/jwplayer/jwplatform/client/MediaRenditionTest.java create mode 100644 src/test/java/com/jwplayer/jwplatform/client/OriginalClientTest.java create mode 100644 src/test/java/com/jwplayer/jwplatform/client/PlayerBiddingConfigClientTest.java create mode 100644 src/test/java/com/jwplayer/jwplatform/client/TagsClientTest.java create mode 100644 src/test/java/com/jwplayer/jwplatform/client/TextTracksClientTest.java create mode 100644 src/test/java/com/jwplayer/jwplatform/client/ThumbnailsClientTest.java create mode 100644 src/test/java/com/jwplayer/jwplatform/client/UsageClientTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 290534e..d22b00a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.1.0 + +* Add V2 Clients for Text tracks, Tags, Usage, Player Bidding Configs, Originals, Media Renditions, Thumbnails. +* Update Playlists client to include watchlist. + ## 1.0.0 * Add the following V2 clients- diff --git a/pom.xml b/pom.xml index 1d0e19d..94db9ad 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ 1.8 UTF-8 - 28.1-jre + 29.0-jre 3.9 1.4.9 diff --git a/src/main/java/com/jwplayer/jwplatform/client/MediaRenditionClient.java b/src/main/java/com/jwplayer/jwplatform/client/MediaRenditionClient.java new file mode 100644 index 0000000..7edc15e --- /dev/null +++ b/src/main/java/com/jwplayer/jwplatform/client/MediaRenditionClient.java @@ -0,0 +1,119 @@ +package com.jwplayer.jwplatform.client; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONObject; + +import com.google.common.base.Preconditions; +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +/** + * JW Platform MediaRendition API client. + * + *

+ * An API client for the JW Platform MediaRendition API. For the API documentation + * see: Introduction + * to api v2 + * + *

+ * Example: MediaRenditionClient client = MediaRenditionClient.getClient(secret); + */ +public class MediaRenditionClient extends JWPlatformClientV2 { + + private String path; + private final String secret; + + /** + * Instantiate a new {@code MediaRenditionClient} instance. + * + * @param secret - your api secret + */ + private MediaRenditionClient(String secret) { + this.secret = secret; + this.path = "https://api.jwplayer.com/v2/sites/%s/media/%s/media_renditions/"; + headers = new HashMap<>(); + headers.put("Authorization", "Bearer " + this.secret); + headers.put("accept", "application/json"); + headers.put("Content-Type", "application/json"); + } + + /** + * see {@link #MediaRenditionClient(String)}. + */ + public static MediaRenditionClient getClient(String secret) { + Preconditions.checkNotNull(secret, "API Secret must not be null!"); + return new MediaRenditionClient(secret); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - PropertyID + * @param params - Parameters to be included in the request + * @return JSON response from Media API + * @throws JWPlatformException See List Renditions + */ + public JSONObject listMediaRenditions(String siteId, String mediaId, Map params) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId); + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a resource + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Media API + * @throws JWPlatformException See Create Rendition + */ + public JSONObject createRendition(String siteId, String mediaId,Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId); + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "POST", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a resource + * @param renditionId - Unique identifier for a rendition + * @param params - Parameters to be included in the request + * @return JSON response from Media API + * @throws JWPlatformException See Get Rendition By ID + */ + public JSONObject getRenditionById(String siteId, String mediaId, String renditionId, Map params) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + Preconditions.checkNotNull(renditionId, "Rendition ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId)+renditionId+"/"; + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a resource + * @param renditionId - Unique identifier for a rendition + * @return JSON response from Media API + * @throws JWPlatformException See Delete Rendition + */ + public JSONObject deleteRendition(String siteId, String mediaId, String renditionId) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + Preconditions.checkNotNull(renditionId, "Rendition ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId)+renditionId+"/"; + return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers); + } +} \ No newline at end of file diff --git a/src/main/java/com/jwplayer/jwplatform/client/OriginalClient.java b/src/main/java/com/jwplayer/jwplatform/client/OriginalClient.java new file mode 100644 index 0000000..ab15297 --- /dev/null +++ b/src/main/java/com/jwplayer/jwplatform/client/OriginalClient.java @@ -0,0 +1,139 @@ +package com.jwplayer.jwplatform.client; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONObject; + +import com.google.common.base.Preconditions; +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +/** + * JW Platform Original API client. + * + *

+ * An API client for the JW Platform Original API. For the API documentation + * see: Introduction + * to api v2 + * + *

+ * Example: OriginalClient client = OriginalClient.getClient(secret); + */ +public class OriginalClient extends JWPlatformClientV2 { + + private String path; + private final String secret; + + /** + * Instantiate a new {@code OriginalClient} instance. + * + * @param secret - your api secret + */ + private OriginalClient(String secret) { + this.secret = secret; + this.path = "https://api.jwplayer.com/v2/sites/%s/media/%s/originals/"; + headers = new HashMap<>(); + headers.put("Authorization", "Bearer " + this.secret); + headers.put("accept", "application/json"); + headers.put("Content-Type", "application/json"); + } + + /** + * see {@link #OriginalClient(String)}. + */ + public static OriginalClient getClient(String secret) { + Preconditions.checkNotNull(secret, "API Secret must not be null!"); + return new OriginalClient(secret); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - PropertyID + * @param params - Parameters to be included in the request + * @return JSON response from Media API + * @throws JWPlatformException See List Originals + */ + public JSONObject listOriginals(String siteId, String mediaId, Map params) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId); + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a resource + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Media API + * @throws JWPlatformException See Create Originals + */ + public JSONObject createOriginals(String siteId, String mediaId,Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId); + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "POST", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a resource + * @param originalId - Unique identifier for a rendition + * @param params - Parameters to be included in the request + * @return JSON response from Media API + * @throws JWPlatformException See Get Original By ID + */ + public JSONObject getOriginalById(String siteId, String mediaId, String originalId, Map params) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + Preconditions.checkNotNull(originalId, "Original ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId)+ originalId + "/"; + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a resource + * @param originalId - Unique identifier for an original + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Media API + * @throws JWPlatformException See Update Original + */ + public JSONObject updateOriginal(String siteId, String mediaId, String originalId, Map bodyParams) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Config ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId) + originalId + "/"; + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "PATCH", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a resource + * @param originalId - Unique identifier for a rendition + * @return JSON response from Media API + * @throws JWPlatformException See Delete Rendition + */ + public JSONObject deleteOriginal(String siteId, String mediaId, String originalId) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + Preconditions.checkNotNull(originalId, "Original ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId) + originalId + "/"; + return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers); + } + +} \ No newline at end of file diff --git a/src/main/java/com/jwplayer/jwplatform/client/PlayerBiddingConfigClient.java b/src/main/java/com/jwplayer/jwplatform/client/PlayerBiddingConfigClient.java new file mode 100644 index 0000000..6fc48ab --- /dev/null +++ b/src/main/java/com/jwplayer/jwplatform/client/PlayerBiddingConfigClient.java @@ -0,0 +1,144 @@ +package com.jwplayer.jwplatform.client; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONObject; + +import com.google.common.base.Preconditions; +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +/** + * JW Platform PlayerBiddingConfigs API client. + * + *

+ * An API client for the JW Platform PlayerBiddingConfigs API. For the API documentation + * see: Introduction + * to api v2 + * + *

+ * Example: PlayerBiddingConfigClient client = PlayerBiddingConfigClient.getClient(secret); + */ +public class PlayerBiddingConfigClient extends JWPlatformClientV2 { + + private String path; + private final String secret; + + /** + * Instantiate a new {@code PlayerBiddingConfigClient} instance. + * + * @param secret - your api secret + */ + private PlayerBiddingConfigClient(String secret) { + this.secret = secret; + this.path = "https://api.jwplayer.com/v2/sites/%s/advertising/player_bidding_configs/"; + headers = new HashMap<>(); + headers.put("Authorization", "Bearer " + this.secret); + headers.put("accept", "application/json"); + headers.put("Content-Type", "application/json"); + } + + /** + * see {@link #PlayerBiddingConfigClient(String)}. + */ + public static PlayerBiddingConfigClient getClient(String secret) { + Preconditions.checkNotNull(secret, "API Secret must not be null!"); + return new PlayerBiddingConfigClient(secret); + } + + /** + * + * @param siteId - PropertyID + * @param params - Parameters to be included in the request + * @return JSON response from Media API + * @throws JWPlatformException See List Configs + */ + public JSONObject listConfigs(String siteId, Map params) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = String.format(this.path, siteId); + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Media API + * @throws JWPlatformException See Create Configs + */ + public JSONObject createConfig(String siteId, Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = String.format(this.path, siteId); + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "POST", headers); + } + + /** + * + * @param siteId - PropertyID + * @param configId - Unique identifier for a resource + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Media API + * @throws JWPlatformException See Update Config + */ + public JSONObject updateConfig(String siteId, String configId, Map bodyParams) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(configId, "Config ID must not be null!"); + this.path = String.format(this.path, siteId) + configId + "/"; + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "PATCH", headers); + } + + /** + * + * @param siteId - PropertyID + * @param configId - Unique identifier for a resource + * @param params - Parameters to be included in the request + * @return JSON response from Media API + * @throws JWPlatformException See Get Config By ID + */ + public JSONObject getConfigById(String siteId, String configId, Map params) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(configId, "Config ID must not be null!"); + this.path = String.format(this.path, siteId) + configId + "/"; + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param configId - Unique identifier for a resource + * @return JSON response from Media API + * @throws JWPlatformException See Delete Config + */ + public JSONObject deleteConfig(String siteId, String configId) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(configId, "Config ID must not be null!"); + this.path = String.format(this.path, siteId) + configId + "/"; + return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers); + } + + /** + * + * @param siteId - PropertyID + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Media API + * @throws JWPlatformException See Update Schedules + */ + public JSONObject updateSchedules(String siteId, Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = "https://api.jwplayer.com/v2/sites/" + siteId + "/advertising/update_schedules_player_bidding_configs/"; + return HttpCalls.request(this.path, bodyParams, false, "PUT", headers); + } + +} diff --git a/src/main/java/com/jwplayer/jwplatform/client/PlaylistsClient.java b/src/main/java/com/jwplayer/jwplatform/client/PlaylistsClient.java index 907c282..822a258 100644 --- a/src/main/java/com/jwplayer/jwplatform/client/PlaylistsClient.java +++ b/src/main/java/com/jwplayer/jwplatform/client/PlaylistsClient.java @@ -512,5 +512,75 @@ public JSONObject deleteRecommendationsPlaylist(String siteId, String playlistId this.path = String.format(this.path, siteId) + playlistId + "/recommendations_playlist/"; return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers); } + + /** + * + * @param siteId - PropertyID + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Playlists API + * @throws JWPlatformException See Create + * Watchlist playlist + */ + public JSONObject createWatchlistPlaylist(String siteId, Map bodyParams) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = String.format(this.path, siteId) + "watchlist_playlist/"; + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "POST", headers); + } + + /** + * + * @param siteId - PropertyID + * @param playlistId - Alphanumeric Playlist ID + * @param params - Parameters to be included in the request + * @return JSON response from Playlists API + * @throws JWPlatformException See Retrieve + * Watchlist playlist by ID + */ + public JSONObject retrieveWatchlistPlaylistById(String siteId, String playlistId, Map params) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(playlistId, "Playlist ID must not be null!"); + this.path = String.format(this.path, siteId) + playlistId + "/watchlist_playlist/"; + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param playlistId - Alphanumeric Playlist ID + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Playlists API + * @throws JWPlatformException See Update + * Watchlist playlist + */ + public JSONObject updateWatchlistPlaylist(String siteId, String playlistId, Map bodyParams) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(playlistId, "Playlist ID must not be null!"); + this.path = String.format(this.path, siteId) + playlistId + "/watchlist_playlist/"; + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "PATCH", headers); + } + + /** + * + * @param siteId - PropertyID + * @param playlistId - Alphanumeric Playlist ID + * @return JSON response from Playlists API + * @throws JWPlatformException See Delete + * Watchlist Playlist + */ + public JSONObject deleteWatchlistPlaylist(String siteId, String playlistId) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(playlistId, "Playlist ID must not be null!"); + this.path = String.format(this.path, siteId) + playlistId + "/watchlist_playlist/"; + return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers); + } } diff --git a/src/main/java/com/jwplayer/jwplatform/client/TagsClient.java b/src/main/java/com/jwplayer/jwplatform/client/TagsClient.java new file mode 100644 index 0000000..b84f661 --- /dev/null +++ b/src/main/java/com/jwplayer/jwplatform/client/TagsClient.java @@ -0,0 +1,79 @@ +package com.jwplayer.jwplatform.client; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONObject; + +import com.google.common.base.Preconditions; +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +/** + * JW Platform Tags API client. + * + *

+ * An API client for the JW Platform Tags API. For the API documentation + * see: Introduction + * to api v2 + * + *

+ * Example: TagsClient client = TagsClient.getClient(secret); + */ + +public class TagsClient extends JWPlatformClientV2 { + private String path; + private final String secret; + + /** + * Instantiate a new {@code TagsClient} instance. + * + * @param secret - your api secret + */ + private TagsClient(String secret) { + this.secret = secret; + this.path = "https://api.jwplayer.com/v2/sites/%s/"; + headers = new HashMap<>(); + headers.put("Authorization", "Bearer " + this.secret); + headers.put("accept", "application/json"); + headers.put("Content-Type", "application/json"); + } + + /** + * see {@link #TagsClient(String)}. + */ + public static TagsClient getClient(String secret) { + Preconditions.checkNotNull(secret, "API Secret must not be null!"); + return new TagsClient(secret); + } + + /** + * + * @param siteId - PropertyID + * @param bodyParams - Parameters to be included in the request + * @return JSON response from Tags APIs + * @throws JWPlatformException See Bulk Remove Tag + */ + public JSONObject bulkRemoveTag(String siteId, Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = String.format(this.path, siteId)+"remove_tag/"; + return HttpCalls.request(this.path, bodyParams, false, "PUT", headers); + } + + /** + * + * @param siteId - PropertyID + * @param bodyParams - Parameters to be included in the request + * @return JSON response from Tags API + * @throws JWPlatformException See Bulk Rename Tag + */ + public JSONObject bulkRenameTag(String siteId, Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = String.format(this.path, siteId)+"rename_tag/"; + return HttpCalls.request(this.path, bodyParams, false, "PUT", headers); + } + +} diff --git a/src/main/java/com/jwplayer/jwplatform/client/TextTracksClient.java b/src/main/java/com/jwplayer/jwplatform/client/TextTracksClient.java new file mode 100644 index 0000000..2fe3fd4 --- /dev/null +++ b/src/main/java/com/jwplayer/jwplatform/client/TextTracksClient.java @@ -0,0 +1,171 @@ +package com.jwplayer.jwplatform.client; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONObject; + +import com.google.common.base.Preconditions; +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +/** + * JW Platform Text Tracks API client. + * + *

+ * An API client for the JW Platform Tracks API. For the API documentation + * see: Introduction + * to api v2 + * + *

+ * Example: TextTracksClient client = TextTracksClient.getClient(secret); + */ + +public class TextTracksClient extends JWPlatformClientV2 { + private String path; + private final String secret; + + /** + * Instantiate a new {@code TextTracksClient} instance. + * + * @param secret - your api secret + */ + private TextTracksClient(String secret) { + this.secret = secret; + this.path = "https://api.jwplayer.com/v2/sites/%s/media/%s/text_tracks/"; + headers = new HashMap<>(); + headers.put("Authorization", "Bearer " + this.secret); + headers.put("accept", "application/json"); + headers.put("Content-Type", "application/json"); + } + + /** + * see {@link #TextTracksClient(String)}. + */ + public static TextTracksClient getClient(String secret) { + Preconditions.checkNotNull(secret, "API Secret must not be null!"); + return new TextTracksClient(secret); + } + + /** + * + * @param siteId - PropertyID + * @param params - Parameters to be included in the request + * @return JSON response from Text Tracks API + * @throws JWPlatformException See Text Tracks Client + */ + public JSONObject listTextTracks(String siteId, String mediaId, Map params) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId); + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a Media + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Text Tracks API + * @throws JWPlatformException See Create Track + */ + public JSONObject createTextTrack(String siteId, String mediaId, Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId); + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "POST", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a Media + * @param trackId - Unique identifier for a Track + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Text Tracks API + * @throws JWPlatformException See Update Track + */ + public JSONObject updateTextTrack(String siteId, String mediaId, String trackId, Map bodyParams) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId) + trackId + "/"; + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "PATCH", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a Media + * @param trackId - Unique identifier for a Track + * @param params - Parameters to be included in the request + * @return JSON response from Text Tracks API + * @throws JWPlatformException See Get Track + */ + public JSONObject getTextTrackById(String siteId, String mediaId, String trackId, Map params) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + Preconditions.checkNotNull(trackId, "Track ID must not be null!"); + this.path = String.format(this.path, siteId, mediaId) + trackId + "/"; + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a Media + * @param trackId - Unique identifier for a Track + * @return JSON response from Text Tracks API + * @throws JWPlatformException See Delete Track + */ + public JSONObject deleteTextTrack(String siteId, String mediaId, String trackId) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + Preconditions.checkNotNull(trackId, "Track ID must not be null!"); + this.path = String.format(this.path, siteId,mediaId) + trackId + "/"; + return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a Media + * @param trackId - Unique identifier for a Track + * @param bodyParams - Parameters to be included in the request + * @return JSON response from Text Tracks API + * @throws JWPlatformException See Publish Text Track + */ + public JSONObject publishTextTrack(String siteId, String mediaId, String trackId, Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + Preconditions.checkNotNull(trackId, "Track ID must not be null!"); + this.path = String.format(this.path, siteId,mediaId) + trackId + "/publish/"; + return HttpCalls.request(this.path, bodyParams, false, "PUT", headers); + } + + /** + * + * @param siteId - PropertyID + * @param mediaId - Unique identifier for a Media + * @param trackId - Unique identifier for a Track + * @param bodyParams - Parameters to be included in the request + * @return JSON response from Text Tracks API + * @throws JWPlatformException See Unpublish Text Track + */ + public JSONObject unpublishTextTrack(String siteId, String mediaId, String trackId, Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(mediaId, "Media ID must not be null!"); + Preconditions.checkNotNull(trackId, "Track ID must not be null!"); + this.path = String.format(this.path, siteId,mediaId) + trackId + "/unpublish/"; + return HttpCalls.request(this.path, bodyParams, false, "PUT", headers); + } +} diff --git a/src/main/java/com/jwplayer/jwplatform/client/ThumbnailsClient.java b/src/main/java/com/jwplayer/jwplatform/client/ThumbnailsClient.java new file mode 100644 index 0000000..7c7acb9 --- /dev/null +++ b/src/main/java/com/jwplayer/jwplatform/client/ThumbnailsClient.java @@ -0,0 +1,134 @@ +package com.jwplayer.jwplatform.client; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONObject; + +import com.google.common.base.Preconditions; +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +/** + * JW Platform Thumbnails API client. + * + *

+ * An API client for the JW Platform Thumbnails API. For the API documentation see: + * Introduction + * to api v2 + * + *

+ * Example: ThumbnailsClient client = ThumbnailsClient.getClient(secret); + */ +public class ThumbnailsClient extends JWPlatformClientV2 { + + private String path; + private final String secret; + + /** + * Instantiate a new {@code ThumbnailsClient} instance. + * + * @param secret - your api secret + */ + private ThumbnailsClient(String secret) { + this.secret = secret; + this.path = "https://api.jwplayer.com/v2/sites/%s/thumbnails/"; + headers = new HashMap<>(); + headers.put("Authorization", "Bearer " + this.secret); + headers.put("accept", "application/json"); + headers.put("Content-Type", "application/json"); + } + + /** + * see {@link #ThumbnailsClient(String)}. + */ + public static ThumbnailsClient getClient(String secret) { + Preconditions.checkNotNull(secret, "API Secret must not be null!"); + return new ThumbnailsClient(secret); + } + + /** + * + * @param siteId - PropertyID + * @param params - Parameters to be included in the request + * @return JSON response from Thumbnail API + * @throws JWPlatformException See List + * All Thumbnails + */ + public JSONObject listThumbnails(String siteId, Map params) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = String.format(this.path, siteId); + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Thumbnail API + * @throws JWPlatformException See Create + * Thumbnail + */ + public JSONObject createThumbnail(String siteId, Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = String.format(this.path, siteId); + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "POST", headers); + } + + /** + * + * @param siteId - PropertyID + * @param thumbnailId - Unique alphanumeric ID of the media + * @param params - Parameters to be included in the request + * @return JSON response from Thumbnail API + * @throws JWPlatformException See Retreive + * Thumbnail by ID + */ + public JSONObject retrieveThumbnailById(String siteId, String thumbnailId, Map params) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(thumbnailId, "Thumbnail ID must not be null!"); + this.path = String.format(this.path, siteId) + thumbnailId + "/"; + return HttpCalls.request(this.path, params, false, "GET", headers); + } + + /** + * + * @param siteId - PropertyID + * @param thumbnailId - Unique alphanumeric ID of the media + * @return JSON response from Thumbnail API + * @throws JWPlatformException See Delete + * thumbnail + */ + public JSONObject deleteThumbnail(String siteId, String thumbnailId) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(thumbnailId, "Thumbnail ID must not be null!"); + this.path = String.format(this.path, siteId) + thumbnailId + "/"; + return HttpCalls.request(this.path, new HashMap<>(), false, "DELETE", headers); + } + + /** + * + * @param siteId - PropertyID + * @param thumbnailId - Unique alphanumeric ID of the media + * @param bodyParams - Parameters to be included in the request body + * @return JSON response from Thumbnail API + * @throws JWPlatformException See Update + * Thumbnail + */ + public JSONObject updateThumbnail(String siteId, String thumbnailId, Map bodyParams) + throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + Preconditions.checkNotNull(thumbnailId, "Media ID must not be null!"); + this.path = String.format(this.path, siteId) + thumbnailId + "/"; + final boolean isBodyParams = bodyParams.size() > 0; + return HttpCalls.request(this.path, bodyParams, isBodyParams, "PATCH", headers); + } +} diff --git a/src/main/java/com/jwplayer/jwplatform/client/UsageClient.java b/src/main/java/com/jwplayer/jwplatform/client/UsageClient.java new file mode 100644 index 0000000..f200b6c --- /dev/null +++ b/src/main/java/com/jwplayer/jwplatform/client/UsageClient.java @@ -0,0 +1,77 @@ +package com.jwplayer.jwplatform.client; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONObject; + +import com.google.common.base.Preconditions; +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +/** + * JW Platform Usage API client. + * + *

+ * An API client for the JW Platform Usage API. For the API documentation + * see: Introduction + * to api v2 + * + *

+ * Example: UsageClient client = UsageClient.getClient(secret); + */ + +public class UsageClient extends JWPlatformClientV2 { + private String path; + private final String secret; + + /** + * Instantiate a new {@code UsageClient} instance. + * + * @param secret - your api secret + */ + private UsageClient(String secret) { + this.secret = secret; + this.path = "https://api.jwplayer.com/v2/"; + headers = new HashMap<>(); + headers.put("Authorization", "Bearer " + this.secret); + headers.put("accept", "application/json"); + headers.put("Content-Type", "application/json"); + } + + /** + * see {@link #UsageClient(String)}. + */ + public static UsageClient getClient(String secret) { + Preconditions.checkNotNull(secret, "API Secret must not be null!"); + return new UsageClient(secret); + } + + /** + * + * @param bodyParams - Parameters to be included in the request + * @return JSON response from Usage API + * @throws JWPlatformException See Query Account Usage + */ + public JSONObject queryAccountUsage(Map bodyParams) throws JWPlatformException { + this.path = this.path+ "query_usage/"; + return HttpCalls.request(this.path, bodyParams, false, "PUT", headers); + } + + /** + * + * @param siteId - PropertyID + * @param bodyParams - Parameters to be included in the request + * @return JSON response from Usage API + * @throws JWPlatformException See Query Site Usage + */ + public JSONObject querySiteUsage(String siteId, Map bodyParams) throws JWPlatformException { + Preconditions.checkNotNull(siteId, "Site ID must not be null!"); + this.path = this.path+ "sites/"+ siteId+ "/query_usage/"; + return HttpCalls.request(this.path, bodyParams, false, "PUT", headers); + } +} + diff --git a/src/main/java/com/jwplayer/jwplatform/client/VPBConfigsClient.java b/src/main/java/com/jwplayer/jwplatform/client/VPBConfigsClient.java index c81464d..8f10b2e 100644 --- a/src/main/java/com/jwplayer/jwplatform/client/VPBConfigsClient.java +++ b/src/main/java/com/jwplayer/jwplatform/client/VPBConfigsClient.java @@ -147,4 +147,4 @@ public JSONObject updateSchedules(String siteId, Map bodyParams) return HttpCalls.request(this.path, bodyParams, false, "PUT", headers); } -} +} \ No newline at end of file diff --git a/src/test/java/com/jwplayer/jwplatform/client/MediaRenditionTest.java b/src/test/java/com/jwplayer/jwplatform/client/MediaRenditionTest.java new file mode 100644 index 0000000..47a6723 --- /dev/null +++ b/src/test/java/com/jwplayer/jwplatform/client/MediaRenditionTest.java @@ -0,0 +1,70 @@ +package com.jwplayer.jwplatform.client; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ HttpCalls.class }) +public class MediaRenditionTest { + + MediaRenditionClient mediaRenditionClient = MediaRenditionClient.getClient("fakeSecret"); + + @Test + public void testAllMethods() throws JWPlatformException { + mediaRenditionClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"success\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("POST"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Object creation successful\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("DELETE"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Deletion success!\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PATCH"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Update successful\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Put successful\"}")); + JSONObject listResp = mediaRenditionClient.listMediaRenditions("siteId", "mediaId",new HashMap<>()); + assertEquals(listResp.get("code"), "success"); + JSONObject deleteResp = mediaRenditionClient.deleteRendition("siteId", "mediaId", "renditionId"); + assertEquals(deleteResp.get("code"), "Deletion success!"); + Map params = new HashMap<>(); + params.put("title", "test"); + mediaRenditionClient.createRendition("siteId", "mediaId", new HashMap<>()); + mediaRenditionClient.createRendition("siteId", "mediaId", params); + mediaRenditionClient.listMediaRenditions("siteId","mediaId", params); + mediaRenditionClient.deleteRendition("siteId","mediaId", "renditionId"); + mediaRenditionClient.getRenditionById("siteId", "mediaId", "renditionId", new HashMap<>()); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(7)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), anyString(), anyMap()); + mediaRenditionClient.removeHeader("test"); + } + + @Test(expected = JWPlatformException.class) + public void testGetMediaRenditionException() throws JSONException, JWPlatformException { + mediaRenditionClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap())) + .thenThrow(new JWPlatformException("some exception occured")); + mediaRenditionClient.listMediaRenditions("siteId", "mediaId", new HashMap<>()); + } +} diff --git a/src/test/java/com/jwplayer/jwplatform/client/OriginalClientTest.java b/src/test/java/com/jwplayer/jwplatform/client/OriginalClientTest.java new file mode 100644 index 0000000..2c0c3cf --- /dev/null +++ b/src/test/java/com/jwplayer/jwplatform/client/OriginalClientTest.java @@ -0,0 +1,71 @@ +package com.jwplayer.jwplatform.client; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ HttpCalls.class }) +public class OriginalClientTest { + + OriginalClient originalClient = OriginalClient.getClient("fakeSecret"); + + @Test + public void testAllMethods() throws JWPlatformException { + originalClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"success\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("POST"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Object creation successful\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("DELETE"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Deletion success!\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PATCH"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Update successful\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Put successful\"}")); + JSONObject listResp = originalClient.listOriginals("siteId", "mediaId", new HashMap<>()); + assertEquals(listResp.get("code"), "success"); + JSONObject deleteResp = originalClient.deleteOriginal("siteId", "mediaId", "originalId"); + assertEquals(deleteResp.get("code"), "Deletion success!"); + Map params = new HashMap<>(); + params.put("title", "test"); + originalClient.createOriginals("siteId", "mediaId", new HashMap<>()); + originalClient.createOriginals("siteId", "mediaId", params); + originalClient.updateOriginal("siteId", "mediaId", "originalId", params); + originalClient.updateOriginal("siteId", "mediaId", "originalId", new HashMap<>()); + originalClient.getOriginalById("siteId", "mediaId", "originalId", new HashMap<>()); + originalClient.deleteOriginal("siteId", "mediaId", "originalId"); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(8)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), anyString(), anyMap()); + originalClient.removeHeader("test"); + } + + @Test(expected = JWPlatformException.class) + public void testGetOriginalsException() throws JSONException, JWPlatformException { + originalClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap())) + .thenThrow(new JWPlatformException("some exception occured")); + originalClient.listOriginals("siteId", "mediaId", new HashMap<>()); + } +} diff --git a/src/test/java/com/jwplayer/jwplatform/client/PlayerBiddingConfigClientTest.java b/src/test/java/com/jwplayer/jwplatform/client/PlayerBiddingConfigClientTest.java new file mode 100644 index 0000000..9614ae5 --- /dev/null +++ b/src/test/java/com/jwplayer/jwplatform/client/PlayerBiddingConfigClientTest.java @@ -0,0 +1,73 @@ +package com.jwplayer.jwplatform.client; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ HttpCalls.class }) +public class PlayerBiddingConfigClientTest { + + VPBConfigsClient pbConfigsClient = VPBConfigsClient.getClient("fakeSecret"); + + @Test + public void testAllMethods() throws JWPlatformException { + pbConfigsClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"success\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("POST"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Object creation successful\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("DELETE"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Deletion success!\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PATCH"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Update successful\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Put successful\"}")); + JSONObject listResp = pbConfigsClient.listConfigs("siteId", new HashMap<>()); + assertEquals(listResp.get("code"), "success"); + JSONObject deleteResp = pbConfigsClient.deleteConfig("siteId", "configId"); + assertEquals(deleteResp.get("code"), "Deletion success!"); + Map params = new HashMap<>(); + params.put("title", "test"); + pbConfigsClient.createConfig("siteId", new HashMap<>()); + pbConfigsClient.createConfig("siteId", params); + pbConfigsClient.updateConfig("siteId", "configId", params); + pbConfigsClient.updateConfig("siteId", "configId", new HashMap<>()); + pbConfigsClient.getConfigById("siteId", "configId", new HashMap<>()); + JSONObject updateAdResp = pbConfigsClient.updateSchedules("siteId", params); + assertEquals(updateAdResp.get("code"), "Put successful"); + pbConfigsClient.updateSchedules("siteId", new HashMap<>()); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(9)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), anyString(), anyMap()); + pbConfigsClient.removeHeader("test"); + } + + @Test(expected = JWPlatformException.class) + public void testGetPbConfigsException() throws JSONException, JWPlatformException { + pbConfigsClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap())) + .thenThrow(new JWPlatformException("some exception occured")); + pbConfigsClient.listConfigs("siteId", new HashMap<>()); + } +} diff --git a/src/test/java/com/jwplayer/jwplatform/client/PlaylistsClientTest.java b/src/test/java/com/jwplayer/jwplatform/client/PlaylistsClientTest.java index da7387b..d46e17e 100644 --- a/src/test/java/com/jwplayer/jwplatform/client/PlaylistsClientTest.java +++ b/src/test/java/com/jwplayer/jwplatform/client/PlaylistsClientTest.java @@ -55,6 +55,7 @@ public void testAllMethods() throws JWPlatformException { playlistsClient.createDynamicPlaylist("siteId", params); playlistsClient.createManualPlaylist("siteId", params); playlistsClient.createRecommendationsPlaylist("siteId", params); + playlistsClient.createWatchlistPlaylist("siteId", params); playlistsClient.createSearchPlaylist("siteId", params); JSONObject createResp = playlistsClient.createTrendingPlaylist("siteId", params); assertEquals(createResp.get("code"), "Object creation successful"); @@ -63,6 +64,7 @@ public void testAllMethods() throws JWPlatformException { playlistsClient.deleteDynamicPlaylist("siteId", "playListID"); playlistsClient.deleteManualPlaylist("siteId", "playListID"); playlistsClient.deleteRecommendationsPlaylist("siteId", "playListID"); + playlistsClient.deleteWatchlistPlaylist("siteId", "playListID"); playlistsClient.deleteSearchPlaylist("siteId", "playListID"); playlistsClient.deleteTrendingPlaylist("siteId", "playListID"); JSONObject deleteResp = playlistsClient.deletePlaylistById("siteId", "playListID"); @@ -76,6 +78,7 @@ public void testAllMethods() throws JWPlatformException { playlistsClient.updateManualPlaylist("siteId", "playListID", new HashMap<>()); playlistsClient.updateRecommendationsPlaylist("siteId", "playListID", params); playlistsClient.updateRecommendationsPlaylist("siteId", "playListID", new HashMap<>()); + playlistsClient.updateWatchlistPlaylist("siteId", "playListID", new HashMap<>()); playlistsClient.updateSearchPlaylist("siteId", "playListID", params); playlistsClient.updateSearchPlaylist("siteId", "playListID", new HashMap<>()); playlistsClient.updateTrendingPlaylist("siteId", "playListID", params); @@ -86,11 +89,12 @@ public void testAllMethods() throws JWPlatformException { playlistsClient.retrieveDynamicPlaylistById("siteId", "playListID", new HashMap<>()); playlistsClient.retrieveManualPlaylistById("siteId", "playListID", new HashMap<>()); playlistsClient.retrieveRecommendationsPlaylistById("siteId", "playListID", new HashMap<>()); + playlistsClient.retrieveWatchlistPlaylistById("siteId", "playListID", new HashMap<>()); playlistsClient.retrieveSearchPlaylistById("siteId", "playListID", new HashMap<>()); playlistsClient.retrieveTrendingPlaylistById("siteId", "playListID", new HashMap<>()); playlistsClient.retrievePlaylistById("siteId", "playListID", new HashMap<>()); - PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(39)); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(43)); HttpCalls.request(anyString(), anyMap(), anyBoolean(), anyString(), anyMap()); playlistsClient.removeHeader("test"); } diff --git a/src/test/java/com/jwplayer/jwplatform/client/TagsClientTest.java b/src/test/java/com/jwplayer/jwplatform/client/TagsClientTest.java new file mode 100644 index 0000000..a369f38 --- /dev/null +++ b/src/test/java/com/jwplayer/jwplatform/client/TagsClientTest.java @@ -0,0 +1,54 @@ +package com.jwplayer.jwplatform.client; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + +import java.util.HashMap; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ HttpCalls.class }) +public class TagsClientTest { + + TagsClient tagsClient = TagsClient.getClient("fakeSecret"); + + @Test + public void testAllMethods() throws JWPlatformException { + tagsClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"success\"}")); + JSONObject bulkRemoveResponse = tagsClient.bulkRemoveTag("siteId", new HashMap<>()); + assertEquals(bulkRemoveResponse.get("code"), "success"); + JSONObject bulkRenameResponse = tagsClient.bulkRenameTag("siteId", new HashMap<>()); + assertEquals(bulkRenameResponse.get("code"), "success"); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(2)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), anyString(), anyMap()); + tagsClient.removeHeader("test"); + } + + @Test(expected = JWPlatformException.class) + public void testTagsException() throws JSONException, JWPlatformException { + tagsClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap())) + .thenThrow(new JWPlatformException("some exception occured")); + tagsClient.bulkRemoveTag("siteId", new HashMap<>()); + } +} diff --git a/src/test/java/com/jwplayer/jwplatform/client/TextTracksClientTest.java b/src/test/java/com/jwplayer/jwplatform/client/TextTracksClientTest.java new file mode 100644 index 0000000..b702dcf --- /dev/null +++ b/src/test/java/com/jwplayer/jwplatform/client/TextTracksClientTest.java @@ -0,0 +1,115 @@ +package com.jwplayer.jwplatform.client; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + +import java.util.HashMap; + +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; +import com.mashape.unirest.http.Unirest; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Unirest.class, HttpCalls.class }) +public class TextTracksClientTest { + TextTracksClient textTracksClient = TextTracksClient.getClient("fakeSecret");; + + @Test + public void testGetTextTrack() throws JWPlatformException { + mockStatic(HttpCalls.class); + JSONObject expected = new JSONObject(); + expected.append("page", 1); + expected.append("media", new JSONObject()); + expected.append("page_length", 1); + expected.append("total", 1); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap())).thenReturn(expected); + JSONObject actual = textTracksClient.listTextTracks("siteId", "mediaId", new HashMap()); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(1)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap()); + assertEquals(expected, actual); + } + + @Test + public void testCreateTextTrack() throws JWPlatformException { + mockStatic(HttpCalls.class); + JSONObject expected = new JSONObject("{\"code\":\"Success\"}"); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("POST"), anyMap())).thenReturn(expected); + JSONObject actual = textTracksClient.createTextTrack("siteId", "mediaId",new HashMap<>()); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(1)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("POST"), anyMap()); + assertEquals(expected, actual); + } + + @Test + public void testGetTextTrackById() throws JWPlatformException { + mockStatic(HttpCalls.class); + JSONObject expected = new JSONObject(); + expected.append("key", "value"); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap())).thenReturn(expected); + JSONObject actual = textTracksClient.getTextTrackById("siteId", "mediaId", "ajhsbjdsha", new HashMap<>()); + assertEquals(expected, actual); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(1)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap()); + } + + @Test + public void testDeleteTextTrack() throws JWPlatformException { + mockStatic(HttpCalls.class); + JSONObject expected = new JSONObject(); + expected.append("key", "value"); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("DELETE"), anyMap())).thenReturn(expected); + JSONObject actual = textTracksClient.deleteTextTrack("siteId", "mediaId", "ajhsbjdsha"); + assertEquals(expected, actual); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(1)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("DELETE"), anyMap()); + } + + @Test + public void testUpdateTextTrack() throws JWPlatformException { + mockStatic(HttpCalls.class); + JSONObject expected = new JSONObject(); + expected.append("key", "value"); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PATCH"), anyMap())).thenReturn(expected); + JSONObject actual = textTracksClient.updateTextTrack("siteId", "mediaId", "ajhsbjdsha", new HashMap<>()); + assertEquals(expected, actual); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(1)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PATCH"), anyMap()); + } + + @Test + public void testPublishTextTrack() throws JWPlatformException { + mockStatic(HttpCalls.class); + JSONObject expected = new JSONObject(); + expected.append("key", "value"); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap())).thenReturn(expected); + JSONObject actual = textTracksClient.publishTextTrack("siteId", "mediaId", "ajhsbjdsha", new HashMap<>()); + assertEquals(expected, actual); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(1)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap()); + } + + @Test + public void testUnpublishTextTrack() throws JWPlatformException { + mockStatic(HttpCalls.class); + JSONObject expected = new JSONObject(); + expected.append("key", "value"); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap())).thenReturn(expected); + JSONObject actual = textTracksClient.unpublishTextTrack("siteId", "mediaId", "ajhsbjdsha", new HashMap<>()); + assertEquals(expected, actual); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(1)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap()); + } +} diff --git a/src/test/java/com/jwplayer/jwplatform/client/ThumbnailsClientTest.java b/src/test/java/com/jwplayer/jwplatform/client/ThumbnailsClientTest.java new file mode 100644 index 0000000..bed95be --- /dev/null +++ b/src/test/java/com/jwplayer/jwplatform/client/ThumbnailsClientTest.java @@ -0,0 +1,69 @@ +package com.jwplayer.jwplatform.client; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + +import java.util.HashMap; +import java.util.Map; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ HttpCalls.class }) +public class ThumbnailsClientTest { + + ThumbnailsClient thumbnailClient = ThumbnailsClient.getClient("fakeSecret"); + + @Test + public void testAllMethods() throws JWPlatformException { + thumbnailClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"success\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("POST"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Object creation successful\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("DELETE"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Deletion success!\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PATCH"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Update successful\"}")); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"Put successful\"}")); + JSONObject listResp = thumbnailClient.listThumbnails("siteId", new HashMap<>()); + assertEquals(listResp.get("code"), "success"); + JSONObject deleteResp = thumbnailClient.deleteThumbnail("siteId", "thumbnailId"); + assertEquals(deleteResp.get("code"), "Deletion success!"); + Map params = new HashMap<>(); + params.put("title", "test"); + thumbnailClient.createThumbnail("siteId", new HashMap<>()); + thumbnailClient.createThumbnail("siteId", params); + thumbnailClient.updateThumbnail("siteId", "thumbnailId", params); + thumbnailClient.deleteThumbnail("siteId", "thumbnailId"); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(6)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), anyString(), anyMap()); + thumbnailClient.removeHeader("test"); + } + + @Test(expected = JWPlatformException.class) + public void testGetOriginalsException() throws JSONException, JWPlatformException { + thumbnailClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("GET"), anyMap())) + .thenThrow(new JWPlatformException("some exception occured")); + thumbnailClient.listThumbnails("siteId", new HashMap<>()); + } +} diff --git a/src/test/java/com/jwplayer/jwplatform/client/UsageClientTest.java b/src/test/java/com/jwplayer/jwplatform/client/UsageClientTest.java new file mode 100644 index 0000000..9b49560 --- /dev/null +++ b/src/test/java/com/jwplayer/jwplatform/client/UsageClientTest.java @@ -0,0 +1,54 @@ +package com.jwplayer.jwplatform.client; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + +import java.util.HashMap; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.jwplayer.jwplatform.exception.JWPlatformException; +import com.jwplayer.jwplatform.rest.HttpCalls; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ HttpCalls.class }) +public class UsageClientTest { + + UsageClient usageClient = UsageClient.getClient("fakeSecret"); + + @Test + public void testAllMethods() throws JWPlatformException { + usageClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap())) + .thenReturn(new JSONObject("{\"code\":\"success\"}")); + JSONObject queryAccountResponse = usageClient.queryAccountUsage(new HashMap<>()); + assertEquals(queryAccountResponse.get("code"), "success"); + JSONObject querySiteResponse = usageClient.querySiteUsage("siteId", new HashMap<>()); + assertEquals(querySiteResponse.get("code"), "success"); + PowerMockito.verifyStatic(HttpCalls.class, Mockito.times(2)); + HttpCalls.request(anyString(), anyMap(), anyBoolean(), anyString(), anyMap()); + usageClient.removeHeader("test"); + } + + @Test(expected = JWPlatformException.class) + public void testUsageException() throws JSONException, JWPlatformException { + usageClient.addHeader("test", "testVal"); + mockStatic(HttpCalls.class); + when(HttpCalls.request(anyString(), anyMap(), anyBoolean(), eq("PUT"), anyMap())) + .thenThrow(new JWPlatformException("some exception occured")); + usageClient.querySiteUsage("siteId", new HashMap<>()); + } +} diff --git a/src/test/java/com/jwplayer/jwplatform/client/VPBConfigsClientTest.java b/src/test/java/com/jwplayer/jwplatform/client/VPBConfigsClientTest.java index a1c42aa..5bc8022 100644 --- a/src/test/java/com/jwplayer/jwplatform/client/VPBConfigsClientTest.java +++ b/src/test/java/com/jwplayer/jwplatform/client/VPBConfigsClientTest.java @@ -70,4 +70,4 @@ public void testGetVpbConfigsException() throws JSONException, JWPlatformExcepti .thenThrow(new JWPlatformException("some exception occured")); vpbConfigsClient.listConfigs("siteId", new HashMap<>()); } -} +} \ No newline at end of file