Skip to content

Commit

Permalink
Fix spring cloud contract example
Browse files Browse the repository at this point in the history
When `workOffline` is `false` a Maven repository must be provided to let
it download the stubs.

Closes spring-iogh-426
  • Loading branch information
snicoll committed May 8, 2017
1 parent b187708 commit aa828b3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
8 changes: 8 additions & 0 deletions initializr-docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@
<target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<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}" />
<propertyregex property="github-tag" override="true" input="${github-tag}" regexp=".*SNAPSHOT" replace="master" />
</target>
Expand Down
1 change: 1 addition & 0 deletions initializr-docs/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Stéphane Nicoll; Dave Syer
:icons: font
:hide-uri-scheme:
:test-examples: ../../test/java/io/spring/initializr
:initializr-repo: snapshot
:github-tag: master
:github-repo: spring-io/initializr
:github-raw: https://raw.github.com/{github-repo}/{github-tag}
Expand Down
54 changes: 27 additions & 27 deletions initializr-docs/src/main/asciidoc/using-the-stubs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
with it like this:

[source,java,subs="attributes"]
[source,java,indent=0,subs="attributes"]
----
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
@AutoConfigureWireMock(port = 0,
stubs="classpath:META-INF/io.spring.initializr/initializr-web/{spring-initializr-version}")
public class ClientApplicationTests {
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureWireMock(port = 0,
stubs="classpath:META-INF/io.spring.initializr/initializr-web/{spring-initializr-version}")
public class ClientApplicationTests {
@Value("${wiremock.server.port}")
private int port;
@Value("${wiremock.server.port}")
private int port;
...
...
}
}
----

The Wiremock features come with Spring Cloud Contract Wiremock:
Expand All @@ -73,31 +73,31 @@ stubs declared as a dependency):

[source,xml,indent=0,subs="attributes,specialchars"]
----
<dependencies>
...
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-stubrunner</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-stubrunner</artifactId>
<scope>test</scope>
</dependency>
----

The test should use `@AutoConfigureStubRunner` instead:

[source,java,subs="attributes,specialchars"]
[source,java,indent=0,,subs="attributes,specialchars"]
----
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
@AutoConfigureStubRunner(ids = "io.spring.initializr:initializr-web:{spring-initializr-version}")
public class ClientApplicationTests {
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
@AutoConfigureStubRunner(
ids = "io.spring.initializr:initializr-web:{spring-initializr-version}",
repositoryRoot = "https://repo.spring.io/{initializr-repo}")
public class ClientApplicationTests {
@Autowired
private StubFinder stubFinder;
@Value("${wiremock.server.port}")
private int port;
...
...
}
}
----

Here is an example of a test that retrieves the metadata of the service. The assertions
Expand Down

0 comments on commit aa828b3

Please sign in to comment.