Improve test coverage of default stubs locations

This commit is contained in:
Dave Syer
2016-11-11 12:55:41 +00:00
parent b063612d89
commit 4829e687d8
10 changed files with 37 additions and 9 deletions

View File

@@ -25,7 +25,7 @@ public class AutoConfigureWireMockApplicationTests {
@Test
public void contextLoads() throws Exception {
stubFor(get(urlEqualTo("/resource"))
stubFor(get(urlEqualTo("/test"))
.willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("Hello World!")));
assertThat(this.service.go()).isEqualTo("Hello World!");
}

View File

@@ -0,0 +1,28 @@
package org.springframework.cloud.contract.wiremock;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes=WiremockTestsApplication.class, properties="app.baseUrl=http://localhost:${wiremock.server.port}", webEnvironment=WebEnvironment.NONE)
@DirtiesContext
@AutoConfigureWireMock(port=0)
// Default stubs work at classpath:/mappings
public class AutoConfigureWireMockAutoStubsApplicationTests {
@Autowired
private Service service;
@Test
public void contextLoads() throws Exception {
assertThat(this.service.go()).isEqualTo("Hello World");
}
}

View File

@@ -25,7 +25,7 @@ public class AutoConfigureWireMockHttpsPortApplicationTests {
@Test
public void contextLoads() throws Exception {
stubFor(get(urlEqualTo("/resource")).willReturn(aResponse()
stubFor(get(urlEqualTo("/test")).willReturn(aResponse()
.withHeader("Content-Type", "text/plain").withBody("Hello World!")));
assertThat(this.service.go()).isEqualTo("Hello World!");
}

View File

@@ -25,7 +25,7 @@ public class AutoConfigureWireMockPortApplicationTests {
@Test
public void contextLoads() throws Exception {
stubFor(get(urlEqualTo("/resource")).willReturn(aResponse()
stubFor(get(urlEqualTo("/test")).willReturn(aResponse()
.withHeader("Content-Type", "text/plain").withBody("Hello World!")));
assertThat(this.service.go()).isEqualTo("Hello World!");
}

View File

@@ -25,7 +25,7 @@ public class AutoConfigureWireMockRandomPortApplicationTests {
@Test
public void contextLoads() throws Exception {
stubFor(get(urlEqualTo("/resource"))
stubFor(get(urlEqualTo("/test"))
.willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("Hello World!")));
assertThat(this.service.go()).isEqualTo("Hello World!");
}

View File

@@ -25,7 +25,7 @@ public class AutoConfigureWireMockRandomPortHttpsApplicationTests {
@Test
public void contextLoads() throws Exception {
stubFor(get(urlEqualTo("/resource"))
stubFor(get(urlEqualTo("/test"))
.willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("Hello World!")));
assertThat(this.service.go()).isEqualTo("Hello World!");
}

View File

@@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes=WiremockTestsApplication.class, properties="app.baseUrl=http://localhost:${wiremock.server.port}", webEnvironment=WebEnvironment.NONE)
@DirtiesContext
@AutoConfigureWireMock(port=0, stubs="file:src/test/resources/mappings")
@AutoConfigureWireMock(port=0, stubs="file:src/test/resources/io.stubs/mappings")
public class AutoConfigureWireMockStubsApplicationTests {
@Autowired

View File

@@ -30,7 +30,7 @@ public class WiremockHttpsServerApplicationTests {
@Test
public void contextLoads() throws Exception {
stubFor(get(urlEqualTo("/resource"))
stubFor(get(urlEqualTo("/test"))
.willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("Hello World!")));
assertThat(this.service.go()).isEqualTo("Hello World!");
}

View File

@@ -30,7 +30,7 @@ public class WiremockServerApplicationTests {
@Test
public void contextLoads() throws Exception {
stubFor(get(urlEqualTo("/resource"))
stubFor(get(urlEqualTo("/test"))
.willReturn(aResponse().withHeader("Content-Type", "text/plain").withBody("Hello World!")));
assertThat(this.service.go()).isEqualTo("Hello World!");
}

View File

@@ -55,6 +55,6 @@ class Service {
}
public String go() {
return this.restTemplate.getForEntity(this.base + "/resource", String.class).getBody();
return this.restTemplate.getForEntity(this.base + "/test", String.class).getBody();
}
}