Skip to content

Commit

Permalink
Fix java tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier-lando committed Jul 23, 2024
1 parent b07db83 commit 2542fb6
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ private void handlePagination(List<Object> allModels, CodegenOperation operation
System.out.println(model);
model.allVars.stream().filter(v -> v.name.equals("data")).findFirst().ifPresent(codegenProperty -> {
Map<String, String> paginationProperties = new HashMap<>();
paginationProperties.put("type", codegenProperty.dataType.substring(codegenProperty.dataType.indexOf("<") + 1, codegenProperty.dataType.indexOf(">")));
if(codegenProperty.dataType.contains("<") && codegenProperty.dataType.contains(">")) {
paginationProperties.put("type", codegenProperty.dataType.substring(codegenProperty.dataType.indexOf("<") + 1, codegenProperty.dataType.indexOf(">")));
} else {
paginationProperties.put("type", codegenProperty.dataType);
}
paginationProperties.put("getter", codegenProperty.getter);
operation.vendorExtensions.put("x-pagination", paginationProperties);
});
Expand Down
12 changes: 3 additions & 9 deletions oas_apivideo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11663,8 +11663,6 @@ paths:
schema:
type: string
example: filterBy[continent]=EU&filterBy[country]=FR&filterBy[browser]=Safari&filterBy[browser]=Firefox
- $ref: '#/components/parameters/current-page'
- $ref: '#/components/parameters/page-size'
responses:
'200':
headers:
Expand Down Expand Up @@ -11786,7 +11784,6 @@ paths:
- apiKey: []
x-client-action: getAggregatedMetrics
x-group-parameters: true
x-client-paginated: true
x-doctave:
code-samples:
'/data/buckets/{metric}/{breakdown}':
Expand Down Expand Up @@ -14613,12 +14610,9 @@ components:
format: date-time
example: '2024-05-29T11:15:07+00:00'
data:
items:
type: number
format: float
example: '356.2'
pagination:
$ref: '#/components/schemas/pagination'
type: number
format: float
example: '356.2'
required:
- context
- data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,50 +47,38 @@ public void requiredParametersTest() {
answerOnAnyRequest(201, "{}");

assertThatNoException().isThrownBy(() -> api.getAggregatedMetrics("play", "count").execute());
//String metric, String aggregation, OffsetDateTime from, OffsetDateTime to, String filterBy, Integer currentPage, Integer pageSize
// String metric, String aggregation, OffsetDateTime from, OffsetDateTime to, String filterBy, Integer
// currentPage, Integer pageSize
}

@Test
@DisplayName("200 response")
public void responseWithStatus200Test() throws ApiException {
answerOnAnyRequest(200, readResourceFile(PAYLOADS_PATH + "responses/200.json"));

Page<Float> res = api.getAggregatedMetrics("play", "count").execute();

/* sample response:
{
"context" : {
"metric" : "impression",
"aggregation" : "count",
"timeframe" : {
"from" : "2024-05-28T11:15:07+00:00",
"to" : "2024-05-29T11:15:07+00:00"
}
},
"data" : 346.5
}
*/
AnalyticsAggregatedMetricsResponse res = api.getAggregatedMetrics("play", "count").execute();

/*
* sample response: { "context" : { "metric" : "impression", "aggregation" : "count", "timeframe" : { "from"
* : "2024-05-28T11:15:07+00:00", "to" : "2024-05-29T11:15:07+00:00" } }, "data" : 346.5 }
*/
}

@Test
@DisplayName("400 response")
public void responseWithStatus400Test() throws ApiException {
answerOnAnyRequest(400, readResourceFile(PAYLOADS_PATH + "responses/400.json"));
answerOnAnyRequest(400, readResourceFile(PAYLOADS_PATH + "responses/400-0.json"));

assertThatThrownBy(() -> api.getAggregatedMetrics("play", "count").execute())
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(400))
.hasMessage("A query parameter is invalid.");

/* sample response:
{
"type" : "https://docs.api.video/reference/request-invalid-query-parameter",
"title" : "A query parameter is invalid.",
"status" : 400,
"detail" : "This field was not expected.",
"name" : "from:2024-05-20T09:15:05+02:00"
}
*/
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(400))
.hasMessage("An attribute is invalid.");

/*
* sample response: { "type" : "https://docs.api.video/reference/request-invalid-query-parameter", "title" :
* "A query parameter is invalid.", "status" : 400, "detail" : "This field was not expected.", "name" :
* "from:2024-05-20T09:15:05+02:00" }
*/
}

@Test
Expand All @@ -99,36 +87,30 @@ public void responseWithStatus404Test() throws ApiException {
answerOnAnyRequest(404, readResourceFile(PAYLOADS_PATH + "responses/404.json"));

assertThatThrownBy(() -> api.getAggregatedMetrics("play", "count").execute())
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(404))
.hasMessage("Unrecognized request URL.");

/* sample response:
{
"type" : "https://docs.api.video/reference/unrecognized-request-url",
"title" : "Unrecognized request URL.",
"status" : 404
}
*/
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(404))
.hasMessage("Unrecognized request URL.");

/*
* sample response: { "type" : "https://docs.api.video/reference/unrecognized-request-url", "title" :
* "Unrecognized request URL.", "status" : 404 }
*/
}

@Test
@DisplayName("429 response")
public void responseWithStatus429Test() throws ApiException {
answerOnAnyRequest(429, readResourceFile(PAYLOADS_PATH + "responses/429.json"));

assertThatThrownBy(() -> api.getAggregatedMetrics("play" ,"count").execute())
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(429))
.hasMessage("Too many requests.");

/* sample response:
{
"type" : "https://docs.api.video/reference/too-many-requests",
"title" : "Too many requests.",
"status" : 429
}
*/
assertThatThrownBy(() -> api.getAggregatedMetrics("play", "count").execute())
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(429))
.hasMessage("Too many requests.");

/*
* sample response: { "type" : "https://docs.api.video/reference/too-many-requests", "title" :
* "Too many requests.", "status" : 429 }
*/
}
}

Expand All @@ -143,7 +125,8 @@ public void requiredParametersTest() {
answerOnAnyRequest(201, "{}");

assertThatNoException().isThrownBy(() -> api.getMetricsBreakdown("play", "media-id").execute());
//String metric, String breakdown, OffsetDateTime from, OffsetDateTime to, String filterBy, Integer currentPage, Integer pageSize
// String metric, String breakdown, OffsetDateTime from, OffsetDateTime to, String filterBy, Integer
// currentPage, Integer pageSize
}

@Test
Expand All @@ -153,60 +136,35 @@ public void responseWithStatus200Test() throws ApiException {

Page<AnalyticsMetricsBreakdownResponseData> res = api.getMetricsBreakdown("play", "media-id").execute();

/* sample response:
{
"context" : {
"metric" : "play",
"breakdown" : "country",
"timeframe" : {
"from" : "2024-04-28T07:15:05+00:00",
"to" : "2024-05-29T11:25:37+00:00"
}
},
"data" : [ {
"metricValue" : 7,
"dimensionValue" : "FR"
} ],
"pagination" : {
"currentPage" : 1,
"currentPageItems" : 1,
"pageSize" : 25,
"pagesTotal" : 1,
"itemsTotal" : 1,
"links" : [ {
"rel" : "self",
"uri" : "/data/buckets/play/country?from=2024-04-28T09%3A15%3A05%2B02%3A00&amp;currentPage=1&amp;pageSize=25"
}, {
"rel" : "first",
"uri" : "/data/buckets/play/country?from=2024-04-28T09%3A15%3A05%2B02%3A00&amp;currentPage=1&amp;pageSize=25"
}, {
"rel" : "last",
"uri" : "/data/buckets/play/country?from=2024-04-28T09%3A15%3A05%2B02%3A00&amp;currentPage=1&amp;pageSize=25"
} ]
}
}
*/
/*
* sample response: { "context" : { "metric" : "play", "breakdown" : "country", "timeframe" : { "from" :
* "2024-04-28T07:15:05+00:00", "to" : "2024-05-29T11:25:37+00:00" } }, "data" : [ { "metricValue" : 7,
* "dimensionValue" : "FR" } ], "pagination" : { "currentPage" : 1, "currentPageItems" : 1, "pageSize" : 25,
* "pagesTotal" : 1, "itemsTotal" : 1, "links" : [ { "rel" : "self", "uri" :
* "/data/buckets/play/country?from=2024-04-28T09%3A15%3A05%2B02%3A00&amp;currentPage=1&amp;pageSize=25" },
* { "rel" : "first", "uri" :
* "/data/buckets/play/country?from=2024-04-28T09%3A15%3A05%2B02%3A00&amp;currentPage=1&amp;pageSize=25" },
* { "rel" : "last", "uri" :
* "/data/buckets/play/country?from=2024-04-28T09%3A15%3A05%2B02%3A00&amp;currentPage=1&amp;pageSize=25" } ]
* } }
*/
}

@Test
@DisplayName("400 response")
public void responseWithStatus400Test() throws ApiException {
answerOnAnyRequest(400, readResourceFile(PAYLOADS_PATH + "responses/400.json"));
answerOnAnyRequest(400, readResourceFile(PAYLOADS_PATH + "responses/400-0.json"));

assertThatThrownBy(() -> api.getMetricsBreakdown("play", "media-id").execute())
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(400))
.hasMessage("A query parameter is invalid.");

/* sample response:
{
"type" : "https://docs.api.video/reference/request-invalid-query-parameter",
"title" : "A query parameter is invalid.",
"status" : 400,
"detail" : "This field was not expected.",
"name" : "from:2024-05-20T09:15:05+02:00"
}
*/
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(400))
.hasMessage("An attribute is invalid.");

/*
* sample response: { "type" : "https://docs.api.video/reference/request-invalid-query-parameter", "title" :
* "A query parameter is invalid.", "status" : 400, "detail" : "This field was not expected.", "name" :
* "from:2024-05-20T09:15:05+02:00" }
*/
}

@Test
Expand All @@ -215,17 +173,14 @@ public void responseWithStatus404Test() throws ApiException {
answerOnAnyRequest(404, readResourceFile(PAYLOADS_PATH + "responses/404.json"));

assertThatThrownBy(() -> api.getMetricsBreakdown("play", "media-id").execute())
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(404))
.hasMessage("Unrecognized request URL.");

/* sample response:
{
"type" : "https://docs.api.video/reference/unrecognized-request-url",
"title" : "Unrecognized request URL.",
"status" : 404
}
*/
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(404))
.hasMessage("Unrecognized request URL.");

/*
* sample response: { "type" : "https://docs.api.video/reference/unrecognized-request-url", "title" :
* "Unrecognized request URL.", "status" : 404 }
*/
}

@Test
Expand All @@ -234,17 +189,14 @@ public void responseWithStatus429Test() throws ApiException {
answerOnAnyRequest(429, readResourceFile(PAYLOADS_PATH + "responses/429.json"));

assertThatThrownBy(() -> api.getMetricsBreakdown("play", "media-id").execute())
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(429))
.hasMessage("Too many requests.");

/* sample response:
{
"type" : "https://docs.api.video/reference/too-many-requests",
"title" : "Too many requests.",
"status" : 429
}
*/
.isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(429))
.hasMessage("Too many requests.");

/*
* sample response: { "type" : "https://docs.api.video/reference/too-many-requests", "title" :
* "Too many requests.", "status" : 429 }
*/
}
}

Expand Down Expand Up @@ -285,11 +237,11 @@ public void responseWithStatus200Test() throws ApiException {
@Test
@DisplayName("400 response")
public void responseWithStatus400Test() throws ApiException {
answerOnAnyRequest(400, readResourceFile(PAYLOADS_PATH + "responses/400.json"));
answerOnAnyRequest(400, readResourceFile(PAYLOADS_PATH + "responses/400-0.json"));

assertThatThrownBy(() -> api.getMetricsOverTime("play").execute()).isInstanceOf(ApiException.class)
.satisfies(e -> assertThat(((ApiException) e).getCode()).isEqualTo(400))
.hasMessage("A query parameter is invalid.");
.hasMessage("An attribute is invalid.");

/*
* sample response: { "type" : "https://docs.api.video/reference/request-invalid-query-parameter", "title" :
Expand Down

0 comments on commit 2542fb6

Please sign in to comment.