Sync docs from 1.0.x to gh-pages
This commit is contained in:
@@ -764,6 +764,7 @@ $(addBlockSwitches);
|
||||
</li>
|
||||
<li><a href="#_jax_rs_support">JAX-RS support</a></li>
|
||||
<li><a href="#_async_support">Async support</a></li>
|
||||
<li><a href="#_working_with_context_paths">Working with Context Paths</a></li>
|
||||
<li><a href="#_messaging_top_level_elements">Messaging Top-Level Elements</a>
|
||||
<ul class="sectlevel4">
|
||||
<li><a href="#_output_triggered_by_a_method">Output triggered by a method</a></li>
|
||||
@@ -6783,6 +6784,107 @@ section a <code>async()</code> method. Example:</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_working_with_context_paths">Working with Context Paths</h4>
|
||||
<div class="paragraph">
|
||||
<p>Spring Cloud Contract supports context paths.</p>
|
||||
</div>
|
||||
<div class="admonitionblock important">
|
||||
<table>
|
||||
<tr>
|
||||
<td class="icon">
|
||||
<div class="title">Important</div>
|
||||
</td>
|
||||
<td class="content">
|
||||
The only thing that changes in order to fully support context paths is the switch
|
||||
on the <strong>PRODUCER</strong> side. The autogenerated tests need to be using the <strong>EXPLICIT</strong> mode.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The consumer side remains untouched, in order for the generated test to pass you have to switch the <strong>EXPLICIT</strong> mode.</p>
|
||||
</div>
|
||||
<div class="listingblock primary">
|
||||
<div class="title">Maven</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code class="language-xml" data-lang="xml"><plugin>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
|
||||
<version>${spring-cloud-contract.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<testMode>EXPLICIT</testMode>
|
||||
</configuration>
|
||||
</plugin></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="listingblock secondary">
|
||||
<div class="title">Gradle</div>
|
||||
<div class="content">
|
||||
<pre class="highlight"><code class="language-groovy" data-lang="groovy">contracts {
|
||||
testMode = 'EXPLICIT'
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>That way you’ll generate a test that <strong>DOES NOT</strong> use MockMvc. It means that you’re generating
|
||||
real requests and you need to setup your generated test’s base class to work on a real socket.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Let’s imagine the following contract:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlight"><code class="language-groovy" data-lang="groovy">org.springframework.cloud.contract.spec.Contract.make {
|
||||
request {
|
||||
method 'GET'
|
||||
url '/my-context-path/url'
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Here is an example of how to set up a base class and Rest Assured for everything to work correctly.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlight"><code class="language-groovy" data-lang="groovy">import com.jayway.restassured.RestAssured;
|
||||
import org.junit.Before;
|
||||
import org.springframework.boot.context.embedded.LocalServerPort;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest(classes = ContextPathTestingBaseClass.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
class ContextPathTestingBaseClass {
|
||||
|
||||
@LocalServerPort int port;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
RestAssured.baseURI = "http://localhost";
|
||||
RestAssured.port = this.port;
|
||||
}
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>That way all:</p>
|
||||
</div>
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p>all your requests in the autogenerated tests will be sent to the real endpoint with your context path included (e.g. <code>/my-context-path/url</code>)</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>your contracts reflect that you have a context path, thus your generated stubs will also
|
||||
have that information (e.g. in the stubs you’ll see that you have too call <code>/my-context-path/url</code>)</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_messaging_top_level_elements">Messaging Top-Level Elements</h4>
|
||||
<div class="paragraph">
|
||||
<p>The DSL for messaging looks a little bit different than the one that focuses on HTTP.</p>
|
||||
|
||||
Reference in New Issue
Block a user