mirror of
https://gitee.com/dcren/initializr.git
synced 2025-04-05 17:38:06 +08:00
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:
parent
b18770871c
commit
aa828b388f
@ -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>
|
||||
|
@ -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}
|
||||
|
@ -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:
|
||||
@ -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 {
|
||||
|
||||
@Value("${wiremock.server.port}")
|
||||
private int port;
|
||||
@Autowired
|
||||
private StubFinder stubFinder;
|
||||
|
||||
...
|
||||
|
||||
}
|
||||
...
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
Here is an example of a test that retrieves the metadata of the service. The assertions
|
||||
|
Loading…
Reference in New Issue
Block a user