Updated docs

This commit is contained in:
Marcin Grzejszczak
2016-07-20 18:36:51 +02:00
parent 9f0881b4cd
commit 19092baabd
27 changed files with 277 additions and 141 deletions

View File

@@ -31,7 +31,7 @@ TIP: The Accurest project was initially started by Marcin Grzejszczak and Jakub
Just to make long story short - Spring Cloud Contract Verifier is a tool that enables Consumer Driven Contract (CDC) development of JVM-based applications. It is shipped
with __Contract Definition Language__ (DSL). Contract definitions are used to produce following resources:
* JSON stub definitions to be used by Wiremock when doing integration testing on the client code (__client tests__).
* JSON stub definitions to be used by WireMock when doing integration testing on the client code (__client tests__).
Test code must still be written by hand, test data is produced by Spring Cloud Contract Verifier.
* Messaging routes if you're using one. We're integrating with Spring Integration, Spring Cloud Stream and Apache Camel. You can however set your own integrations if you want to
* Acceptance tests (in JUnit or Spock) used to verify if server-side implementation of the API is compliant with the contract (__server tests__).
@@ -105,7 +105,7 @@ The main purposes of Spring Cloud Contract Verifier with Stub Runner are:
==== Client Side
During the tests you want to have a Wiremock instance / Messaging route up and running that simulates the service Y.
During the tests you want to have a WireMock instance / Messaging route up and running that simulates the service Y.
You would like to feed that instance with a proper stub definition. That stub definition would need
to be valid and should also be reusable on the server side.

View File

@@ -1,5 +1,5 @@
:toc: left
:toclevels: 6
:toclevels: 8
= Spring Cloud Contract

View File

@@ -9,7 +9,7 @@ TIP: The Accurest project was initially started by Marcin Grzejszczak and Jakub
Just to make long story short - Spring Cloud Contract Verifier is a tool that enables Consumer Driven Contract (CDC) development of JVM-based applications. It is shipped
with __Contract Definition Language__ (DSL). Contract definitions are used to produce following resources:
* JSON stub definitions to be used by Wiremock when doing integration testing on the client code (__client tests__).
* JSON stub definitions to be used by WireMock when doing integration testing on the client code (__client tests__).
Test code must still be written by hand, test data is produced by Spring Cloud Contract Verifier.
* Messaging routes if you're using one. We're integrating with Spring Integration, Spring Cloud Stream and Apache Camel. You can however set your own integrations if you want to
* Acceptance tests (in JUnit or Spock) used to verify if server-side implementation of the API is compliant with the contract (__server tests__).
@@ -83,7 +83,7 @@ The main purposes of Spring Cloud Contract Verifier with Stub Runner are:
==== Client Side
During the tests you want to have a Wiremock instance / Messaging route up and running that simulates the service Y.
During the tests you want to have a WireMock instance / Messaging route up and running that simulates the service Y.
You would like to feed that instance with a proper stub definition. That stub definition would need
to be valid and should also be reusable on the server side.

View File

@@ -11,35 +11,20 @@ You can use one of the three integration configurations:
- Spring Integration
- Spring Cloud Stream
You have to provide as a dependency one of the Spring Cloud Contract Verifier Messaging modules. Example for Gradle:
Since we're using Spring Boot then if you have added one of the aforementioned libraries
to the classpath then automatically all the messaging configuration will be set up.
[source,groovy,indent=0]
----
// for Apache Camel
testCompile "org.springframework.cloud:spring-cloud-contract-verifier-camel"
// for Spring Integration
testCompile "org.springframework.cloud:spring-cloud-contract-verifier-integration"
// for Spring Cloud Stream
testCompile "org.springframework.cloud:spring-cloud-contract-verifier-stream"
----
If you're using Spring Boot, the test configurations will be added automatically.
IMPORTANT: Remember to put `@AutoConfigureMessageVerifier` on the base class of your
generated tests. Otherwise messaging part of Spring Cloud Contract Verifier will not work.
==== Manual Integration Testing
The `spring-cloud-contract-verifier-messaging-core` module contains `ContractVerifierMessageExchange`,
class that allows you to build, send and receive messages
The main interface used by the tests is the `org.springframework.cloud.contract.verifier.messaging.MessageVerifier`.
It defines how to send and receive messages. You can create your own implementation to achieve the
same goal.
In the a test you can inject a `ContractVerifierMessageExchange` to send and receive messages that follow the contract.
You have to provide as a dependency the messaging module that matches your provider. Example for Gradle and Spring Integration:
[source,groovy,indent=0]
----
testCompile "org.springframework.cloud:spring-cloud-contract-verifier-integration"
----
and then add `@AutoConfigureMessageVerifier` to your test, e.g.
Then add `@AutoConfigureMessageVerifier` to your test, e.g.
[source,java,indent=0]
----
@@ -157,4 +142,4 @@ include::{plugins_path}/spring-cloud-contract-gradle-plugin/src/test/resources/f
===== Maven Setup
Example of Maven can be found in the https://github.com/spring-cloud/spring-cloud-contract/[Spring Cloud Contract Verifier README]
Example of Maven can be found in the https://github.com/spring-cloud/spring-cloud-contract/tree/master/samples/standalone/stream-sink/pom.xml[Stream Sink sample]

View File

@@ -4,7 +4,10 @@
===== Prerequisites
In order to use Spring Cloud Contract Verifier with WireMock you have to use gradle or maven plugin.
In order to use Spring Cloud Contract Verifier with WireMock you have to use Gradle or Maven plugin.
WARNING: If you want to use Spock in your projects you have to add separately
the `spock-core` and `spock-spring` modules. Check http://spockframework.github.io/[Spock docs for more information]
====== Add gradle plugin
@@ -29,7 +32,7 @@ dependencies {
}
----
======= Snapshot versions
====== Snapshot versions for Gradle
Add the additional snapshot repository to your build.gradle to use snapshot versions which are automatically uploaded after every successful build:
@@ -61,9 +64,76 @@ repositories {
</plugin>
----
Read more: https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract-maven-plugin/[spring-cloud-contract-maven-plugin]
====== Snapshot versions for Maven
For Snapshot / Milestone versions you have to add the following section to your `pom.xml`
[source,xml,indent=0]
----
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-plugin-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/plugins-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-plugin-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/plugins-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
----
====== Add stubs
By default Spring Cloud Contract Verifier is looking for stubs in `src/test/resources/contracts` directory.
@@ -216,30 +286,95 @@ class LoanApplicationServiceSpec extends Specification {
}
----
Underneath LoanApplication makes a call to FraudDetection service. This request is handled by Wiremock server configured using stubs generated by Spring Cloud Contract Verifier.
Underneath LoanApplication makes a call to FraudDetection service. This request is handled by WireMock server configured using stubs generated by Spring Cloud Contract Verifier.
==== Using in your Maven project
===== Add maven plugin
Add the Spring Cloud Contract BOM
[source,xml,indent=0]
----
<plugin>
<groupId>org.springframework.cloud.verifier</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>convert</goal>
<goal>generateStubs</goal>
<goal>generateTests</goal>
</goals>
</execution>
</executions>
</plugin>
include::{standalone_samples_path}/http-server/pom.xml[tags=contract_bom,indent=0]
----
Read more: https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract-maven-plugin/[spring-cloud-contract-maven-plugin]
Next, the `Spring Cloud Contract Verifier` Maven plugin
[source,xml,indent=0]
----
include::{standalone_samples_path}/http-server/pom.xml[tags=contract_maven_plugin,indent=0]
----
You can read more in the https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract-maven-plugin/[Spring Cloud Contract Maven Plugin Docs]
====== Snapshot versions
For Snapshot / Milestone versions you have to add the following section to your `pom.xml`
[source,xml,indent=0]
----
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-plugin-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/plugins-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-plugin-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/plugins-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
----
===== Add stubs
@@ -269,7 +404,7 @@ To change default configuration just add `configuration` section to plugin defin
[source,xml,indent=0]
----
<plugin>
<groupId>org.springframework.cloud.verifier</groupId>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<executions>
<execution>
@@ -294,13 +429,14 @@ To change default configuration just add `configuration` section to plugin defin
- **ruleClassForTests** - specifies Rule which should be added to generated test classes.
- **baseClassForTests** - base class for generated tests. By default `spock.lang.Specification` if using Spock tests.
- **contractsDir** - directory containing contracts written using the GroovyDSL. By default `/src/test/resources/contracts`.
- **testFramework** - the target test framework to be used; currently Spock and JUnit are supported with Spock being the default framework
- **testFramework** - the target test framework to be used; currently Spock and JUnit are supported with JUnit being the default framework
For complete information take a look at https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract-maven-plugin/plugin-info.html[Plugin Documentation]
====== Base class for tests
When using Spring Cloud Contract Verifier in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified.
When using Spring Cloud Contract Verifier in default MockMvc you need to create a base specification for all generated acceptance tests.
In this class you need to point to endpoint which should be verified.
[source,groovy,indent=0]
----
@@ -321,7 +457,7 @@ In case of using `Explicit` mode, you can use base class to initialize the whole
===== Invoking generated tests
Spring Cloud Contract Verifier Maven Plugins generates verification code into directory `/generated-test-sources/contractVerifier` and attach this directory to `testCompile` goal.
Spring Cloud Contract Verifier Maven Plugin generates verification code into directory `/generated-test-sources/contractVerifier` and attach this directory to `testCompile` goal.
For Groovy Spock code use:
@@ -361,14 +497,22 @@ To ensure that provider side is complaint with defined contracts, you need to in
===== Spring Cloud Contract Verifier on consumer side
In consumer service you need to configure Spring Cloud Contract Verifier plugin in exactly the same way as in case of provider. You need to copy contracts stored in `src/test/resources/contracts` and generate Wiremock json stubs using: `mvn generateStubs` command. By default generated WireMock mapping is stored in directory `target/mappings`. Your project should create from this generated mappings additional artifact with classifier `stubs` for easy deploy to maven repository.
You can actually use the Spring Cloud Contract Verifier also for the consumer side!
You can use the plugin so that it only converts the contracts and generates the stubs.
To achieve that you need to configure Spring Cloud Contract Verifier plugin in exactly
the same way as in case of provider. You need to copy contracts stored in
`src/test/resources/contracts` and generate WireMock json stubs using:
`mvn generateStubs` command. By default generated WireMock mapping is
stored in directory `target/mappings`. Your project should create from
this generated mappings additional artifact with classifier `stubs` for
easy deploy to maven repository.
Sample configuration:
[source,xml,indent=0]
----
<plugin>
<groupId>org.springframework.cloud.verifier</groupId>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${verifier-plugin.version}</version>
<executions>
@@ -408,7 +552,8 @@ public class LoanApplicationServiceTests {
}
----
Underneath `LoanApplication` makes a call to the `FraudDetection` service. This request is handled by a Wiremock server configured using stubs generated by Spring Cloud Contract Verifier.
Underneath `LoanApplication` makes a call to the `FraudDetection` service. This request is handled by
a WireMock server configured using stubs generated by Spring Cloud Contract Verifier.
==== Scenarios
@@ -423,10 +568,12 @@ my_contracts_dir\
3_logout.groovy
----
Such tree will cause Spring Cloud Contract Verifier generating Wiremock's scenario with name `scenario1` and three steps:
Such tree will cause Spring Cloud Contract Verifier generating WireMock's scenario with name `scenario1` and three steps:
- login marked as `Started` pointing to:
- showCart marked as `Step1` pointing to:
- logout marked as `Step2` which will close the scenario.
More details about Wiremock scenarios can be found under http://wiremock.org/stateful-behaviour.html[http://wiremock.org/stateful-behaviour.html]
More details about WireMock scenarios can be found under http://wiremock.org/stateful-behaviour.html[http://wiremock.org/stateful-behaviour.html]
Spring Cloud Contract Verifier will also generate tests with guaranteed order of execution.

View File

@@ -4,7 +4,7 @@
:samples_path: {core_path}/samples
:verifier_core_path: {verifier_root_path}
:stubrunner_core_path: {core_path}/spring-cloud-contract-stub-runner
:standalone_samples_path: {samples_path}/samples-standalone
:standalone_samples_path: {samples_path}/standalone
:tests_path: ../../../../../tests
include::introduction.adoc[]

View File

@@ -5,6 +5,9 @@ One of the issues that you could have encountered while using Spring Cloud Contr
Copying the JSON files / setting the client side for messaging manually is out of the question.
That's why we'll introduce Spring Cloud Contract Stub Runner that can download and run the stubs
automatically for you.
==== Snapshot versions
Add the additional snapshot repository to your build.gradle to use snapshot versions which are automatically uploaded after every successful build:
@@ -18,6 +21,38 @@ repositories {
}
----
for Maven
[source,xml,indent=0]
----
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
----
==== Publishing stubs as JARs
The easiest approach would be to centralize the way stubs are kept. For example you can keep them as JARs in a Maven repository.
@@ -37,20 +72,8 @@ Example of Maven can be found in the https://github.com/spring-cloud/spring-clou
==== Modules
Spring Cloud Contract Stub Runner comes with a new structure of modules
[source,indent=0]
----
└── spring-cloud-contract-stub-runner
├── spring-cloud-contract-stub-runner
├── spring-cloud-contract-stub-runner-boot
├── spring-cloud-contract-stub-runner-spring
└── spring-cloud-contract-stub-runner-spring-cloud
----
include::{stubrunner_core_path}/README.adoc[]
==== Common properties for JUnit and Spring
Some of the properties that are repetitive can be set using system properties or configuration properties (for Spring). Here are their names with their default values:

View File

@@ -55,7 +55,7 @@ public class XegerTest {
}
private List<String> generateRegex(Xeger generator, int count) {
List<String> regexList = new ArrayList<String>();
List<String> regexList = new ArrayList<>();
for (int i = 0; i < count; i++) {
regexList.add(generator.generate());
}

View File

@@ -129,7 +129,7 @@ You can see that for this example the following test is valid:
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleCustomPortJUnitTest.java[tags=test_with_port]
----
==== Stub Runner Spring
==== Stub Runner with Spring
Sets up Spring configuration of the Stub Runner project.
@@ -153,14 +153,7 @@ include::src/test/resources/application.yml[]
=== Stub Runner Spring Cloud
Registers the stubs in the provided Service Discovery. It's enough to add the jar
[source,groovy,indent=0]
----
org.springframework.cloud:stub-runner-spring-cloud
----
and the Stub Runner autoconfiguration should be picked up.
Stub Runner can integrate with Spring Cloud.
==== Stubbing Service Discovery
@@ -169,22 +162,36 @@ The most important feature of `Stub Runner Spring Cloud` is the fact that it's s
- `DiscoveryClient`
- `Ribbon` `ServerList`
that means that regardles of the fact whether you're using Zookeeper, Consul, Eureka or anything else, you don't need that in your tests.
that 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 balanced `RestTemplate`
or `DiscoveryClient` directly, to call those stubbed servers instead of calling the real Service Discovery tool.
For example this test will pass
[source,groovy,indent=0]
----
include::src/test/groovy/org/springframework/cloud/contract/stubrunner/spring/cloud/StubRunnerSpringCloudAutoConfigurationSpec.groovy[tags=test]
----
for the following configuration file
[source,yml,indent=0]
----
include::src/test/resources/application.yml[]
----
==== Additional Configuration
You can match the artifactId of the stub with the name of your app by using the `stubrunner.stubs.idsToServiceIds:` map.
You can disable Stub Runner Ribbon support by providing: `stubrunner.cloud.ribbon.enabled` equal to `false`
You can disable Stub Runner support by providing: `stubrunner.cloud.enabled` equal to `false`
=== Stub Runner Boot
=== Stub Runner Boot Application
Spring Cloud Contract Verifier Stub Runner Boot is a Spring Boot application that exposes REST endpoints to
trigger the messaging labels and to access started WireMock servers.
One of the usecases is to run some smoke (end to end) tests on a deployed application. You can read
One of the use-cases is to run some smoke (end to end) tests on a deployed application. You can read
more about this in the http://toomuchcoding.com/blog/2015/09/27/microservice-deployment/["Microservice Deployment" article at Too Much Coding blog.]
==== How to use it?
@@ -193,22 +200,10 @@ Just add the
[source,groovy,indent=0]
----
compile "org.springframework.cloud:spring-cloud-stub-runner"
compile "org.springframework.cloud:spring-cloud-starter-stub-runner"
----
and (optionally) a messaging implementation:
[source,groovy,indent=0]
----
// for Apache Camel
compile "org.springframework.cloud:spring-cloud-contract-stub-runner-camel"
// for Spring Integration
compile "org.springframework.cloud:spring-cloud-contract-stub-runner-integration"
// for Spring Cloud Stream
compile "org.springframework.cloud:spring-cloud-contract-stub-runner-stream"
----
Build a fat-jar with `@EnableStubRunnerServer` and you're ready to go!
Annotate a class with `@EnableStubRunnerServer`, build a fat-jar and you're ready to go!
For the properties check the *Stub Runner Spring* section.

View File

@@ -151,9 +151,9 @@ public class AetherStubDownloader implements StubDownloader {
if (unpackedJar == null) {
return null;
}
return new AbstractMap.SimpleEntry<StubConfiguration, File>(new StubConfiguration(
stubConfiguration.groupId, stubConfiguration.artifactId, version,
stubConfiguration.classifier), unpackedJar);
return new AbstractMap.SimpleEntry<>(
new StubConfiguration(stubConfiguration.groupId, stubConfiguration.artifactId, version,
stubConfiguration.classifier), unpackedJar);
}
private String resolveHighestArtifactVersion(String stubsGroup, String stubsModule,

View File

@@ -78,7 +78,7 @@ public class StubRunnerMain {
private void execute() {
try {
log.debug("Launching StubRunner with args: $arguments");
log.debug("Launching StubRunner with args: " + arguments);
// TODO: Pass StubsToRun either from String or File
BatchStubRunner stubRunner = new BatchStubRunnerFactory(arguments.getStubRunnerOptions()).buildBatchStubRunner();
RunningStubs runningCollaborators = stubRunner.runStubs();

View File

@@ -26,13 +26,9 @@ import java.lang.annotation.Target;
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration;
import org.springframework.context.annotation.Import;
/**
* @author Dave Syer
*
*/
/**
* Annotation to enable a Stub runner server.
* @author Spencer Gibb
* @author Dave Syer
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)

View File

@@ -51,6 +51,6 @@ public class HttpStubsController {
if (port!=null) {
return ResponseEntity.ok(port);
}
return new ResponseEntity<Integer>(HttpStatus.NOT_FOUND);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

View File

@@ -38,7 +38,7 @@ public class StubRunnerBackupAutoConfiguration {
@Bean
public ContractVerifierMessaging<Object> contractVerifierMessaging(
MessageVerifier<Object> exchange) {
return new ContractVerifierMessaging<Object>(exchange);
return new ContractVerifierMessaging<>(exchange);
}
}

View File

@@ -55,7 +55,7 @@ public class TriggerController {
return ResponseEntity.ok().body(Collections.<String, Collection<String>>emptyMap());
} catch (Exception e) {
log.debug("Exception occurred while trying to return " + label + " label", e);
return new ResponseEntity<Map<String,Collection<String>>>(stubFinder.labels(), HttpStatus.NOT_FOUND);
return new ResponseEntity<>(stubFinder.labels(), HttpStatus.NOT_FOUND);
}
}
@@ -66,7 +66,7 @@ public class TriggerController {
return ResponseEntity.ok().body(Collections.<String, Collection<String>>emptyMap());
} catch (Exception e) {
log.debug("Exception occurred while trying to return " + label + " label", e);
return new ResponseEntity<Map<String,Collection<String>>>(stubFinder.labels(), HttpStatus.NOT_FOUND);
return new ResponseEntity<>(stubFinder.labels(), HttpStatus.NOT_FOUND);
}
}

View File

@@ -22,7 +22,7 @@ package org.springframework.cloud.contract.stubrunner.util;
* @author Marcin Grzejszczak
*/
public class StringUtils {
public static String EMPTY = "";
public static final String EMPTY = "";
private static int INDEX_NOT_FOUND = -1;
// Empty checks

View File

@@ -32,9 +32,10 @@ import spock.lang.Specification
/**
* @author Marcin Grzejszczak
*/
// Not necessary if Spring Cloud is used. TODO: make it work without this.
// tag::test[]
@ContextConfiguration(classes = Config, loader = SpringBootContextLoader)
// Not necessary if Spring Cloud is used. TODO: make it work without this.
@IntegrationTest(["stubrunner.cloud.enabled=false", "stubrunner.camel.enabled=false"])
@AutoConfigureStubRunner
@DirtiesContext

View File

@@ -58,11 +58,12 @@ class StubRunnerSpringCloudAutoConfigurationSpec extends Specification {
@BeforeClass
@AfterClass
void setupProps() {
static void setupProps() {
System.clearProperty("stubrunner.stubs.repository.root");
System.clearProperty("stubrunner.stubs.classifier");
}
// tag::test[]
def 'should make service discovery work'() {
expect: 'WireMocks are running'
"${stubFinder.findStubUrl('loanIssuance').toString()}/name".toURL().text == 'loanIssuance'
@@ -71,6 +72,7 @@ class StubRunnerSpringCloudAutoConfigurationSpec extends Specification {
restTemplate.getForObject('http://loanIssuance/name', String) == 'loanIssuance'
restTemplate.getForObject('http://someNameThatShouldMapFraudDetectionServer/name', String) == 'fraudDetectionServer'
}
// end::test[]
TestingServer startTestingServer() {
return new TestingServer(SocketUtils.findAvailableTcpPort())

View File

@@ -22,13 +22,13 @@ import java.util.concurrent.TimeUnit;
/**
* Core interface that allows you to build, send and receive messages.
*
* Destination is relevant to the underlaying implementation. Might be a channel, queue, topic etc.
* Destination is relevant to the underlying implementation. Might be a channel, queue, topic etc.
*
* @author Marcin Grzejszczak
*/
public interface MessageVerifier<M> {
/**
* Sends the {@link ContractVerifierMessage} to the given destination.
* Sends the message to the given destination.
*/
void send(M message, String destination);
@@ -38,13 +38,13 @@ public interface MessageVerifier<M> {
<T> void send(T payload, Map<String, Object> headers, String destination);
/**
* Receives the {@link ContractVerifierMessage} from the given destination. You can provide the timeout
* Receives the message from the given destination. You can provide the timeout
* for receiving that message.
*/
M receive(String destination, long timeout, TimeUnit timeUnit);
/**
* Receives the {@link ContractVerifierMessage} from the given destination. A default timeout will be applied.
* Receives the message from the given destination. A default timeout will be applied.
*/
M receive(String destination);
}

View File

@@ -35,8 +35,7 @@ import org.springframework.stereotype.Component;
* @author Marcin Grzejszczak
*/
@Component
public class CamelStubMessages implements
MessageVerifier<Message> {
public class CamelStubMessages implements MessageVerifier<Message> {
private static final Logger log = LoggerFactory.getLogger(
CamelStubMessages.class);
@@ -77,7 +76,7 @@ public class CamelStubMessages implements
} catch (Exception e) {
log.error("Exception occurred while trying to read a message from " +
" a channel with name [" + destination + "]", e);
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

View File

@@ -37,7 +37,7 @@ import org.springframework.messaging.Message;
@ConditionalOnClass(Message.class)
@AutoConfigureBefore(NoOpContractVerifierAutoConfiguration.class)
@AutoConfigureAfter(ContractVerifierStreamAutoConfiguration.class)
public class ContractVerifierIntegrationConfiguration<T> {
public class ContractVerifierIntegrationConfiguration {
@Bean
@ConditionalOnMissingBean

View File

@@ -72,7 +72,7 @@ public class SpringIntegrationStubMessages implements
} catch (Exception e) {
log.error("Exception occurred while trying to read a message from " +
" a channel with name [" + destination + "]", e);
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

View File

@@ -41,7 +41,7 @@ public class NoOpContractVerifierAutoConfiguration {
@ConditionalOnMissingBean
public ContractVerifierMessaging<?> contractVerifierMessaging(
MessageVerifier<Object> exchange) {
return new ContractVerifierMessaging<Object>(exchange);
return new ContractVerifierMessaging<>(exchange);
}
}

View File

@@ -76,7 +76,7 @@ public class StreamStubMessages implements MessageVerifier<Message<?>> {
catch (Exception e) {
log.error("Exception occurred while trying to read a message from "
+ " a channel with name [" + destination + "]", e);
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

View File

@@ -9,12 +9,8 @@ routes.
==== Adding it to the project
To use it you have to add the following dependency to your project (example for Gradle):
[source,groovy,indent=0]
----
testCompile "org.springframework.cloud:stub-runner-camel:${verifierVersion}"
----
It's enough to have both Apache Camel and Spring Cloud Contract Stub Runner on classpath.
Remember to annotate your test class with `@AutoConfigureMessageVerifier`.
==== Examples

View File

@@ -9,12 +9,8 @@ routes.
==== Adding it to the project
To use it you have to add the following dependency to your project (example for Gradle):
[source,groovy,indent=0]
----
testCompile "org.springframework.cloud:stub-runner-integration:${verifierVersion}"
----
It's enough to have both Apache Camel and Spring Cloud Contract Stub Runner on classpath.
Remember to annotate your test class with `@AutoConfigureMessageVerifier`.
==== Examples

View File

@@ -10,12 +10,8 @@ channel name.
==== Adding it to the project
To use it you have to add the following dependency to your project (example for Gradle):
[source,groovy,indent=0]
----
testCompile "org.springframework.cloud:stub-runner-stream:${verifierVersion}"
----
It's enough to have both Apache Camel and Spring Cloud Contract Stub Runner on classpath.
Remember to annotate your test class with `@AutoConfigureMessageVerifier`.
==== Examples