-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: global response templating configurable
- Loading branch information
1 parent
1b42d76
commit 21b06a8
Showing
6 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package usecases; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.restassured.RestAssured; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.wiremock.spring.ConfigureWireMock; | ||
import org.wiremock.spring.EnableWireMock; | ||
|
||
@SpringBootTest | ||
@EnableWireMock({ | ||
@ConfigureWireMock(filesUnderClasspath = "response-templating", globalTemplating = true) | ||
}) | ||
class ResponseTemplatingGlobalTest { | ||
|
||
@Value("${wiremock.server.baseUrl}") | ||
private String wireMockServerUrl; | ||
|
||
@Test | ||
void testLocal() { | ||
RestAssured.baseURI = this.wireMockServerUrl; | ||
final String actual = | ||
RestAssured.when().get("/local-templating").then().extract().asPrettyString(); | ||
assertThat(actual) | ||
.isEqualToIgnoringWhitespace( | ||
""" | ||
{ | ||
"name": "Resolved: local-templating" | ||
} | ||
"""); | ||
} | ||
|
||
@Test | ||
void testGlobal() { | ||
RestAssured.baseURI = this.wireMockServerUrl; | ||
final String actual = | ||
RestAssured.when().get("/global-templating").then().extract().asPrettyString(); | ||
assertThat(actual) | ||
.isEqualToIgnoringWhitespace( | ||
""" | ||
{ | ||
"name": "Resolved: global-templating" | ||
} | ||
"""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package usecases; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.restassured.RestAssured; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.wiremock.spring.ConfigureWireMock; | ||
import org.wiremock.spring.EnableWireMock; | ||
|
||
@SpringBootTest | ||
@EnableWireMock({ | ||
@ConfigureWireMock(filesUnderClasspath = "response-templating", globalTemplating = false) | ||
}) | ||
class ResponseTemplatingLocalTest { | ||
|
||
@Value("${wiremock.server.baseUrl}") | ||
private String wireMockServerUrl; | ||
|
||
@Test | ||
void testLocal() { | ||
RestAssured.baseURI = this.wireMockServerUrl; | ||
final String actual = | ||
RestAssured.when().get("/local-templating").then().extract().asPrettyString(); | ||
assertThat(actual) | ||
.isEqualToIgnoringWhitespace(""" | ||
{ | ||
"name": "Resolved: local-templating" | ||
} | ||
"""); | ||
} | ||
|
||
@Test | ||
void testGlobal() { | ||
RestAssured.baseURI = this.wireMockServerUrl; | ||
final String actual = | ||
RestAssured.when().get("/global-templating").then().extract().asPrettyString(); | ||
assertThat(actual) | ||
.isEqualToIgnoringWhitespace(""" | ||
{ | ||
"name": "Resolved: {{request.path.[0]}}" | ||
} | ||
"""); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/resources/response-templating/mappings/global-templating.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/global-templating" | ||
}, | ||
"response": { | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"jsonBody": { | ||
"name": "Resolved: {{request.path.[0]}}" | ||
}, | ||
"status": 200 | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/resources/response-templating/mappings/local-templating-enabled.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/local-templating" | ||
}, | ||
"response": { | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"jsonBody": { | ||
"name": "Resolved: {{request.path.[0]}}" | ||
}, | ||
"transformers": [ | ||
"response-template" | ||
], | ||
"status": 200 | ||
} | ||
} |