From ae916379adee7d21d4e3950b2b9fd0011d990573 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Thu, 23 Feb 2017 16:52:10 +0000 Subject: [PATCH] Sync docs from 1.0.x to gh-pages --- .../checkstyle.rss | 34 +++---- .../plugins.html | 2 +- 1.0.x/spring-cloud-contract.html | 91 +++++++++++++++++++ 3 files changed, 109 insertions(+), 18 deletions(-) diff --git a/1.0.x/spring-cloud-contract-maven-plugin/checkstyle.rss b/1.0.x/spring-cloud-contract-maven-plugin/checkstyle.rss index 2baf3c0acf..7758168dff 100644 --- a/1.0.x/spring-cloud-contract-maven-plugin/checkstyle.rss +++ b/1.0.x/spring-cloud-contract-maven-plugin/checkstyle.rss @@ -46,7 +46,7 @@ under the License. - org/springframework/cloud/contract/maven/verifier/GenerateTestsMojo.java + org/springframework/cloud/contract/maven/verifier/MavenContractsDownloader.java 0 @@ -60,7 +60,7 @@ under the License. - org/springframework/cloud/contract/maven/verifier/MavenContractsDownloader.java + org/springframework/cloud/contract/maven/verifier/GenerateTestsMojo.java 0 @@ -113,6 +113,20 @@ under the License. 0 + + + + org/springframework/cloud/contract/maven/verifier/stubrunner/RemoteStubRunner.java + + + 0 + + + 0 + + + 0 + @@ -144,7 +158,7 @@ under the License. - org/springframework/cloud/contract/maven/verifier/stubrunner/RemoteStubRunner.java + org/springframework/cloud/contract/maven/verifier/stubrunner/LocalStubRunner.java 0 @@ -169,20 +183,6 @@ under the License. 0 - - - - org/springframework/cloud/contract/maven/verifier/stubrunner/LocalStubRunner.java - - - 0 - - - 0 - - - 0 - diff --git a/1.0.x/spring-cloud-contract-maven-plugin/plugins.html b/1.0.x/spring-cloud-contract-maven-plugin/plugins.html index 469d8b81a2..5e20f694c3 100644 --- a/1.0.x/spring-cloud-contract-maven-plugin/plugins.html +++ b/1.0.x/spring-cloud-contract-maven-plugin/plugins.html @@ -405,7 +405,7 @@ org.jacoco http://jacoco-maven-plugin -0.7.8 +0.7.9

Project Report Plugins

diff --git a/1.0.x/spring-cloud-contract.html b/1.0.x/spring-cloud-contract.html index 9506d0a837..4549b2108e 100644 --- a/1.0.x/spring-cloud-contract.html +++ b/1.0.x/spring-cloud-contract.html @@ -507,6 +507,7 @@ $(addBlockSwitches);
  • WireMock and Spring MVC Mocks
  • Generating Stubs using RestDocs
  • +
  • Generating Contracts using RestDocs
  • Spring Cloud Contract Verifier
    • Introduction @@ -1197,6 +1198,96 @@ number of different ways, including as described above using
      +

      Generating Contracts using RestDocs

      +
      +
      +

      Another thing that can be generated with Spring RestDocs is the Spring Cloud +Contract DSL file and documentation. If you combine that with Spring Cloud +WireMock then you’re getting both the contracts and stubs.

      +
      +
      +
  • + + + + +
    +
    Tip
    +
    +You might wonder why this functionality is in the WireMock module. +Come to think of it, it does make sense since it makes little sense to generate +only contracts and not generate the stubs. That’s why we suggest to do both. +
    +
    +
    +

    Let’s imagine the following test:

    +
    +
    +
    +
    		this.mockMvc.perform(post("/foo")
    +					.accept(MediaType.APPLICATION_PDF)
    +					.accept(MediaType.APPLICATION_JSON)
    +					.contentType(MediaType.APPLICATION_JSON)
    +					.content("{\"foo\": 23 }"))
    +				.andExpect(status().isOk())
    +				.andExpect(content().string("bar"))
    +				// first WireMock
    +				.andDo(WireMockRestDocs.verify()
    +						.jsonPath("$[?(@.foo >= 20)]")
    +						.contentType(MediaType.valueOf("application/json"))
    +						.stub("shouldGrantABeerIfOldEnough"))
    +				// then Contract DSL documentation
    +				.andDo(document("index", SpringCloudContractRestDocs.dslContract()));
    +
    +
    +
    +

    This will lead in the creation of the stub as presented in the previous +section, contract will get generated and a documentation file too.

    +
    +
    +

    The contract will be called index.groovy and look more like this.

    +
    +
    +
    +
    import org.springframework.cloud.contract.spec.Contract
    +
    +Contract.make {
    +    request {
    +        method 'POST'
    +        url 'http://localhost:8080/foo'
    +        body('''
    +            {"foo": 23 }
    +        ''')
    +        headers {
    +            header('''Accept''', '''application/json''')
    +            header('''Content-Type''', '''application/json''')
    +            header('''Host''', '''localhost:8080''')
    +            header('''Content-Length''', '''12''')
    +        }
    +    }
    +    response {
    +        status 200
    +        body('''
    +        bar
    +        ''')
    +        headers {
    +            header('''Content-Type''', '''application/json;charset=UTF-8''')
    +            header('''Content-Length''', '''3''')
    +        }
    +        testMatchers {
    +            jsonPath('$[?(@.foo >= 20)]', byType())
    +        }
    +    }
    +}
    +
    +
    +
    +

    the generated document (example for Asciidoc) will contain a formatted contract +(the location of this file would be index/dsl-contract.adoc).

    +
    + + +

    Spring Cloud Contract Verifier