From 26afe17ec5b3e58ef0b558d33eee3240d0be20bb Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Sun, 24 Apr 2016 22:08:46 +0200 Subject: [PATCH] Updated docs --- docs/src/docs/asciidoc/contract.adoc | 2 + docs/src/docs/asciidoc/index.adoc | 2 + docs/src/docs/asciidoc/messaging.adoc | 2 +- docs/src/docs/asciidoc/stubrunner_msg.adoc | 3 +- stub-runner/stub-runner-junit/README.adoc | 72 ++----------------- .../junit/AccurestRuleJUnitTest.java | 10 ++- .../stubrunner/junit/AccurestRuleSpec.groovy | 2 + .../stub-runner-spring-cloud/README.adoc | 3 +- stub-runner/stub-runner-spring/README.adoc | 31 +------- .../spring/StubRunnerConfigurationSpec.groovy | 2 + stub-runner/stub-runner/README.adoc | 13 ++-- 11 files changed, 35 insertions(+), 107 deletions(-) diff --git a/docs/src/docs/asciidoc/contract.adoc b/docs/src/docs/asciidoc/contract.adoc index a028da70cb..1e8fb9b780 100644 --- a/docs/src/docs/asciidoc/contract.adoc +++ b/docs/src/docs/asciidoc/contract.adoc @@ -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 diff --git a/docs/src/docs/asciidoc/index.adoc b/docs/src/docs/asciidoc/index.adoc index 2cd9d4ea76..3447efe7db 100644 --- a/docs/src/docs/asciidoc/index.adoc +++ b/docs/src/docs/asciidoc/index.adoc @@ -1,3 +1,5 @@ +:messaging_version: 1.0.7 + include::introduction.adoc[] include::contract.adoc[] diff --git a/docs/src/docs/asciidoc/messaging.adoc b/docs/src/docs/asciidoc/messaging.adoc index 037d49cb24..e47549ef98 100644 --- a/docs/src/docs/asciidoc/messaging.adoc +++ b/docs/src/docs/asciidoc/messaging.adoc @@ -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. diff --git a/docs/src/docs/asciidoc/stubrunner_msg.adoc b/docs/src/docs/asciidoc/stubrunner_msg.adoc index 482dae2e01..76bf5c241e 100644 --- a/docs/src/docs/asciidoc/stubrunner_msg.adoc +++ b/docs/src/docs/asciidoc/stubrunner_msg.adoc @@ -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: diff --git a/stub-runner/stub-runner-junit/README.adoc b/stub-runner/stub-runner-junit/README.adoc index 23b995c55f..ff253fa537 100644 --- a/stub-runner/stub-runner-junit/README.adoc +++ b/stub-runner/stub-runner-junit/README.adoc @@ -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. diff --git a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java b/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java index 8b6b237925..db2719191d 100644 --- a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java +++ b/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleJUnitTest.java @@ -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 { diff --git a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleSpec.groovy b/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleSpec.groovy index 91f693c113..1883c8b5d8 100644 --- a/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleSpec.groovy +++ b/stub-runner/stub-runner-junit/src/test/groovy/io/codearte/accurest/stubrunner/junit/AccurestRuleSpec.groovy @@ -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[] } diff --git a/stub-runner/stub-runner-spring-cloud/README.adoc b/stub-runner/stub-runner-spring-cloud/README.adoc index 003b94422f..d874c8f9d6 100644 --- a/stub-runner/stub-runner-spring-cloud/README.adoc +++ b/stub-runner/stub-runner-spring-cloud/README.adoc @@ -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` \ No newline at end of file diff --git a/stub-runner/stub-runner-spring/README.adoc b/stub-runner/stub-runner-spring/README.adoc index 0d87fe9146..7d07363bdb 100644 --- a/stub-runner/stub-runner-spring/README.adoc +++ b/stub-runner/stub-runner-spring/README.adoc @@ -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] ---- \ No newline at end of file diff --git a/stub-runner/stub-runner-spring/src/test/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfigurationSpec.groovy b/stub-runner/stub-runner-spring/src/test/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfigurationSpec.groovy index b43cd14143..a6800015b6 100644 --- a/stub-runner/stub-runner-spring/src/test/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfigurationSpec.groovy +++ b/stub-runner/stub-runner-spring/src/test/groovy/io/codearte/accurest/stubrunner/spring/StubRunnerConfigurationSpec.groovy @@ -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[] \ No newline at end of file diff --git a/stub-runner/stub-runner/README.adoc b/stub-runner/stub-runner/README.adoc index 102a4225cf..d6dd566c1f 100644 --- a/stub-runner/stub-runner/README.adoc +++ b/stub-runner/stub-runner/README.adoc @@ -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. \ No newline at end of file +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. \ No newline at end of file