Fix spring cloud contract example

When `workOffline` is `false` a Maven repository must be provided to let
it download the stubs.

Closes gh-426
This commit is contained in:
Stephane Nicoll 2017-05-08 14:35:20 +02:00
parent b18770871c
commit aa828b388f
3 changed files with 36 additions and 27 deletions

View File

@ -276,6 +276,14 @@
<target> <target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" /> <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" /> <taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" />
<var name="version-type" value="${project.version}" />
<propertyregex property="version-type" override="true" input="${version-type}" regexp=".*\.(.*)" replace="\1" />
<propertyregex property="version-type" override="true" input="${version-type}" regexp="(M)\d+" replace="MILESTONE" />
<propertyregex property="version-type" override="true" input="${version-type}" regexp="(RC)\d+" replace="MILESTONE" />
<propertyregex property="version-type" override="true" input="${version-type}" regexp="BUILD-(.*)" replace="SNAPSHOT" />
<stringutil string="${version-type}" property="initializr-repo">
<lowercase />
</stringutil>
<var name="github-tag" value="v${project.version}" /> <var name="github-tag" value="v${project.version}" />
<propertyregex property="github-tag" override="true" input="${github-tag}" regexp=".*SNAPSHOT" replace="master" /> <propertyregex property="github-tag" override="true" input="${github-tag}" regexp=".*SNAPSHOT" replace="master" />
</target> </target>

View File

@ -8,6 +8,7 @@ Stéphane Nicoll; Dave Syer
:icons: font :icons: font
:hide-uri-scheme: :hide-uri-scheme:
:test-examples: ../../test/java/io/spring/initializr :test-examples: ../../test/java/io/spring/initializr
:initializr-repo: snapshot
:github-tag: master :github-tag: master
:github-repo: spring-io/initializr :github-repo: spring-io/initializr
:github-raw: https://raw.github.com/{github-repo}/{github-tag} :github-raw: https://raw.github.com/{github-repo}/{github-tag}

View File

@ -33,20 +33,20 @@ and then pull the stubs from the classpath. In a Spring Boot application, using
Spring Cloud Contract, you can start a WireMock server and register all the stubs Spring Cloud Contract, you can start a WireMock server and register all the stubs
with it like this: with it like this:
[source,java,subs="attributes"] [source,java,indent=0,subs="attributes"]
---- ----
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.NONE) @SpringBootTest
@AutoConfigureWireMock(port = 0, @AutoConfigureWireMock(port = 0,
stubs="classpath:META-INF/io.spring.initializr/initializr-web/{spring-initializr-version}") stubs="classpath:META-INF/io.spring.initializr/initializr-web/{spring-initializr-version}")
public class ClientApplicationTests { public class ClientApplicationTests {
@Value("${wiremock.server.port}") @Value("${wiremock.server.port}")
private int port; private int port;
... ...
} }
---- ----
The Wiremock features come with Spring Cloud Contract Wiremock: The Wiremock features come with Spring Cloud Contract Wiremock:
@ -73,31 +73,31 @@ stubs declared as a dependency):
[source,xml,indent=0,subs="attributes,specialchars"] [source,xml,indent=0,subs="attributes,specialchars"]
---- ----
<dependencies> <dependency>
... <groupId>org.springframework.cloud</groupId>
<dependency> <artifactId>spring-cloud-starter-contract-stubrunner</artifactId>
<groupId>org.springframework.cloud</groupId> <scope>test</scope>
<artifactId>spring-cloud-starter-contract-stubrunner</artifactId> </dependency>
<scope>test</scope>
</dependency>
</dependencies>
---- ----
The test should use `@AutoConfigureStubRunner` instead: The test should use `@AutoConfigureStubRunner` instead:
[source,java,subs="attributes,specialchars"] [source,java,indent=0,,subs="attributes,specialchars"]
---- ----
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.NONE) @SpringBootTest(webEnvironment = WebEnvironment.NONE)
@AutoConfigureStubRunner(ids = "io.spring.initializr:initializr-web:{spring-initializr-version}") @AutoConfigureStubRunner(
public class ClientApplicationTests { ids = "io.spring.initializr:initializr-web:{spring-initializr-version}",
repositoryRoot = "https://repo.spring.io/{initializr-repo}")
public class ClientApplicationTests {
@Value("${wiremock.server.port}") @Autowired
private int port; private StubFinder stubFinder;
...
} ...
}
---- ----
Here is an example of a test that retrieves the metadata of the service. The assertions Here is an example of a test that retrieves the metadata of the service. The assertions