Updated docs

This commit is contained in:
Marcin Grzejszczak
2016-04-24 22:08:46 +02:00
parent 204637159e
commit 26afe17ec5
11 changed files with 35 additions and 107 deletions

View File

@@ -162,6 +162,8 @@ include::../../../../accurest-core/src/test/groovy/io/codearte/accurest/builder/
=== Messaging Top-Level Elements
WARNING: Feature available since {messaging_version}
The DSL for messaging looks a little bit different than the one that focuses on HTTP.
==== Output triggered by a method

View File

@@ -1,3 +1,5 @@
:messaging_version: 1.0.7
include::introduction.adoc[]
include::contract.adoc[]

View File

@@ -1,6 +1,6 @@
== Accurest Messaging
WARNING: Feature available since 1.0.7
WARNING: Feature available since {messaging_version}
Accurest allows you to verify your application that uses messaging as means of communication.
All of our integrations are working with Spring but you can also set one yourself.

View File

@@ -1,6 +1,6 @@
== Stub Runner for Messaging
WARNING: Feature available since 1.0.7
WARNING: Feature available since {messaging_version}
Stub Runner has the functionality to run the published stubs in memory. It can integrate with the following frameworks out of the box
@@ -10,7 +10,6 @@ Stub Runner has the functionality to run the published stubs in memory. It can i
It also provides points of entry to integrate with any other solution on the market.
=== Stub triggering
To trigger a message it's enough to use the `StubTiggerer` interface:

View File

@@ -4,11 +4,7 @@ Stub Runner comes with a JUnit rule thanks to which you can very easily download
[source,java,indent=0]
----
@ClassRule public static AccurestRule rule == new AccurestRule()
.repoRoot("http://your.repo.com")
.downloadStub("io.codearte.accurest.stubs", "loanIssuance")
.downloadStub("io.codearte.accurest.stubs:fraudDetectionServer")
.downloadStub("io.codearte:stub1", "io.codearte:stub2:classifier", "io.codearte:stub3");
include::src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java[tags=classrule]
----
After that rule gets executed Stub Runner connects to your Maven repository and for the given list of dependencies tries to:
@@ -25,81 +21,21 @@ Since the `AccurestRule` implements the `StubFinder` it allows you to find the s
[source,groovy,indent=0]
----
interface StubFinder {
/**
* For the given groupId and artifactId tries to find the matching
* URL of the running stub.
*
* @param groupId - might be null. In that case a search only via artifactId takes place
* @return URL of a running stub or null if not found
*/
URL findStubUrl(String groupId, String artifactId)
/**
* For the given Ivy notation {@code groupId:artifactId} tries to find the matching
* URL of the running stub. You can also pass only {@code artifactId}.
*
* @param ivyNotation - Ivy representation of the Maven artifact
* @return URL of a running stub or null if not found
*/
URL findStubUrl(String ivyNotation)
/**
* Returns all running stubs
*/
RunningStubs findAllRunningStubs()
}
include::../stub-runner/src/main/groovy/io/codearte/accurest/stubrunner/StubFinder.groovy[]
----
Example of usage in Spock tests:
[source,groovy,indent=0]
----
@ClassRule @Shared AccurestRule rule == new AccurestRule()
.repoRoot('http://your.repo.com')
.downloadStub("io.codearte.accurest.stubs", "loanIssuance")
.downloadStub("io.codearte.accurest.stubs:fraudDetectionServer")
def 'should start WireMock servers'() {
expect: 'WireMocks are running'
rule.findStubUrl('io.codearte.accurest.stubs', 'loanIssuance') !== null
rule.findStubUrl('loanIssuance') !== null
rule.findStubUrl('loanIssuance') === rule.findStubUrl('io.codearte.accurest.stubs', 'loanIssuance')
rule.findStubUrl('io.codearte.accurest.stubs:fraudDetectionServer') !== null
and:
rule.findAllRunningStubs().isPresent('loanIssuance')
rule.findAllRunningStubs().isPresent('io.codearte.accurest.stubs', 'fraudDetectionServer')
rule.findAllRunningStubs().isPresent('io.codearte.accurest.stubs:fraudDetectionServer')
and: 'Stubs were registered'
"${rule.findStubUrl('loanIssuance').toString()}/name".toURL().text === 'loanIssuance'
"${rule.findStubUrl('fraudDetectionServer').toString()}/name".toURL().text === 'fraudDetectionServer'
}
include::src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleSpec.java[tags=classrule]
----
Example of usage in JUnit tests:
[source,java,indent=0]
----
@ClassRule public static AccurestRule rule == new AccurestRule()
.repoRoot("http://your.repo.com")
.downloadStub("io.codearte.accurest.stubs", "loanIssuance")
.downloadStub("io.codearte.accurest.stubs:fraudDetectionServer");
@Test
public void should_start_wiremock_servers() throws Exception {
// expect: 'WireMocks are running'
then(rule.findStubUrl("io.codearte.accurest.stubs", "loanIssuance")).isNotNull();
then(rule.findStubUrl("loanIssuance")).isNotNull();
then(rule.findStubUrl("loanIssuance")).isEqualTo(rule.findStubUrl("io.codearte.accurest.stubs", "loanIssuance"));
then(rule.findStubUrl("io.codearte.accurest.stubs:fraudDetectionServer")).isNotNull();
// and:
then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
then(rule.findAllRunningStubs().isPresent("io.codearte.accurest.stubs", "fraudDetectionServer")).isTrue();
then(rule.findAllRunningStubs().isPresent("io.codearte.accurest.stubs:fraudDetectionServer")).isTrue();
// and: 'Stubs were registered'
then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance");
then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer");
}
include::src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java[tags=test]
----
Check the *Common properties for JUnit and Spring* for more information on how to apply global configuration of Stub Runner.

View File

@@ -1,14 +1,14 @@
package io.codearte.accurest.stubrunner.junit;
import java.io.InputStream;
import java.net.URI;
import org.apache.commons.io.IOUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import java.io.InputStream;
import java.net.URI;
import static org.assertj.core.api.BDDAssertions.then;
/**
@@ -23,11 +23,14 @@ public class AccurestRuleJUnitTest {
System.getProperties().setProperty("stubrunner.stubs.classifier", "stubs");
}
// tag:classrule[]
@ClassRule public static AccurestRule rule = new AccurestRule()
.repoRoot(repoRoot())
.downloadStub("io.codearte.accurest.stubs", "loanIssuance")
.downloadStub("io.codearte.accurest.stubs:fraudDetectionServer");
// end:classrule[]
// tag:test[]
@Test
public void should_start_wiremock_servers() throws Exception {
// expect: 'WireMocks are running'
@@ -43,6 +46,7 @@ public class AccurestRuleJUnitTest {
then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance");
then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer");
}
// end:test[]
private static String repoRoot() {
try {

View File

@@ -18,6 +18,7 @@ class AccurestRuleSpec extends Specification {
System.getProperties().setProperty("stubrunner.stubs.classifier", "stubs");
}
// tag:classrule[]
@ClassRule @Shared AccurestRule rule = new AccurestRule()
.repoRoot(AccurestRuleSpec.getResource("/m2repo").toURI().toString())
.downloadStub("io.codearte.accurest.stubs", "loanIssuance")
@@ -37,4 +38,5 @@ class AccurestRuleSpec extends Specification {
"${rule.findStubUrl('loanIssuance').toString()}/name".toURL().text == 'loanIssuance'
"${rule.findStubUrl('fraudDetectionServer').toString()}/name".toURL().text == 'fraudDetectionServer'
}
// end:classrule[]
}

View File

@@ -9,7 +9,8 @@ io.codearte.accurest:stub-runner-spring-cloud
and the Stub Runner autoconfiguration should be picked up.
You can match the artifactId of the stub with the name of your app by using the `stubrunner.stubs.idsToServiceIds:` map.
==== 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`

View File

@@ -10,37 +10,12 @@ its methods as presented below:
[source,groovy,indent=0]
----
@ContextConfiguration(classes == Config, loader == SpringApplicationContextLoader)
class StubRunnerConfigurationSpec extends Specification {
@Autowired StubFinder stubFinder
def 'should start WireMock servers'() {
expect: 'WireMocks are running'
stubFinder.findStubUrl('io.codearte.accurest.stubs', 'loanIssuance') !== null
stubFinder.findStubUrl('loanIssuance') !== null
stubFinder.findStubUrl('loanIssuance') === stubFinder.findStubUrl('io.codearte.accurest.stubs', 'loanIssuance')
stubFinder.findStubUrl('io.codearte.accurest.stubs:fraudDetectionServer') !== null
and:
stubFinder.findAllRunningStubs().isPresent('loanIssuance')
stubFinder.findAllRunningStubs().isPresent('io.codearte.accurest.stubs', 'fraudDetectionServer')
stubFinder.findAllRunningStubs().isPresent('io.codearte.accurest.stubs:fraudDetectionServer')
and: 'Stubs were registered'
"${stubFinder.findStubUrl('loanIssuance').toString()}/name".toURL().text === 'loanIssuance'
"${stubFinder.findStubUrl('fraudDetectionServer').toString()}/name".toURL().text === 'fraudDetectionServer'
}
@Configuration
@Import(StubRunnerConfiguration)
@EnableAutoConfiguration
static class Config {}
}
include::src/test/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfigurationSpec.groovy[tags=test]
----
for the following configuration file:
[source,groovy,indent=0]
[source,yml,indent=0]
----
stubrunner.stubs.repository.root: classpath:m2repo
stubrunner.stubs.ids: io.codearte.accurest.stubs:loanIssuance,io.codearte.accurest.stubs:fraudDetectionServer
include::src/test/resources/application.yml[tags=test]
----

View File

@@ -12,6 +12,7 @@ import spock.lang.Specification
/**
* @author Marcin Grzejszczak
*/
// tag::test[]
@ContextConfiguration(classes = Config, loader = SpringApplicationContextLoader)
class StubRunnerConfigurationSpec extends Specification {
@@ -37,3 +38,4 @@ class StubRunnerConfigurationSpec extends Specification {
@EnableAutoConfiguration
static class Config {}
}
// end::test[]

View File

@@ -3,6 +3,9 @@
Runs stubs for service collaborators. Treating stubs as contracts of services allows to use stub-runner as an implementation of
http://martinfowler.com/articles/consumerDrivenContracts.html[Consumer Driven Contracts].
Stub Runner allows you to automatically download the stubs of the provided dependencies, start WireMock servers for them and feed them with proper stub definitions.
For messaging, special stub routes are defined.
==== Running stubs
===== Running using main app
@@ -64,7 +67,7 @@ or each parameter separately with a `-P` prefix and without the hyphen `-` in th
./gradlew stub-runner-root:stub-runner:run -Pc=pl -Pminp=10000 -Pmaxp=10005 -Ps=a:b:c,d:e,f:g:h
----
===== Stubs
===== HTTP Stubs
Stubs are defined in JSON documents, whose syntax is defined in http://wiremock.org/stubbing.html[WireMock documentation]
@@ -87,8 +90,10 @@ Example:
}
----
In the provided JAR file we're harvesting all JSON files and try to put them inside running WireMock instance.
===== Viewing registered mappings
Every stubbed collaborator exposes list of defined mappings under `__/admin/` endpoint.
Every stubbed collaborator exposes list of defined mappings under `__/admin/` endpoint.
===== Messaging Stubs
Depending on the provided Stub Runner dependency and the DSL the messaging routes are automatically set up.