diff --git a/README.md b/README.md index 9bdde6d..3d4b7c4 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,29 @@ $ mvn install } ``` +### Search creative images with phrase, custom parameter, and customer header +```java + String apiKey = "API Key"; + String apiSecret = "API Secret"; + String userName = "Username"; + String userPassword = "Password"; + + ApiClient client = ApiClient.GetApiClientWithResourceOwnerCredentials(apiKey, apiSecret, userName, userPassword); + + try { + SearchImagesCreative search = client.searchimagescreative() + .withPhrase("cat") + .withCustomParameter("safe_search", "true") + .withCustomHeader("gi-country-code", "CAN"); + String result = search.executeAsync(); + System.out.print(result); + + } catch (SdkException e) { + System.out.println("Exception occurred while searching for creative images: " + e.getLocalizedMessage()); + System.exit(-1); + } +``` + ### Custom Request to search images with phrase, fields, and age of people ```java diff --git a/src/main/java/com/gettyimages/api/Search/SearchImages.java b/src/main/java/com/gettyimages/api/Search/SearchImages.java index 57befc9..90b12a5 100644 --- a/src/main/java/com/gettyimages/api/Search/SearchImages.java +++ b/src/main/java/com/gettyimages/api/Search/SearchImages.java @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException { return super.executeAsync(); } + public SearchImages withCustomHeader(String key, String value) { + headers.put(key, value); + return this; + } + + public SearchImages withCustomParameter(String key, String value) { + queryParams.put(key, value); + return this; + } + public SearchImages withAcceptLanguage(String value) { headers.put(Constants.AcceptLanguageString, value); diff --git a/src/main/java/com/gettyimages/api/Search/SearchImagesCreative.java b/src/main/java/com/gettyimages/api/Search/SearchImagesCreative.java index d62f871..3f60f92 100644 --- a/src/main/java/com/gettyimages/api/Search/SearchImagesCreative.java +++ b/src/main/java/com/gettyimages/api/Search/SearchImagesCreative.java @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException { return super.executeAsync(); } + public SearchImagesCreative withCustomHeader(String key, String value) { + headers.put(key, value); + return this; + } + + public SearchImagesCreative withCustomParameter(String key, String value) { + queryParams.put(key, value); + return this; + } + public SearchImagesCreative withAcceptLanguage(String value) { headers.put(Constants.AcceptLanguageString, value); diff --git a/src/main/java/com/gettyimages/api/Search/SearchImagesEditorial.java b/src/main/java/com/gettyimages/api/Search/SearchImagesEditorial.java index a536e4e..4db88ea 100644 --- a/src/main/java/com/gettyimages/api/Search/SearchImagesEditorial.java +++ b/src/main/java/com/gettyimages/api/Search/SearchImagesEditorial.java @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException { return super.executeAsync(); } + public SearchImagesEditorial withCustomHeader(String key, String value) { + headers.put(key, value); + return this; + } + + public SearchImagesEditorial withCustomParameter(String key, String value) { + queryParams.put(key, value); + return this; + } + public SearchImagesEditorial withAcceptLanguage(String value) { headers.put(Constants.AcceptLanguageString, value); diff --git a/src/main/java/com/gettyimages/api/Search/SearchVideos.java b/src/main/java/com/gettyimages/api/Search/SearchVideos.java index 4412bd0..6fe9fc6 100644 --- a/src/main/java/com/gettyimages/api/Search/SearchVideos.java +++ b/src/main/java/com/gettyimages/api/Search/SearchVideos.java @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException { return super.executeAsync(); } + public SearchVideos withCustomHeader(String key, String value) { + headers.put(key, value); + return this; + } + + public SearchVideos withCustomParameter(String key, String value) { + queryParams.put(key, value); + return this; + } + public SearchVideos withAcceptLanguage(String value) { headers.put(Constants.AcceptLanguageString, value); diff --git a/src/main/java/com/gettyimages/api/Search/SearchVideosCreative.java b/src/main/java/com/gettyimages/api/Search/SearchVideosCreative.java index bbb96e4..801f96d 100644 --- a/src/main/java/com/gettyimages/api/Search/SearchVideosCreative.java +++ b/src/main/java/com/gettyimages/api/Search/SearchVideosCreative.java @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException { return super.executeAsync(); } + public SearchVideosCreative withCustomHeader(String key, String value) { + headers.put(key, value); + return this; + } + + public SearchVideosCreative withCustomParameter(String key, String value) { + queryParams.put(key, value); + return this; + } + public SearchVideosCreative withAcceptLanguage(String value) { headers.put(Constants.AcceptLanguageString, value); diff --git a/src/main/java/com/gettyimages/api/Search/SearchVideosEditorial.java b/src/main/java/com/gettyimages/api/Search/SearchVideosEditorial.java index 3709bd3..28c766e 100644 --- a/src/main/java/com/gettyimages/api/Search/SearchVideosEditorial.java +++ b/src/main/java/com/gettyimages/api/Search/SearchVideosEditorial.java @@ -26,6 +26,16 @@ public String executeAsync() throws SdkException { return super.executeAsync(); } + public SearchVideosEditorial withCustomHeader(String key, String value) { + headers.put(key, value); + return this; + } + + public SearchVideosEditorial withCustomParameter(String key, String value) { + queryParams.put(key, value); + return this; + } + public SearchVideosEditorial withAcceptLanguage(String value) { headers.put(Constants.AcceptLanguageString, value); diff --git a/src/test/java/AuthFailureTest.java b/src/test/java/AuthFailureTest.java index 86172b3..1dc853c 100644 --- a/src/test/java/AuthFailureTest.java +++ b/src/test/java/AuthFailureTest.java @@ -1,4 +1,4 @@ -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockserver.integration.ClientAndServer.startClientAndServer; import static org.mockserver.model.HttpRequest.request; diff --git a/src/test/java/CustomRequestTest.java b/src/test/java/CustomRequestTest.java index 24e3f0b..12ae0cb 100644 --- a/src/test/java/CustomRequestTest.java +++ b/src/test/java/CustomRequestTest.java @@ -37,10 +37,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -53,81 +49,80 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("phrase", "cat"), - new Parameter("compositions", "abstract,full_frame") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("phrase", "cat"), + new Parameter("compositions", "abstract,full_frame") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("POST") - .withPath("/downloads/images/12345") - .withQueryStringParameters( - new Parameter("auto_download", "false") - ) - ) + request() + .withMethod("POST") + .withPath("/downloads/images/12345") + .withQueryStringParameters( + new Parameter("auto_download", "false") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("POST") - .withPath("/boards") - .withBody( - json("{" + System.lineSeparator() + - " \"name\": \"new board\"," + System.lineSeparator() + - " \"description\": \"new description\"" + System.lineSeparator() + - "}", - MatchType.STRICT + request() + .withMethod("POST") + .withPath("/boards") + .withBody( + json("{" + System.lineSeparator() + + " \"name\": \"new board\"," + System.lineSeparator() + + " \"description\": \"new description\"" + System.lineSeparator() + + "}", + MatchType.STRICT + ) ) - ) - ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("PUT") - .withPath("/asset-changes/change-sets") - .withQueryStringParameters( - new Parameter("channel_id", "3") - ) - ) + request() + .withMethod("PUT") + .withPath("/asset-changes/change-sets") + .withQueryStringParameters( + new Parameter("channel_id", "3") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("PUT") - .withPath("/boards/111") - .withBody( - json("{" + System.lineSeparator() + - " \"name\": \"new board\"," + System.lineSeparator() + - " \"description\": \"new description\"" + System.lineSeparator() + - "}", - MatchType.STRICT + request() + .withMethod("PUT") + .withPath("/boards/111") + .withBody( + json("{" + System.lineSeparator() + + " \"name\": \"new board\"," + System.lineSeparator() + + " \"description\": \"new description\"" + System.lineSeparator() + + "}", + MatchType.STRICT + ) ) - ) - ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("DELETE") - .withPath("/boards/333") - .withQueryStringParameters( - new Parameter("asset_ids", "1234,5678") - ) - ) + request() + .withMethod("DELETE") + .withPath("/boards/333") + .withQueryStringParameters( + new Parameter("asset_ids", "1234,5678") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("phrase", "cat") - ) - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("phrase", "cat") + ) + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); - } @Test diff --git a/src/test/java/DownloadImagesTest.java b/src/test/java/DownloadImagesTest.java index 63aac36..08558bf 100644 --- a/src/test/java/DownloadImagesTest.java +++ b/src/test/java/DownloadImagesTest.java @@ -28,10 +28,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -44,54 +40,54 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("POST") - .withPath("/downloads/images/12345") - .withQueryStringParameters( - new Parameter("auto_download", "false") - ) - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("POST") + .withPath("/downloads/images/12345") + .withQueryStringParameters( + new Parameter("auto_download", "false") + ) + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("POST") - .withPath("/downloads/images/12345") - .withQueryStringParameters( - new Parameter("file_type", "jpg"), - new Parameter("auto_download", "false") - ) - ) + request() + .withMethod("POST") + .withPath("/downloads/images/12345") + .withQueryStringParameters( + new Parameter("file_type", "jpg"), + new Parameter("auto_download", "false") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("POST") - .withPath("/downloads/images/12345") - .withQueryStringParameters( - new Parameter("auto_download", "false"), - new Parameter("height", "592") - ) - ) + request() + .withMethod("POST") + .withPath("/downloads/images/12345") + .withQueryStringParameters( + new Parameter("auto_download", "false"), + new Parameter("height", "592") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("POST") - .withPath("/downloads/images/12345") - .withQueryStringParameters( - new Parameter("product_id", "9876"), - new Parameter("auto_download", "false") - ) - ) + request() + .withMethod("POST") + .withPath("/downloads/images/12345") + .withQueryStringParameters( + new Parameter("product_id", "9876"), + new Parameter("auto_download", "false") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("POST") - .withPath("/downloads/images/12345") - .withQueryStringParameters( - new Parameter("product_type", "easyaccess"), - new Parameter("auto_download", "false") - ) - ) + request() + .withMethod("POST") + .withPath("/downloads/images/12345") + .withQueryStringParameters( + new Parameter("product_type", "easyaccess"), + new Parameter("auto_download", "false") + ) + ) .respond(response().withStatusCode(200).withBody("success")); } diff --git a/src/test/java/DownloadVideosTest.java b/src/test/java/DownloadVideosTest.java index 6fdb9d7..4143e8c 100644 --- a/src/test/java/DownloadVideosTest.java +++ b/src/test/java/DownloadVideosTest.java @@ -26,10 +26,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -42,34 +38,34 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("POST") - .withPath("/downloads/videos/12345") - .withQueryStringParameters( - new Parameter("auto_download", "false") - ) - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("POST") + .withPath("/downloads/videos/12345") + .withQueryStringParameters( + new Parameter("auto_download", "false") + ) + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("POST") - .withPath("/downloads/videos/12345") - .withQueryStringParameters( - new Parameter("product_id", "9876"), - new Parameter("auto_download", "false") - ) - ) + request() + .withMethod("POST") + .withPath("/downloads/videos/12345") + .withQueryStringParameters( + new Parameter("product_id", "9876"), + new Parameter("auto_download", "false") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("POST") - .withPath("/downloads/videos/12345") - .withQueryStringParameters( - new Parameter("size", "size"), - new Parameter("auto_download", "false") - ) - ) + request() + .withMethod("POST") + .withPath("/downloads/videos/12345") + .withQueryStringParameters( + new Parameter("size", "size"), + new Parameter("auto_download", "false") + ) + ) .respond(response().withStatusCode(200).withBody("success")); } diff --git a/src/test/java/ImagesTest.java b/src/test/java/ImagesTest.java index c481cc1..571b8c8 100644 --- a/src/test/java/ImagesTest.java +++ b/src/test/java/ImagesTest.java @@ -27,10 +27,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -43,29 +39,29 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("GET") - .withPath("/images/12345") - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("GET") + .withPath("/images/12345") + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/images/12345") - .withQueryStringParameters( - new Parameter("fields", "country,id") - ) - ) + request() + .withMethod("GET") + .withPath("/images/12345") + .withQueryStringParameters( + new Parameter("fields", "country,id") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/images") - .withQueryStringParameters( - new Parameter("ids", "12345,678910") - ) - ) + request() + .withMethod("GET") + .withPath("/images") + .withQueryStringParameters( + new Parameter("ids", "12345,678910") + ) + ) .respond(response().withStatusCode(200).withBody("success")); } diff --git a/src/test/java/SearchImagesCreativeTest.java b/src/test/java/SearchImagesCreativeTest.java index 6bd0cd0..443c18f 100644 --- a/src/test/java/SearchImagesCreativeTest.java +++ b/src/test/java/SearchImagesCreativeTest.java @@ -28,10 +28,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -44,209 +40,225 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("age_of_people", "baby,child,adult") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("age_of_people", "baby,child,adult") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("artists", "roman makhmutov") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("artists", "roman makhmutov") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("collection_codes", "WRI,ARF") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("collection_codes", "WRI,ARF") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("collections_filter_type", "exclude") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("collections_filter_type", "exclude") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("color", "#002244") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("color", "#002244") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("compositions", "abstract,headshot") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("compositions", "abstract,headshot") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("embed_content_only", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("embed_content_only", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("ethnicity", "black,japanese") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("ethnicity", "black,japanese") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("exclude_nudity", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("exclude_nudity", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("fields", "asset_family,id,uri_oembed") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("fields", "asset_family,id,uri_oembed") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("file_types", "eps,jpg") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("file_types", "eps,jpg") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("graphical_styles", "fine_art,illustration") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("graphical_styles", "fine_art,illustration") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("keyword_ids", "1111,2222,3333") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("keyword_ids", "1111,2222,3333") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("minimum_size", "small") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("minimum_size", "small") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("number_of_people", "one,group") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("number_of_people", "one,group") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("orientations", "Horizontal,Square") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("orientations", "Horizontal,Square") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("page", "3") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("page", "3") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("page_size", "50") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("page_size", "50") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("phrase", "cat") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("phrase", "cat") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("prestige_content_only", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("prestige_content_only", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("product_types", "easyaccess,editorialsubscription") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("product_types", "easyaccess,editorialsubscription") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("sort_order", "newest") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/creative") - .withQueryStringParameters( - new Parameter("sort_order", "newest") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withQueryStringParameters( + new Parameter("safe_search", "true") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/images/creative") + .withHeader("gi-country-code", "CAN") + ) .respond(response().withStatusCode(200).withBody("success")); } @@ -458,6 +470,24 @@ void searchImagesCreativeWithSortOrder() throws Exception { assertEquals("success", result); } + @Test + void searchImagesCreativeWithCustomParameter() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchImagesCreative search = client.searchimagescreative() + .withCustomParameter("safe_search", "true"); + String result = search.executeAsync(); + assertEquals("success", result); + } + + @Test + void searchImagesCreativeWithCustomHeader() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchImagesCreative search = client.searchimagescreative() + .withCustomHeader("gi-country-code", "CAN"); + String result = search.executeAsync(); + assertEquals("success", result); + } + @AfterAll public static void stopProxy() { mockServer.stop(); diff --git a/src/test/java/SearchImagesEditorialTest.java b/src/test/java/SearchImagesEditorialTest.java index 05241ee..34bf5ba 100644 --- a/src/test/java/SearchImagesEditorialTest.java +++ b/src/test/java/SearchImagesEditorialTest.java @@ -1,6 +1,7 @@ import com.gettyimages.api.ApiClient; import com.gettyimages.api.Filters.*; +import com.gettyimages.api.Search.SearchImagesCreative; import com.gettyimages.api.Search.SearchImagesEditorial; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -28,10 +29,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -44,254 +41,270 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("age_of_people", "baby,child,adult") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("age_of_people", "baby,child,adult") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("artists", "roman makhmutov") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("artists", "roman makhmutov") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("collection_codes", "WRI,ARF") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("collection_codes", "WRI,ARF") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("collections_filter_type", "exclude") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("collections_filter_type", "exclude") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("compositions", "abstract,headshot") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("compositions", "abstract,headshot") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("editorial_segments", "archival,publicity") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("editorial_segments", "archival,publicity") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("embed_content_only", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("embed_content_only", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("end_date", "2015-04-01") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("end_date", "2015-04-01") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("entity_uris", "uri1,uri2") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("entity_uris", "uri1,uri2") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("ethnicity", "black,japanese") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("ethnicity", "black,japanese") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("event_ids", "123,456,789") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("event_ids", "123,456,789") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("exclude_nudity", "true") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("fields", "asset_family,id,uri_oembed") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("exclude_nudity", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("file_types", "eps,jpg") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("fields", "asset_family,id,uri_oembed") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("graphical_styles", "fine_art,illustration") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("file_types", "eps,jpg") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("keyword_ids", "1111,2222,3333") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("graphical_styles", "fine_art,illustration") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("minimum_quality_rank", "1") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("keyword_ids", "1111,2222,3333") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("minimum_size", "small") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("minimum_quality_rank", "1") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("number_of_people", "one,group") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("minimum_size", "small") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("orientations", "Horizontal,Square") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("number_of_people", "one,group") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("page", "3") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("orientations", "Horizontal,Square") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("page_size", "50") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("page", "3") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("phrase", "cat") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("page_size", "50") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("product_types", "easyaccess,editorialsubscription") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("phrase", "cat") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("sort_order", "newest") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("product_types", "easyaccess,editorialsubscription") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("specific_people", "Reggie Jackson") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("sort_order", "newest") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("start_date", "2015-04-01") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("specific_people", "Reggie Jackson") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withQueryStringParameters( + new Parameter("include_related_searches", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images/editorial") - .withQueryStringParameters( - new Parameter("start_date", "2015-04-01") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images/editorial") + .withHeader("gi-country-code", "CAN") + ) .respond(response().withStatusCode(200).withBody("success")); } @@ -549,6 +562,24 @@ void searchImagesEditorialWithStartDate() throws Exception { assertEquals("success", result); } + @Test + void searchImagesEditorialWithCustomParameter() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchImagesEditorial search = client.searchimageseditorial() + .withCustomParameter("include_related_searches", "true"); + String result = search.executeAsync(); + assertEquals("success", result); + } + + @Test + void searchImagesEditorialWithCustomHeader() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchImagesEditorial search = client.searchimageseditorial() + .withCustomHeader("gi-country-code", "CAN"); + String result = search.executeAsync(); + assertEquals("success", result); + } + @AfterAll public static void stopProxy() { mockServer.stop(); diff --git a/src/test/java/SearchImagesTest.java b/src/test/java/SearchImagesTest.java index 3af0225..8e90742 100644 --- a/src/test/java/SearchImagesTest.java +++ b/src/test/java/SearchImagesTest.java @@ -2,6 +2,7 @@ import com.gettyimages.api.ApiClient; import com.gettyimages.api.Filters.*; import com.gettyimages.api.Search.SearchImages; +import com.gettyimages.api.Search.SearchImagesCreative; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -28,10 +29,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -44,227 +41,243 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("age_of_people", "baby,child,adult") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("age_of_people", "baby,child,adult") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("artists", "roman makhmutov") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("artists", "roman makhmutov") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("collection_codes", "WRI,ARF") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("collection_codes", "WRI,ARF") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("collections_filter_type", "exclude") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("collections_filter_type", "exclude") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("color", "#002244") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("color", "#002244") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("compositions", "abstract,headshot") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("compositions", "abstract,headshot") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("embed_content_only", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("embed_content_only", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("ethnicity", "black,japanese") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("ethnicity", "black,japanese") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("event_ids", "123,456,789") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("event_ids", "123,456,789") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("exclude_nudity", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("exclude_nudity", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("fields", "asset_family,id,uri_oembed") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("fields", "asset_family,id,uri_oembed") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("file_types", "eps,jpg") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("file_types", "eps,jpg") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("graphical_styles", "fine_art,illustration") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("graphical_styles", "fine_art,illustration") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("keyword_ids", "1111,2222,3333") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("keyword_ids", "1111,2222,3333") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("minimum_size", "small") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("minimum_size", "small") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("number_of_people", "one,group") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("number_of_people", "one,group") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("orientations", "Horizontal,Square") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("orientations", "Horizontal,Square") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("page", "3") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("page", "3") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("page_size", "50") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("page_size", "50") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("phrase", "cat") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("phrase", "cat") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("prestige_content_only", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("prestige_content_only", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("product_types", "easyaccess,editorialsubscription") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("product_types", "easyaccess,editorialsubscription") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("sort_order", "newest") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("specific_people", "Reggie Jackson") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("sort_order", "newest") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withQueryStringParameters( + new Parameter("include_related_searches", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/images") - .withQueryStringParameters( - new Parameter("specific_people", "Reggie Jackson") - ) - ) + request() + .withMethod("GET") + .withPath("/search/images") + .withHeader("gi-country-code", "CAN") + ) .respond(response().withStatusCode(200).withBody("success")); } @@ -494,6 +507,24 @@ void searchImagesWithSpecificPeople() throws Exception { assertEquals("success", result); } + @Test + void searchImagesWithCustomParameter() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchImages search = client.searchimages() + .withCustomParameter("include_related_searches", "true"); + String result = search.executeAsync(); + assertEquals("success", result); + } + + @Test + void searchImagesWithCustomHeader() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchImages search = client.searchimages() + .withCustomHeader("gi-country-code", "CAN"); + String result = search.executeAsync(); + assertEquals("success", result); + } + @AfterAll public static void stopProxy() { mockServer.stop(); diff --git a/src/test/java/SearchVideosCreativeTest.java b/src/test/java/SearchVideosCreativeTest.java index f5a53fe..ee3f9fc 100644 --- a/src/test/java/SearchVideosCreativeTest.java +++ b/src/test/java/SearchVideosCreativeTest.java @@ -1,6 +1,7 @@ import com.gettyimages.api.ApiClient; import com.gettyimages.api.Filters.*; +import com.gettyimages.api.Search.SearchImagesCreative; import com.gettyimages.api.Search.SearchVideosCreative; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -28,10 +29,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -44,137 +41,153 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("age_of_people", "baby,child,adult") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("age_of_people", "baby,child,adult") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("collection_codes", "WRI,ARF") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("collection_codes", "WRI,ARF") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("collections_filter_type", "exclude") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("collections_filter_type", "exclude") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("exclude_nudity", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("exclude_nudity", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("fields", "asset_family,id,uri_oembed") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("fields", "asset_family,id,uri_oembed") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("format_available", "hd") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("format_available", "hd") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("frame_rates", "24,29.97") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("frame_rates", "24,29.97") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("keyword_ids", "1111,2222,3333") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("keyword_ids", "1111,2222,3333") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("license_models", "rightsmanaged") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("license_models", "rightsmanaged") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("page", "3") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("page", "3") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("page_size", "50") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("page_size", "50") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("phrase", "cat") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("phrase", "cat") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("product_types", "easyaccess,editorialsubscription") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("product_types", "easyaccess,editorialsubscription") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/creative") - .withQueryStringParameters( - new Parameter("sort_order", "newest") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("sort_order", "newest") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withQueryStringParameters( + new Parameter("safe_search", "true") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/videos/creative") + .withHeader("gi-country-code", "CAN") + ) .respond(response().withStatusCode(200).withBody("success")); } @@ -313,6 +326,24 @@ void searchVideosCreativeWithSortOrder() throws Exception { assertEquals("success", result); } + @Test + void searchVideosCreativeWithCustomParameter() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchVideosCreative search = client.searchvideoscreative() + .withCustomParameter("safe_search", "true"); + String result = search.executeAsync(); + assertEquals("success", result); + } + + @Test + void searchVideosCreativeWithCustomHeader() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchVideosCreative search = client.searchvideoscreative() + .withCustomHeader("gi-country-code", "CAN"); + String result = search.executeAsync(); + assertEquals("success", result); + } + @AfterAll public static void stopProxy() { mockServer.stop(); diff --git a/src/test/java/SearchVideosEditorialTest.java b/src/test/java/SearchVideosEditorialTest.java index dca65fa..3ad54b2 100644 --- a/src/test/java/SearchVideosEditorialTest.java +++ b/src/test/java/SearchVideosEditorialTest.java @@ -1,6 +1,7 @@ import com.gettyimages.api.ApiClient; import com.gettyimages.api.Filters.*; +import com.gettyimages.api.Search.SearchVideos; import com.gettyimages.api.Search.SearchVideosEditorial; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -28,10 +29,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -44,155 +41,171 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("age_of_people", "baby,child,adult") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("age_of_people", "baby,child,adult") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("collection_codes", "WRI,ARF") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("collection_codes", "WRI,ARF") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("collections_filter_type", "exclude") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("collections_filter_type", "exclude") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("editorial_video_types", "raw,produced") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("editorial_video_types", "raw,produced") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("entity_uris", "uri1,uri2") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("entity_uris", "uri1,uri2") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("exclude_nudity", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("exclude_nudity", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("fields", "asset_family,id,uri_oembed") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("fields", "asset_family,id,uri_oembed") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("format_available", "hd") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("format_available", "hd") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("frame_rates", "24,29.97") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("frame_rates", "24,29.97") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("keyword_ids", "1111,2222,3333") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("keyword_ids", "1111,2222,3333") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("page", "3") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("page", "3") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("page_size", "50") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("page_size", "50") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("phrase", "cat") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("phrase", "cat") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("product_types", "easyaccess,editorialsubscription") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("product_types", "easyaccess,editorialsubscription") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("sort_order", "newest") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("sort_order", "newest") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos/editorial") - .withQueryStringParameters( - new Parameter("specific_people", "Reggie Jackson") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("specific_people", "Reggie Jackson") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withQueryStringParameters( + new Parameter("include_related_searches", "true") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/videos/editorial") + .withHeader("gi-country-code", "CAN") + ) .respond(response().withStatusCode(200).withBody("success")); } @@ -349,6 +362,24 @@ void searchVideosEditorialWithSpecificPeople() throws Exception { assertEquals("success", result); } + @Test + void searchVideosEditorialWithCustomParameter() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchVideosEditorial search = client.searchvideoseditorial() + .withCustomParameter("include_related_searches", "true"); + String result = search.executeAsync(); + assertEquals("success", result); + } + + @Test + void searchVideosEditorialWithCustomHeader() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchVideosEditorial search = client.searchvideoseditorial() + .withCustomHeader("gi-country-code", "CAN"); + String result = search.executeAsync(); + assertEquals("success", result); + } + @AfterAll public static void stopProxy() { mockServer.stop(); diff --git a/src/test/java/SearchVideosTest.java b/src/test/java/SearchVideosTest.java index 7b5ffea..d791011 100644 --- a/src/test/java/SearchVideosTest.java +++ b/src/test/java/SearchVideosTest.java @@ -1,6 +1,7 @@ import com.gettyimages.api.ApiClient; import com.gettyimages.api.Filters.*; +import com.gettyimages.api.Search.SearchImages; import com.gettyimages.api.Search.SearchVideos; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -28,10 +29,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -44,155 +41,171 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("age_of_people", "baby,child,adult") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("age_of_people", "baby,child,adult") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("collection_codes", "WRI,ARF") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("collection_codes", "WRI,ARF") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("collections_filter_type", "exclude") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("collections_filter_type", "exclude") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("editorial_video_types", "raw,produced") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("editorial_video_types", "raw,produced") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("exclude_nudity", "true") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("exclude_nudity", "true") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("fields", "asset_family,id,uri_oembed") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("fields", "asset_family,id,uri_oembed") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("format_available", "hd") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("format_available", "hd") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("frame_rates", "24,29.97") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("frame_rates", "24,29.97") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("keyword_ids", "1111,2222,3333") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("keyword_ids", "1111,2222,3333") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("license_models", "rightsmanaged") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("license_models", "rightsmanaged") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("page", "3") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("page", "3") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("page_size", "50") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("page_size", "50") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("phrase", "cat") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("phrase", "cat") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("product_types", "easyaccess,editorialsubscription") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("product_types", "easyaccess,editorialsubscription") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("sort_order", "newest") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("sort_order", "newest") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/search/videos") - .withQueryStringParameters( - new Parameter("specific_people", "Reggie Jackson") - ) - ) + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("specific_people", "Reggie Jackson") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/videos") + .withQueryStringParameters( + new Parameter("include_related_searches", "true") + ) + ) + .respond(response().withStatusCode(200).withBody("success")); + client.when( + request() + .withMethod("GET") + .withPath("/search/videos") + .withHeader("gi-country-code", "CAN") + ) .respond(response().withStatusCode(200).withBody("success")); } @@ -349,6 +362,24 @@ void searchVideosWithSpecificPeople() throws Exception { assertEquals("success", result); } + @Test + void searchVideosWithCustomParameter() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchVideos search = client.searchvideos() + .withCustomParameter("include_related_searches", "true"); + String result = search.executeAsync(); + assertEquals("success", result); + } + + @Test + void searchVideosWithCustomHeader() throws Exception { + ApiClient client = ApiClient.GetApiClientWithClientCredentials("apiKey", "apiSecret"); + SearchVideos search = client.searchvideos() + .withCustomHeader("gi-country-code", "CAN"); + String result = search.executeAsync(); + assertEquals("success", result); + } + @AfterAll public static void stopProxy() { mockServer.stop(); diff --git a/src/test/java/VideosTest.java b/src/test/java/VideosTest.java index 6946543..b6973fc 100644 --- a/src/test/java/VideosTest.java +++ b/src/test/java/VideosTest.java @@ -27,10 +27,6 @@ public static void startProxy() throws Exception { field.setAccessible(true); field.set(null, "http://127.0.0.1:1080/"); mockServer = startClientAndServer(1080); - } - - @BeforeEach - public void createMock(){ MockServerClient client = new MockServerClient("127.0.0.1", 1080); client @@ -43,29 +39,29 @@ public void createMock(){ .withBody("{ access_token: 'client_credentials_access_token', token_type: 'Bearer', expires_in: '1800' }") ); client.when( - request() - .withMethod("GET") - .withPath("/videos/12345") - .withHeader("Accept-Language", "de") - ) + request() + .withMethod("GET") + .withPath("/videos/12345") + .withHeader("Accept-Language", "de") + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/videos/12345") - .withQueryStringParameters( - new Parameter("fields", "country,id") - ) - ) + request() + .withMethod("GET") + .withPath("/videos/12345") + .withQueryStringParameters( + new Parameter("fields", "country,id") + ) + ) .respond(response().withStatusCode(200).withBody("success")); client.when( - request() - .withMethod("GET") - .withPath("/videos") - .withQueryStringParameters( - new Parameter("ids", "12345,678910") - ) - ) + request() + .withMethod("GET") + .withPath("/videos") + .withQueryStringParameters( + new Parameter("ids", "12345,678910") + ) + ) .respond(response().withStatusCode(200).withBody("success")); }