From 97928c8e6df238ecfaf0c5f48a5a1c268eb32c69 Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Fri, 12 Oct 2018 22:05:22 +0200 Subject: [PATCH] Add docs. --- docs/src/main/asciidoc/verifier_faq.adoc | 8 ++++---- spring-cloud-contract-stub-runner/README.adoc | 20 +++++++++++++------ .../junit/StubRunnerJUnit5ExtensionTest.java | 2 ++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/docs/src/main/asciidoc/verifier_faq.adoc b/docs/src/main/asciidoc/verifier_faq.adoc index 4640f8b32c..3c4d7ee7e6 100644 --- a/docs/src/main/asciidoc/verifier_faq.adoc +++ b/docs/src/main/asciidoc/verifier_faq.adoc @@ -634,7 +634,7 @@ In order to do that, use the usual producer setup, and then add the `pushStubsTo On the consumer side when passing the `repositoryRoot` parameter, either from the `@AutoConfigureStubRunner` annotation, the -JUnit rule or properties, it's enough to pass the URL of the +JUnit rule, JUnit 5 extension or properties, it's enough to pass the URL of the SCM repository, prefixed with the protocol. For example [source,java,indent=0] @@ -868,9 +868,9 @@ logging.level.com.github.tomakehurst.wiremock=ERROR ==== How can I see what got registered in the HTTP server stub? -You can use the `mappingsOutputFolder` property on `@AutoConfigureStubRunner` or `StubRunnerRule` -to dump all mappings per artifact id. Also the port at which the given stub server was -started will be attached. +You can use the `mappingsOutputFolder` property on `@AutoConfigureStubRunner`, `StubRunnerRule` or +`StubRunnerExtension`to dump all mappings per artifact id. Also the port at which the given stub server +was started will be attached. ==== Can I reference text from file? diff --git a/spring-cloud-contract-stub-runner/README.adoc b/spring-cloud-contract-stub-runner/README.adoc index c2b1b3fe70..86ac8fb7fd 100644 --- a/spring-cloud-contract-stub-runner/README.adoc +++ b/spring-cloud-contract-stub-runner/README.adoc @@ -267,7 +267,7 @@ mappings available for the given server: Depending on the provided Stub Runner dependency and the DSL the messaging routes are automatically set up. -=== Stub Runner JUnit Rule +=== Stub Runner JUnit Rule and Stub Runner JUnit5 Extension Stub Runner comes with a JUnit rule thanks to which you can very easily download and run stubs for given group and artifact id: @@ -276,7 +276,8 @@ Stub Runner comes with a JUnit rule thanks to which you can very easily download include::src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java[tags=classrule] ---- -After that rule gets executed Stub Runner connects to your Maven repository and for the given list of dependencies tries to: +There's also a `StubRunnerExtension` available for JUnit 5. `StubRunnerRule` and `StubRunnerExtension` work in a very +similar fashion. After the rule/ extension is executed, Stub Runner connects to your Maven repository and for the given list of dependencies tries to: - download them - cache them locally @@ -288,7 +289,7 @@ After that rule gets executed Stub Runner connects to your Maven repository and Stub Runner uses https://wiki.eclipse.org/Aether[Eclipse Aether] mechanism to download the Maven dependencies. Check their https://wiki.eclipse.org/Aether[docs] for more information. -Since the `StubRunnerRule` implements the `StubFinder` it allows you to find the started stubs: +Since the `StubRunnerRule` and `StubRunnerExtension` implement the `StubFinder` they allow you to find the started stubs: [source,groovy,indent=0] ---- @@ -309,11 +310,18 @@ Example of usage in JUnit tests: include::src/test/groovy/org/springframework/cloud/contract/stubrunner/junit/StubRunnerRuleJUnitTest.java[tags=test] ---- +JUnit 5 Extension example: + +[source,java,indent=0] +---- +include::src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionTest.java[tags=extension] +---- + Check the *Common properties for JUnit and Spring* for more information on how to apply global configuration of Stub Runner. -IMPORTANT: To use the JUnit rule together with messaging you have to provide an implementation of the +IMPORTANT: To use the JUnit rule or JUnit 5 extension together with messaging, you have to provide an implementation of the `MessageVerifier` interface to the rule builder (e.g. `rule.messageVerifier(new MyMessageVerifier())`). -If you don't do this then whenever you try to send a message an exception will be thrown. +If you don't do this, then whenever you try to send a message an exception will be thrown. ==== Maven settings @@ -327,7 +335,7 @@ JUnit rule. ==== Fluent API -When using the `StubRunnerRule` you can add a stub to download and then pass the port for the last downloaded stub. +When using the `StubRunnerRule` or `StubRunnerExtension` you can add a stub to download and then pass the port for the last downloaded stub. [source,java,indent=0] ---- diff --git a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionTest.java b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionTest.java index 1cf47ac939..50589ddb3f 100644 --- a/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionTest.java +++ b/spring-cloud-contract-stub-runner/src/test/java/org/springframework/cloud/contract/stubrunner/junit/StubRunnerJUnit5ExtensionTest.java @@ -41,6 +41,7 @@ class StubRunnerJUnit5ExtensionTest { System.clearProperty("stubrunner.classifier"); } + // tag::extension[] // Visible for Junit @RegisterExtension static StubRunnerExtension stubRunnerExtension = new StubRunnerExtension() @@ -60,6 +61,7 @@ class StubRunnerJUnit5ExtensionTest { assertThat(stubRunnerExtension .findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull(); } + // end::extension[] @Test void should_output_mappings_to_output_folder() {