-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72bd586
commit f2c35d0
Showing
4 changed files
with
115 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
5870e1ef80feb27342e0e8b1fd5369cb21a38e57 | ||
|
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 |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#Wed Sep 25 18:22:00 CEST 2024 | ||
# | ||
#Sun Oct 06 08:21:20 CEST 2024 | ||
description=WireMock integration for Spring Boot. | ||
version=3.0.0-SNAPSHOT | ||
group=org.wiremock.spring | ||
sourceCompatibility=17 | ||
targetCompatibility=17 | ||
website=https://github.com/wiremock/wiremock-spring-boot | ||
vcsUrl=https://github.com/wiremock/wiremock-spring-boot | ||
licenseName=MIT | ||
nexusUsernameEnvOrProp=OSSRH_USERNAME | ||
nexusPasswordEnvOrProp=OSSRH_TOKEN | ||
nexusUsernameEnvOrProp=OSSRH_USERNAME | ||
signingKeyEnvOrProp=OSSRH_GPG_SECRET_KEY | ||
signingPasswordEnvOrProp=OSSRH_GPG_SECRET_KEY_PASSWORD | ||
tags=wiremock,springboot | ||
sourceCompatibility=17 | ||
tags=wiremock,springboot | ||
targetCompatibility=17 | ||
vcsUrl=https\://github.com/wiremock/wiremock-spring-boot | ||
version=3.0.0 | ||
website=https\://github.com/wiremock/wiremock-spring-boot |
103 changes: 103 additions & 0 deletions
103
wiremock-spring-boot-example/src/test/java/app/ResetWireMockBetweenTest.java
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,103 @@ | ||
package app; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.anyRequestedFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import io.restassured.RestAssured; | ||
import org.junit.jupiter.api.BeforeEach; | ||
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; | ||
import org.wiremock.spring.InjectWireMock; | ||
|
||
@SpringBootTest | ||
@EnableWireMock({ | ||
@ConfigureWireMock( | ||
name = "wm1", | ||
portProperties = "wm1.server.port", | ||
baseUrlProperties = "wm1.server.url"), | ||
@ConfigureWireMock( | ||
name = "wm2", | ||
portProperties = "wm2.server.port", | ||
baseUrlProperties = "wm2.server.url") | ||
}) | ||
class ResetWireMockBetweenTest { | ||
|
||
@InjectWireMock("wm1") | ||
private WireMockServer wm1; | ||
|
||
@Value("${wm1.server.port}") | ||
private int wm1Port; | ||
|
||
@Value("${wm1.server.url}") | ||
private String wm1Url; | ||
|
||
@InjectWireMock("wm2") | ||
private WireMockServer wm2; | ||
|
||
@Value("${wm2.server.port}") | ||
private int wm2Port; | ||
|
||
@Value("${wm2.server.url}") | ||
private String wm2Url; | ||
|
||
private WireMock wm1Client; | ||
|
||
private WireMock wm2Client; | ||
|
||
@BeforeEach | ||
public void before() { | ||
this.wm1Client = WireMock.create().port(this.wm1Port).build(); | ||
this.wm1Client.register( | ||
get("/wm1_configured_in_before").willReturn(aResponse().withStatus(202))); | ||
|
||
this.wm2Client = WireMock.create().port(this.wm2Port).build(); | ||
this.wm2Client.register( | ||
get("/wm2_configured_in_before").willReturn(aResponse().withStatus(202))); | ||
} | ||
|
||
@Test | ||
void test1() { | ||
assertThat(this.wm1Client.find(anyRequestedFor(anyUrl()))).hasSize(0); | ||
assertThat(this.wm1Client.allStubMappings().getMappings()).hasSize(1); | ||
|
||
assertThat(this.wm2Client.find(anyRequestedFor(anyUrl()))).hasSize(0); | ||
assertThat(this.wm2Client.allStubMappings().getMappings()).hasSize(1); | ||
|
||
this.wm1Client.register(get("/wm1_configured_in_test").willReturn(aResponse().withStatus(202))); | ||
|
||
RestAssured.when().get(this.wm1Url + "/wm1_configured_in_test").then().statusCode(202); | ||
|
||
assertThat(this.wm1Client.find(anyRequestedFor(anyUrl()))).hasSize(1); | ||
assertThat(this.wm1Client.allStubMappings().getMappings()).hasSize(2); | ||
|
||
assertThat(this.wm2Client.find(anyRequestedFor(anyUrl()))).hasSize(0); | ||
assertThat(this.wm2Client.allStubMappings().getMappings()).hasSize(1); | ||
} | ||
|
||
@Test | ||
void test2() { | ||
assertThat(this.wm1Client.find(anyRequestedFor(anyUrl()))).hasSize(0); | ||
assertThat(this.wm1Client.allStubMappings().getMappings()).hasSize(1); | ||
|
||
assertThat(this.wm2Client.find(anyRequestedFor(anyUrl()))).hasSize(0); | ||
assertThat(this.wm2Client.allStubMappings().getMappings()).hasSize(1); | ||
|
||
this.wm2Client.register(get("/wm2_configured_in_test").willReturn(aResponse().withStatus(202))); | ||
|
||
RestAssured.when().get(this.wm2Url + "/wm2_configured_in_test").then().statusCode(202); | ||
|
||
assertThat(this.wm1Client.find(anyRequestedFor(anyUrl()))).hasSize(0); | ||
assertThat(this.wm1Client.allStubMappings().getMappings()).hasSize(1); | ||
|
||
assertThat(this.wm2Client.find(anyRequestedFor(anyUrl()))).hasSize(1); | ||
assertThat(this.wm2Client.allStubMappings().getMappings()).hasSize(2); | ||
} | ||
} |