-
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.
feat: HTTP and HTTPS in same mock (refs #62)
- Loading branch information
1 parent
fdb382c
commit 7ce0021
Showing
4 changed files
with
204 additions
and
41 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
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
77 changes: 77 additions & 0 deletions
77
wiremock-spring-boot-example/src/test/java/app/HttpsAndHttpTest.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,77 @@ | ||
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(httpsPort = 0)}) | ||
class HttpsAndHttpTest { | ||
|
||
@InjectWireMock private WireMockServer wiremock; | ||
|
||
@Value("${wiremock.server.httpsPort}") | ||
private int wiremockHttpsPort; | ||
|
||
@Value("${wiremock.server.port}") | ||
private int wiremockHttpPort; | ||
|
||
@Value("${wiremock.server.httpsBaseUrl}") | ||
private String wiremockHttpsUrl; | ||
|
||
@Value("${wiremock.server.baseUrl}") | ||
private String wiremockHttpUrl; | ||
|
||
@BeforeEach | ||
public void before() { | ||
RestAssured.useRelaxedHTTPSValidation(); | ||
} | ||
|
||
@Test | ||
void testProperties() { | ||
assertThat(this.wiremockHttpsPort).isNotNull(); | ||
assertThat(this.wiremockHttpsUrl) | ||
.startsWith("https://") | ||
.contains(String.valueOf(this.wiremockHttpsPort)); | ||
|
||
assertThat(this.wiremockHttpPort).isNotNull(); | ||
assertThat(this.wiremockHttpUrl) | ||
.startsWith("http://") | ||
.contains(String.valueOf(this.wiremockHttpPort)); | ||
} | ||
|
||
@Test | ||
void testInjectedClient() { | ||
this.wiremock.stubFor(get("/injected-client").willReturn(aResponse().withStatus(202))); | ||
|
||
RestAssured.when().get(this.wiremockHttpsUrl + "/injected-client").then().statusCode(202); | ||
assertThat(this.wiremock.findAll(anyRequestedFor(anyUrl()))).hasSize(1); | ||
|
||
RestAssured.when().get(this.wiremockHttpUrl + "/injected-client").then().statusCode(202); | ||
assertThat(this.wiremock.findAll(anyRequestedFor(anyUrl()))).hasSize(2); | ||
} | ||
|
||
@Test | ||
void testDefaultClient() { | ||
WireMock.stubFor(WireMock.get("/with-default-client").willReturn(aResponse().withStatus(202))); | ||
|
||
RestAssured.when().get(this.wiremockHttpsUrl + "/with-default-client").then().statusCode(202); | ||
assertThat(WireMock.findAll(anyRequestedFor(anyUrl()))).hasSize(1); | ||
|
||
RestAssured.when().get(this.wiremockHttpUrl + "/with-default-client").then().statusCode(202); | ||
assertThat(WireMock.findAll(anyRequestedFor(anyUrl()))).hasSize(2); | ||
} | ||
} |
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