From a60ced9ce3b2338e5381af9ed547c7f20e043f2c Mon Sep 17 00:00:00 2001
From: buildmaster
@ContextConfiguration(classes = Config, loader = SpringBootContextLoader) @SpringBootTest(properties = [" stubrunner.cloud.enabled=false", - 'foo=${stubrunner.runningstubs.fraudDetectionServer.port}']) + 'foo=${stubrunner.runningstubs.fraudDetectionServer.port}', + 'fooWithGroup=${stubrunner.runningstubs.org.springframework.cloud.contract.verifier.stubs.fraudDetectionServer.port}']) @AutoConfigureStubRunner(mappingsOutputFolder = "target/outputmappings/") @DirtiesContext @ActiveProfiles("test") @@ -386,6 +387,8 @@ its methods as presented below:@Autowired StubFinder stubFinder @Autowired Environment environment + @StubRunnerPort("fraudDetectionServer") int fraudDetectionServerPort + @StubRunnerPort("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer") int fraudDetectionServerPortWithGroupId @Value('${foo}') Integer foo @BeforeClass @@ -430,6 +433,9 @@ its methods as presented below:"stubrunner.runningstubs.fraudDetectionServer.port") != null stubFinder.findAllRunningStubs().getPort("fraudDetectionServer") == (environment.getProperty("stubrunner.runningstubs.fraudDetectionServer.port") as Integer) + and: + environment.getProperty("stubrunner.runningstubs.fraudDetectionServer.port") != null + stubFinder.findAllRunningStubs().getPort("fraudDetectionServer") == (environment.getProperty("stubrunner.runningstubs.org.springframework.cloud.contract.verifier.stubs.fraudDetectionServer.port") as Integer) } def 'should be able to interpolate a running stub in the passed test property'() { @@ -438,9 +444,20 @@ its methods as presented below:0 environment.getProperty("foo", Integer) == fraudPort + environment.getProperty("fooWithGroup", Integer) == fraudPort foo == fraudPort } + @Issue("#573") + def 'should be able to retrieve the port of a running stub via an annotation'() { + given: + int fraudPort = stubFinder.findAllRunningStubs().getPort("fraudDetectionServer") + expect: + fraudPort > 0 + fraudDetectionServerPort == fraudPort + fraudDetectionServerPortWithGroupId == fraudPort + } + def 'should dump all mappings to a file'() { when: def url = stubFinder.findStubUrl("fraudDetectionServer") @@ -465,7 +482,12 @@ Below you can find an example of achieving the same result by setting values on stubsMode = StubRunnerProperties.StubsMode.REMOTE, repositoryRoot = "classpath:m2repo/repository/")Stub Runner Spring registers environment variables in the following manner for every registered WireMock server. Example for Stub Runner ids -
com.example:foo,com.example:bar.
stubrunner.runningstubs.foo.portstubrunner.runningstubs.bar.portWhich you can reference in your code.
Stub Runner can integrate with Spring Cloud.
For real life examples you can check the
The most important feature of
Stub Runner Spring Cloudis the fact that it’s stubbing
DiscoveryClientRibbonServerListthat means that regardless of the fact whether you’re using Zookeeper, Consul, Eureka or anything else, you don’t need that in your tests. +
com.example:foo,com.example:bar.
stubrunner.runningstubs.foo.portstubrunner.runningstubs.com.example.foo.portstubrunner.runningstubs.bar.portstubrunner.runningstubs.com.example.bar.portWhich you can reference in your code.
You can also use the
@StubRunnerPortannotation to inject the port of a running stub. +Value of the annotation can be thegroupid:artifactidor just theartifactid. Example for Stub Runner ids +com.example:foo,com.example:bar.@StubRunnerPort("foo") +int fooPort; +@StubRunnerPort("com.example:bar") +int barPort;Stub Runner can integrate with Spring Cloud.
For real life examples you can check the
The most important feature of
Stub Runner Spring Cloudis the fact that it’s stubbing
DiscoveryClientRibbonServerListthat means that regardless of the fact whether you’re using Zookeeper, Consul, Eureka or anything else, you don’t need that in your tests. We’re starting WireMock instances of your dependencies and we’re telling your application whenever you’re using
Feign, load balancedRestTemplateorDiscoveryClientdirectly, to call those stubbed servers instead of calling the real Service Discovery tool.For example this test will pass
def 'should make service discovery work'() { expect: 'WireMocks are running' diff --git a/multi/multi__spring_cloud_contract_wiremock.html b/multi/multi__spring_cloud_contract_wiremock.html index 6e02391150..c4d6e0e593 100644 --- a/multi/multi__spring_cloud_contract_wiremock.html +++ b/multi/multi__spring_cloud_contract_wiremock.html @@ -112,7 +112,8 @@ annotation or the stub runner. If you use the JUnit@Rule< classpath and it is selected by theRestTemplateBuilderand configured to ignore SSL errors. If you use the defaultjava.netclient, you do not need the annotation (but it won’t do any harm). There is no support currently for other clients, but it may be added -in future releases.Spring Cloud Contract provides a convenience class that can load JSON WireMock stubs into +in future releases.
To disable the custom
RestTemplateBuilder, set thewiremock.rest-template-ssl-enabled+property tofalse.Spring Cloud Contract provides a convenience class that can load JSON WireMock stubs into a Spring
MockRestServiceServer. The following code shows an example:@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class WiremockForDocsMockServerApplicationTests { diff --git a/single/spring-cloud-contract.html b/single/spring-cloud-contract.html index d665d84f45..61d4a50b16 100644 --- a/single/spring-cloud-contract.html +++ b/single/spring-cloud-contract.html @@ -2430,7 +2430,8 @@ then(rule.findStubUrl(StubFinder interface and use its methods as presented below:@ContextConfiguration(classes = Config, loader = SpringBootContextLoader) @SpringBootTest(properties = [" stubrunner.cloud.enabled=false", - 'foo=${stubrunner.runningstubs.fraudDetectionServer.port}']) + 'foo=${stubrunner.runningstubs.fraudDetectionServer.port}', + 'fooWithGroup=${stubrunner.runningstubs.org.springframework.cloud.contract.verifier.stubs.fraudDetectionServer.port}'])@AutoConfigureStubRunner(mappingsOutputFolder = "target/outputmappings/") @DirtiesContext @ActiveProfiles("test") @@ -2438,6 +2439,8 @@ its methods as presented below:@Autowired StubFinder stubFinder @Autowired Environment environment + @StubRunnerPort("fraudDetectionServer") int fraudDetectionServerPort + @StubRunnerPort("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer") int fraudDetectionServerPortWithGroupId @Value('${foo}') Integer foo @BeforeClass @@ -2482,6 +2485,9 @@ its methods as presented below:"stubrunner.runningstubs.fraudDetectionServer.port") != null stubFinder.findAllRunningStubs().getPort("fraudDetectionServer") == (environment.getProperty("stubrunner.runningstubs.fraudDetectionServer.port") as Integer) + and: + environment.getProperty("stubrunner.runningstubs.fraudDetectionServer.port") != null + stubFinder.findAllRunningStubs().getPort("fraudDetectionServer") == (environment.getProperty("stubrunner.runningstubs.org.springframework.cloud.contract.verifier.stubs.fraudDetectionServer.port") as Integer) } def 'should be able to interpolate a running stub in the passed test property'() { @@ -2490,9 +2496,20 @@ its methods as presented below:0 environment.getProperty("foo", Integer) == fraudPort + environment.getProperty("fooWithGroup", Integer) == fraudPort foo == fraudPort } + @Issue("#573") + def 'should be able to retrieve the port of a running stub via an annotation'() { + given: + int fraudPort = stubFinder.findAllRunningStubs().getPort("fraudDetectionServer") + expect: + fraudPort > 0 + fraudDetectionServerPort == fraudPort + fraudDetectionServerPortWithGroupId == fraudPort + } + def 'should dump all mappings to a file'() { when: def url = stubFinder.findStubUrl("fraudDetectionServer") @@ -2517,7 +2534,12 @@ Below you can find an example of achieving the same result by setting values on stubsMode = StubRunnerProperties.StubsMode.REMOTE, repositoryRoot = "classpath:m2repo/repository/")Stub Runner Spring registers environment variables in the following manner for every registered WireMock server. Example for Stub Runner ids -
com.example:foo,com.example:bar.
stubrunner.runningstubs.foo.portstubrunner.runningstubs.bar.portWhich you can reference in your code.
Stub Runner can integrate with Spring Cloud.
For real life examples you can check the
The most important feature of
Stub Runner Spring Cloudis the fact that it’s stubbing
DiscoveryClientRibbonServerListthat means that regardless of the fact whether you’re using Zookeeper, Consul, Eureka or anything else, you don’t need that in your tests. +
com.example:foo,com.example:bar.
stubrunner.runningstubs.foo.portstubrunner.runningstubs.com.example.foo.portstubrunner.runningstubs.bar.portstubrunner.runningstubs.com.example.bar.portWhich you can reference in your code.
You can also use the
@StubRunnerPortannotation to inject the port of a running stub. +Value of the annotation can be thegroupid:artifactidor just theartifactid. Example for Stub Runner ids +com.example:foo,com.example:bar.@StubRunnerPort("foo") +int fooPort; +@StubRunnerPort("com.example:bar") +int barPort;Stub Runner can integrate with Spring Cloud.
For real life examples you can check the
The most important feature of
Stub Runner Spring Cloudis the fact that it’s stubbing
DiscoveryClientRibbonServerListthat means that regardless of the fact whether you’re using Zookeeper, Consul, Eureka or anything else, you don’t need that in your tests. We’re starting WireMock instances of your dependencies and we’re telling your application whenever you’re using
Feign, load balancedRestTemplateorDiscoveryClientdirectly, to call those stubbed servers instead of calling the real Service Discovery tool.For example this test will pass
def 'should make service discovery work'() { expect: 'WireMocks are running' @@ -5467,7 +5489,8 @@ annotation or the stub runner. If you use the JUnit@Rule< classpath and it is selected by theRestTemplateBuilderand configured to ignore SSL errors. If you use the defaultjava.netclient, you do not need the annotation (but it won’t do any harm). There is no support currently for other clients, but it may be added -in future releases.Spring Cloud Contract provides a convenience class that can load JSON WireMock stubs into +in future releases.
To disable the custom
RestTemplateBuilder, set thewiremock.rest-template-ssl-enabled+property tofalse.Spring Cloud Contract provides a convenience class that can load JSON WireMock stubs into a Spring
MockRestServiceServer. The following code shows an example:@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class WiremockForDocsMockServerApplicationTests { diff --git a/spring-cloud-contract.xml b/spring-cloud-contract.xml index 5f7e180538..1d0edbeb1e 100644 --- a/spring-cloud-contract.xml +++ b/spring-cloud-contract.xml @@ -4156,7 +4156,8 @@ and registers in WireMock the selected stubs. its methods as presented below:@ContextConfiguration(classes = Config, loader = SpringBootContextLoader) @SpringBootTest(properties = [" stubrunner.cloud.enabled=false", - 'foo=${stubrunner.runningstubs.fraudDetectionServer.port}']) + 'foo=${stubrunner.runningstubs.fraudDetectionServer.port}', + 'fooWithGroup=${stubrunner.runningstubs.org.springframework.cloud.contract.verifier.stubs.fraudDetectionServer.port}']) @AutoConfigureStubRunner(mappingsOutputFolder = "target/outputmappings/") @DirtiesContext @ActiveProfiles("test") @@ -4164,6 +4165,8 @@ class StubRunnerConfigurationSpec extends Specification { @Autowired StubFinder stubFinder @Autowired Environment environment + @StubRunnerPort("fraudDetectionServer") int fraudDetectionServerPort + @StubRunnerPort("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer") int fraudDetectionServerPortWithGroupId @Value('${foo}') Integer foo @BeforeClass @@ -4208,6 +4211,9 @@ class StubRunnerConfigurationSpec extends Specification { and: environment.getProperty("stubrunner.runningstubs.fraudDetectionServer.port") != null stubFinder.findAllRunningStubs().getPort("fraudDetectionServer") == (environment.getProperty("stubrunner.runningstubs.fraudDetectionServer.port") as Integer) + and: + environment.getProperty("stubrunner.runningstubs.fraudDetectionServer.port") != null + stubFinder.findAllRunningStubs().getPort("fraudDetectionServer") == (environment.getProperty("stubrunner.runningstubs.org.springframework.cloud.contract.verifier.stubs.fraudDetectionServer.port") as Integer) } def 'should be able to interpolate a running stub in the passed test property'() { @@ -4216,9 +4222,20 @@ class StubRunnerConfigurationSpec extends Specification { expect: fraudPort > 0 environment.getProperty("foo", Integer) == fraudPort + environment.getProperty("fooWithGroup", Integer) == fraudPort foo == fraudPort } + @Issue("#573") + def 'should be able to retrieve the port of a running stub via an annotation'() { + given: + int fraudPort = stubFinder.findAllRunningStubs().getPort("fraudDetectionServer") + expect: + fraudPort > 0 + fraudDetectionServerPort == fraudPort + fraudDetectionServerPortWithGroupId == fraudPort + } + def 'should dump all mappings to a file'() { when: def url = stubFinder.findStubUrl("fraudDetectionServer") @@ -4254,10 +4271,23 @@ for every registered WireMock server. Example for Stub Runner ids stubrunner.runningstubs.foo.port + ++ stubrunner.runningstubs.com.example.foo.port + stubrunner.runningstubs.bar.port + + stubrunner.runningstubs.com.example.bar.port Which you can reference in your code. +You can also use the +@StubRunnerPort annotation to inject the port of a running stub. +Value of the annotation can be thegroupid:artifactid or just theartifactid . Example for Stub Runner ids +com.example:foo ,com.example:bar .@StubRunnerPort("foo") +int fooPort; +@StubRunnerPort("com.example:bar") +int barPort; @@ -8656,6 +8686,8 @@ classpath and it is selected by the RestTemplateBuilder and c errors. If you use the defaultjava.net client, you do not need the annotation (but it won’t do any harm). There is no support currently for other clients, but it may be added in future releases. +To disable the custom RestTemplateBuilder , set thewiremock.rest-template-ssl-enabled +property tofalse .WireMock and Spring MVC Mocks