From 85e24e718195876fc7bf936b3da636e1e0049f04 Mon Sep 17 00:00:00 2001 From: Olivier Lando Date: Wed, 2 Oct 2024 14:42:08 +0200 Subject: [PATCH] Add tests --- oas_apivideo.yaml | 6 +-- .../api/client/api/clients/TagsApiTest.java | 42 +++++++++++++++++++ .../api/client/api/clients/TagsApiTest.java | 42 +++++++++++++++++++ 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/oas_apivideo.yaml b/oas_apivideo.yaml index 82ea71ba..eb3e04ac 100644 --- a/oas_apivideo.yaml +++ b/oas_apivideo.yaml @@ -990,11 +990,11 @@ paths: currentPageItems: 2 links: - rel: self - uri: 'https://ws.api.video/watermarks?currentPage=1' + uri: '/tags?currentPage=1&pageSize=25' - rel: first - uri: 'https://ws.api.video/watermarks?currentPage=1' + uri: '/tags?currentPage=1&pageSize=25' - rel: last - uri: 'https://ws.api.video/watermarks?currentPage=1' + uri: '/tags?currentPage=1&pageSize=25' '429': headers: X-RateLimit-Limit: diff --git a/templates/java/statics/android/src/test/java/video/api/client/api/clients/TagsApiTest.java b/templates/java/statics/android/src/test/java/video/api/client/api/clients/TagsApiTest.java index 92976afb..f9df4b5b 100644 --- a/templates/java/statics/android/src/test/java/video/api/client/api/clients/TagsApiTest.java +++ b/templates/java/statics/android/src/test/java/video/api/client/api/clients/TagsApiTest.java @@ -1,9 +1,51 @@ package video.api.client.api.clients; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import video.api.client.api.ApiException; +import video.api.client.api.models.ListTagsResponseData; +import video.api.client.api.models.Page; +import video.api.client.api.models.PaginationLink; + +import java.net.URI; + +import static org.assertj.core.api.Assertions.assertThat; + /** * API tests for TagsApi */ @DisplayName("TagsApi") public class TagsApiTest extends AbstractApiTest { + private final TagsApi api = apiClientMock.tags(); + + @Nested + @DisplayName("list") + class listTags { + private static final String PAYLOADS_PATH = "/payloads/tags/list/"; + + + @Test + @DisplayName("200 response") + public void responseWithStatus200Test() throws ApiException { + answerOnAnyRequest(200, readResourceFile(PAYLOADS_PATH + "responses/200.json")); + + Page res = api.list().execute(); + + assertThat(res.getCurrentPage()).isEqualTo(1); + assertThat(res.getPageSize()).isEqualTo(25); + assertThat(res.getPagesTotal()).isEqualTo(1); + assertThat(res.getCurrentPageItems()).isEqualTo(2); + assertThat(res.getLinks()).containsExactlyInAnyOrder( + new PaginationLink().rel("self").uri(URI.create("/tags?currentPage=1&pageSize=25")), + new PaginationLink().rel("first").uri(URI.create("/tags?currentPage=1&pageSize=25")), + new PaginationLink().rel("last").uri(URI.create("/tags?currentPage=1&pageSize=25"))); + + assertThat(res.getItems()).containsExactlyInAnyOrder( + new ListTagsResponseData().value("maths").videoCount(33), + new ListTagsResponseData().value("tutorials").videoCount(10) + ); + } + } + } diff --git a/templates/java/statics/java/src/test/java/video/api/client/api/clients/TagsApiTest.java b/templates/java/statics/java/src/test/java/video/api/client/api/clients/TagsApiTest.java index 92976afb..f9df4b5b 100644 --- a/templates/java/statics/java/src/test/java/video/api/client/api/clients/TagsApiTest.java +++ b/templates/java/statics/java/src/test/java/video/api/client/api/clients/TagsApiTest.java @@ -1,9 +1,51 @@ package video.api.client.api.clients; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import video.api.client.api.ApiException; +import video.api.client.api.models.ListTagsResponseData; +import video.api.client.api.models.Page; +import video.api.client.api.models.PaginationLink; + +import java.net.URI; + +import static org.assertj.core.api.Assertions.assertThat; + /** * API tests for TagsApi */ @DisplayName("TagsApi") public class TagsApiTest extends AbstractApiTest { + private final TagsApi api = apiClientMock.tags(); + + @Nested + @DisplayName("list") + class listTags { + private static final String PAYLOADS_PATH = "/payloads/tags/list/"; + + + @Test + @DisplayName("200 response") + public void responseWithStatus200Test() throws ApiException { + answerOnAnyRequest(200, readResourceFile(PAYLOADS_PATH + "responses/200.json")); + + Page res = api.list().execute(); + + assertThat(res.getCurrentPage()).isEqualTo(1); + assertThat(res.getPageSize()).isEqualTo(25); + assertThat(res.getPagesTotal()).isEqualTo(1); + assertThat(res.getCurrentPageItems()).isEqualTo(2); + assertThat(res.getLinks()).containsExactlyInAnyOrder( + new PaginationLink().rel("self").uri(URI.create("/tags?currentPage=1&pageSize=25")), + new PaginationLink().rel("first").uri(URI.create("/tags?currentPage=1&pageSize=25")), + new PaginationLink().rel("last").uri(URI.create("/tags?currentPage=1&pageSize=25"))); + + assertThat(res.getItems()).containsExactlyInAnyOrder( + new ListTagsResponseData().value("maths").videoCount(33), + new ListTagsResponseData().value("tutorials").videoCount(10) + ); + } + } + }