Files
spring-cloud-contract/reference/html/migrations.html
2019-07-31 00:23:56 +00:00

345 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 1.5.7.1">
<title>Migrations</title>
<link rel="stylesheet" href="css/spring.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.hidden {
display: none;
}
.switch {
border-width: 1px 1px 0 1px;
border-style: solid;
border-color: #7a2518;
display: inline-block;
}
.switch--item {
padding: 10px;
background-color: #ffffff;
color: #7a2518;
display: inline-block;
cursor: pointer;
}
.switch--item:not(:first-child) {
border-width: 0 0 0 1px;
border-style: solid;
border-color: #7a2518;
}
.switch--item.selected {
background-color: #7a2519;
color: #ffffff;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js"></script>
<script type="text/javascript">
function addBlockSwitches() {
$('.primary').each(function() {
primary = $(this);
createSwitchItem(primary, createBlockSwitch(primary)).item.addClass("selected");
primary.children('.title').remove();
});
$('.secondary').each(function(idx, node) {
secondary = $(node);
primary = findPrimary(secondary);
switchItem = createSwitchItem(secondary, primary.children('.switch'));
switchItem.content.addClass('hidden');
findPrimary(secondary).append(switchItem.content);
secondary.remove();
});
}
function createBlockSwitch(primary) {
blockSwitch = $('<div class="switch"></div>');
primary.prepend(blockSwitch);
return blockSwitch;
}
function findPrimary(secondary) {
candidate = secondary.prev();
while (!candidate.is('.primary')) {
candidate = candidate.prev();
}
return candidate;
}
function createSwitchItem(block, blockSwitch) {
blockName = block.children('.title').text();
content = block.children('.content').first().append(block.next('.colist'));
item = $('<div class="switch--item">' + blockName + '</div>');
item.on('click', '', content, function(e) {
$(this).addClass('selected');
$(this).siblings().removeClass('selected');
e.data.siblings('.content').addClass('hidden');
e.data.removeClass('hidden');
});
blockSwitch.append(item);
return {'item': item, 'content': content};
}
$(addBlockSwitches);
</script>
</head>
<body class="book toc2 toc-left">
<div id="header">
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#_migrations">Migrations</a>
<ul class="sectlevel2">
<li><a href="#cloud-verifier-1.0-1.1">1.0.x &#8594; 1.1.x</a></li>
<li><a href="#cloud-verifier-1.1-1.2">1.1.x &#8594; 1.2.x</a></li>
<li><a href="#cloud-verifier-1.2-2.0">1.2.x &#8594; 2.0.x</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="_migrations"><a class="link" href="#_migrations">Migrations</a></h2>
<div class="sectionbody">
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
For up to date migration guides please visit
the project&#8217;s <a href="https://github.com/spring-cloud/spring-cloud-contract/wiki/">wiki page</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>This section covers migrating from one version of Spring Cloud Contract Verifier to the
next version. It covers the following versions upgrade paths:</p>
</div>
<div class="sect2">
<h3 id="cloud-verifier-1.0-1.1"><a class="link" href="#cloud-verifier-1.0-1.1">1.0.x &#8594; 1.1.x</a></h3>
<div class="paragraph">
<p>This section covers upgrading from version 1.0 to version 1.1.</p>
</div>
<div class="sect3">
<h4 id="_new_structure_of_generated_stubs"><a class="link" href="#_new_structure_of_generated_stubs">New structure of generated stubs</a></h4>
<div class="paragraph">
<p>In <code>1.1.x</code> we have introduced a change to the structure of generated stubs. If you have
been using the <code>@AutoConfigureWireMock</code> notation to use the stubs from the classpath,
it no longer works. The following example shows how the <code>@AutoConfigureWireMock</code> notation
used to work:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@AutoConfigureWireMock(stubs = "classpath:/customer-stubs/mappings", port = 8084)</code></pre>
</div>
</div>
<div class="paragraph">
<p>You must either change the location of the stubs to:
<code>classpath:&#8230;&#8203;/META-INF/groupId/artifactId/version/mappings</code> or use the new
classpath-based <code>@AutoConfigureStubRunner</code>, as shown in the following example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@AutoConfigureWireMock(stubs = "classpath:customer-stubs/META-INF/travel.components/customer-contract/1.0.2-SNAPSHOT/mappings/", port = 8084)</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you do not want to use <code>@AutoConfigureStubRunner</code> and you want to remain with the old
structure, set your plugin tasks accordingly. The following example would work for the
structure presented in the previous snippet.</p>
</div>
<div class="listingblock primary">
<div class="title">Maven</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml">&lt;!-- start of pom.xml --&gt;
&lt;properties&gt;
&lt;!-- we don't want the verifier to do a jar for us --&gt;
&lt;spring.cloud.contract.verifier.skip&gt;true&lt;/spring.cloud.contract.verifier.skip&gt;
&lt;/properties&gt;
&lt;!-- ... --&gt;
&lt;!-- You need to set up the assembly plugin --&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;stub&lt;/id&gt;
&lt;phase&gt;prepare-package&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;single&lt;/goal&gt;
&lt;/goals&gt;
&lt;inherited&gt;false&lt;/inherited&gt;
&lt;configuration&gt;
&lt;attach&gt;true&lt;/attach&gt;
&lt;descriptor&gt;${basedir}/src/assembly/stub.xml&lt;/descriptor&gt;
&lt;/configuration&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;!-- end of pom.xml --&gt;
&lt;!-- start of stub.xml--&gt;
&lt;assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 https://maven.apache.org/xsd/assembly-1.1.3.xsd"&gt;
&lt;id&gt;stubs&lt;/id&gt;
&lt;formats&gt;
&lt;format&gt;jar&lt;/format&gt;
&lt;/formats&gt;
&lt;includeBaseDirectory&gt;false&lt;/includeBaseDirectory&gt;
&lt;fileSets&gt;
&lt;fileSet&gt;
&lt;directory&gt;${project.build.directory}/snippets/stubs&lt;/directory&gt;
&lt;outputDirectory&gt;customer-stubs/mappings&lt;/outputDirectory&gt;
&lt;includes&gt;
&lt;include&gt;**/*&lt;/include&gt;
&lt;/includes&gt;
&lt;/fileSet&gt;
&lt;fileSet&gt;
&lt;directory&gt;${basedir}/src/test/resources/contracts&lt;/directory&gt;
&lt;outputDirectory&gt;customer-stubs/contracts&lt;/outputDirectory&gt;
&lt;includes&gt;
&lt;include&gt;**/*.groovy&lt;/include&gt;
&lt;/includes&gt;
&lt;/fileSet&gt;
&lt;/fileSets&gt;
&lt;/assembly&gt;
&lt;!-- end of stub.xml--&gt;</code></pre>
</div>
</div>
<div class="listingblock secondary">
<div class="title">Gradle</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">task copyStubs(type: Copy, dependsOn: 'generateWireMockClientStubs') {
// Preserve directory structure from 1.0.X of spring-cloud-contract
from "${project.buildDir}/resources/main/customer-stubs/META-INF/${project.group}/${project.name}/${project.version}"
into "${project.buildDir}/resources/main/customer-stubs"
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="cloud-verifier-1.1-1.2"><a class="link" href="#cloud-verifier-1.1-1.2">1.1.x &#8594; 1.2.x</a></h3>
<div class="paragraph">
<p>This section covers upgrading from version 1.1 to version 1.2.</p>
</div>
<div class="sect3">
<h4 id="_custom_httpserverstub"><a class="link" href="#_custom_httpserverstub">Custom <code>HttpServerStub</code></a></h4>
<div class="paragraph">
<p><code>HttpServerStub</code> includes a method that was not in version 1.1. The method is
<code>String registeredMappings()</code> If you have classes that implement <code>HttpServerStub</code>, you
now have to implement the <code>registeredMappings()</code> method. It should return a <code>String</code>
representing all mappings available in a single <code>HttpServerStub</code>.</p>
</div>
<div class="paragraph">
<p>See <a href="https://github.com/spring-cloud/spring-cloud-contract/issues/355">issue 355</a> for more
detail.</p>
</div>
</div>
<div class="sect3">
<h4 id="_new_packages_for_generated_tests"><a class="link" href="#_new_packages_for_generated_tests">New packages for generated tests</a></h4>
<div class="paragraph">
<p>The flow for setting the generated tests package name will look like this:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Set <code>basePackageForTests</code></p>
</li>
<li>
<p>If <code>basePackageForTests</code> was not set, pick the package from <code>baseClassForTests</code></p>
</li>
<li>
<p>If <code>baseClassForTests</code> was not set, pick <code>packageWithBaseClasses</code></p>
</li>
<li>
<p>If nothing got set, pick the default value:
<code>org.springframework.cloud.contract.verifier.tests</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>See <a href="https://github.com/spring-cloud/spring-cloud-contract/issues/260">issue 260</a> for more
detail.</p>
</div>
</div>
<div class="sect3">
<h4 id="_new_methods_in_templateprocessor"><a class="link" href="#_new_methods_in_templateprocessor">New Methods in TemplateProcessor</a></h4>
<div class="paragraph">
<p>In order to add support for <code>fromRequest.path</code>, the following methods had to be added to the
<code>TemplateProcessor</code> interface:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>path()</code></p>
</li>
<li>
<p><code>path(int index)</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>See <a href="https://github.com/spring-cloud/spring-cloud-contract/issues/388">issue 388</a> for more
detail.</p>
</div>
</div>
<div class="sect3">
<h4 id="_restassured_3_0"><a class="link" href="#_restassured_3_0">RestAssured 3.0</a></h4>
<div class="paragraph">
<p>Rest Assured, used in the generated test classes, got bumped to <code>3.0</code>. If
you manually set versions of Spring Cloud Contract and the release train
you might see the following exception:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project some-project: Compilation failure: Compilation failure:
[ERROR] /some/path/SomeClass.java:[4,39] package com.jayway.restassured.response does not exist</code></pre>
</div>
</div>
<div class="paragraph">
<p>This exception will occur due to the fact that the tests got generated with
an old version of plugin and at test execution time you have an incompatible
version of the release train (and vice versa).</p>
</div>
<div class="paragraph">
<p>Done via <a href="https://github.com/spring-cloud/spring-cloud-contract/issues/267">issue 267</a></p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="cloud-verifier-1.2-2.0"><a class="link" href="#cloud-verifier-1.2-2.0">1.2.x &#8594; 2.0.x</a></h3>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/tocbot/tocbot.min.js"></script>
<script type="text/javascript" src="js/toc.js"></script>
<link rel="stylesheet" href="js/highlight/styles/atom-one-dark-reasonable.min.css">
<script src="js/highlight/highlight.min.js"></script>
<script>hljs.initHighlighting()</script>
</body>
</html>