Skip to content

Commit 0a0684a

Browse files
committed
Add more test for path params
1 parent 1d84863 commit 0a0684a

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

mock/core/src/test/java/io/quarkiverse/openapi/generator/wiremock/mapper/WiremockPathParamTest.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void shouldMapOneWiremockDefinition() throws URISyntaxException, IOException {
5050

5151
@Test
5252
@DisplayName("Should convert with a two OpenAPI#paths each one with one path param")
53-
void shouldMapTwoWiremockDefinitions() throws URISyntaxException, IOException {
53+
void shouldMapTwoWiremockDefinitions() {
5454

5555
String content = Testing.readContentFromFile("wiremock/path_param_two_params_but_different_path.yml");
5656
if (content == null) {
@@ -91,7 +91,7 @@ void shouldMapTwoWiremockDefinitions() throws URISyntaxException, IOException {
9191

9292
@Test
9393
@DisplayName("Should convert with a combination of path param")
94-
void shouldConvertWithACombinationOfPathParam() throws URISyntaxException, IOException {
94+
void shouldConvertWithACombinationOfPathParam() {
9595

9696
String content = Testing.readContentFromFile("wiremock/path_param_two_path_params_combination.yml");
9797
if (content == null) {
@@ -131,4 +131,36 @@ void shouldConvertWithACombinationOfPathParam() throws URISyntaxException, IOExc
131131
});
132132
}
133133

134+
@Test
135+
@DisplayName("Should convert with a combination but only one with example")
136+
void shouldConvertPathParamCombinationOnlyOneWithExample() {
137+
138+
String content = Testing.readContentFromFile("wiremock/path_param_two_path_params_only_one_with_example.yml");
139+
if (content == null) {
140+
Assertions.fail("Was not possible to read the file!");
141+
}
142+
143+
OpenAPIQuarkiverseMockImporter importer = new OpenAPIQuarkiverseMockImporter();
144+
145+
QuarkiverseMock mock = importer.parse(content);
146+
147+
WiremockMapper wiremockMapper = new WiremockMapper();
148+
149+
List<WiremockDefinition> definitions = wiremockMapper.map(mock);
150+
151+
SoftAssertions.assertSoftly(softly -> {
152+
softly.assertThat(definitions).hasSize(1);
153+
154+
softly.assertThat(definitions).anySatisfy(wiremockDefinition -> {
155+
// request
156+
softly.assertThat(wiremockDefinition.request().url()).isEqualTo("/users/1/books/{bookId}");
157+
softly.assertThat(wiremockDefinition.request().method()).isEqualTo("GET");
158+
// response
159+
softly.assertThat(wiremockDefinition.response().status()).isEqualTo(200);
160+
softly.assertThat(wiremockDefinition.response().body())
161+
.isEqualTo("{\"name\": \"Book for John\", \"chapters\": 8}");
162+
});
163+
});
164+
}
165+
134166
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
openapi: 3.0.3
2+
servers:
3+
- url: http://localhost:8888
4+
info:
5+
version: 999-SNAPSHOT
6+
title: Method GET one path param
7+
paths:
8+
"/users/{userId}/books/{bookId}":
9+
get:
10+
parameters:
11+
- name: userId
12+
in: path
13+
examples:
14+
john:
15+
value: 1
16+
- name: bookId
17+
in: path
18+
responses:
19+
200:
20+
content:
21+
"application/json":
22+
examples:
23+
john:
24+
value: '{"name": "Book for John", "chapters": 8}'
25+
description: Ok

0 commit comments

Comments
 (0)