diff --git a/multi/multi__contract_dsl.html b/multi/multi__contract_dsl.html index 0aa111e8e8..54c806cd36 100644 --- a/multi/multi__contract_dsl.html +++ b/multi/multi__contract_dsl.html @@ -1619,29 +1619,12 @@ to work with Web Flux.

Maven. 

contracts {
 		testMode = 'EXPLICIT'
 }

-

The following example shows how to set up a base class and Rest Assured for Web Flux:

@RunWith(SpringRunner.class)
-@SpringBootTest(classes = BeerRestBase.Config.class,
-		webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
-		properties = "server.port=0")
-public abstract class BeerRestBase {
+

The following example shows how to set up a base class and Rest Assured for Web Flux:

Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_webflux/src/test/java/com/example/BeerRestBase.java[tags=annotations,indent=0]
 
     // your tests go here
 
     // in this config class you define all controllers and mocked services
-@Configuration
-@EnableAutoConfiguration
-static class Config {
-
-	@Bean
-	PersonCheckingService personCheckingService()  {
-		return personToCheck -> personToCheck.age >= 20;
-	}
-
-	@Bean
-	ProducerController producerController() {
-		return new ProducerController(personCheckingService());
-	}
-}
+Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_webflux/src/test/java/com/example/BeerRestBase.java[tags=config,indent=0]
 
 }

8.10 Messaging Top-Level Elements

The DSL for messaging looks a little bit different than the one that focuses on HTTP. The following sections explain the differences:

8.10.1 Output Triggered by a Method

The output message can be triggered by calling a method (such as a Scheduler when a was diff --git a/multi/multi__customization.html b/multi/multi__customization.html index 3522c8d4ec..d2133c646e 100644 --- a/multi/multi__customization.html +++ b/multi/multi__customization.html @@ -3,215 +3,16 @@ 9. Customization

9. Customization

[Important]Important

This section is valid only for Groovy DSL

You can customize the Spring Cloud Contract Verifier by extending the DSL, as shown in the remainder of this section.

9.1 Extending the DSL

You can provide your own functions to the DSL. The key requirement for this feature is to maintain the static compatibility. Later in this document, you can see examples of:

  • Creating a JAR with reusable classes.
  • Referencing of these classes in the DSLs.

You can find the full example -here.

9.1.1 Common JAR

The following examples show three classes that can be reused in the DSLs.

PatternUtils contains functions used by both the consumer and the producer.

package com.example;
-
-import java.util.regex.Pattern;
-
-/**
- * If you want to use {@link Pattern} directly in your tests
- * then you can create a class resembling this one. It can
- * contain all the {@link Pattern} you want to use in the DSL.
- *
- * <pre>
- * {@code
- * request {
- *     body(
- *         [ age: $(c(PatternUtils.oldEnough()))]
- *     )
- * }
- * </pre>
- *
- * Notice that we're using both {@code $()} for dynamic values
- * and {@code c()} for the consumer side.
- *
- * @author Marcin Grzejszczak
- */
-//tag::impl[]
-public class PatternUtils {
-
-	public static String tooYoung() {
-		//remove::start[]
-		return "[0-1][0-9]";
-		//remove::end[return]
-	}
-
-	public static Pattern oldEnough() {
-		//remove::start[]
-		return Pattern.compile("[2-9][0-9]");
-		//remove::end[return]
-	}
-
-	/**
-	 * Makes little sense but it's just an example ;)
-	 */
-	public static Pattern ok() {
-		//remove::start[]
-		return Pattern.compile("OK");
-		//remove::end[return]
-	}
-}
-//end::impl[]

ConsumerUtils contains functions used by the consumer.

package com.example;
-
-import org.springframework.cloud.contract.spec.internal.ClientDslProperty;
-
-/**
- * DSL Properties passed to the DSL from the consumer's perspective.
- * That means that on the input side {@code Request} for HTTP
- * or {@code Input} for messaging you can have a regular expression.
- * On the {@code Response} for HTTP or {@code Output} for messaging
- * you have to have a concrete value.
- *
- * @author Marcin Grzejszczak
- */
-//tag::impl[]
-public class ConsumerUtils {
-	/**
-	 * Consumer side property. By using the {@link ClientDslProperty}
-	 * you can omit most of boilerplate code from the perspective
-	 * of dynamic values. Example
-	 *
-	 * <pre>
-	 * {@code
-	 * request {
-	 *     body(
-	 *         [ age: $(ConsumerUtils.oldEnough())]
-	 *     )
-	 * }
-	 * </pre>
-	 *
-	 * That way it's in the implementation that we decide what value we will pass to the consumer
-	 * and which one to the producer.
-	 *
-	 * @author Marcin Grzejszczak
-	 */
-	public static ClientDslProperty oldEnough() {
-		//remove::start[]
-		// this example is not the best one and
-		// theoretically you could just pass the regex instead of `ServerDslProperty` but
-		// it's just to show some new tricks :)
-		return new ClientDslProperty(PatternUtils.oldEnough(), 40);
-		//remove::end[return]
-	}
-
-}
-//end::impl[]

ProducerUtils contains functions used by the producer.

package com.example;
-
-import org.springframework.cloud.contract.spec.internal.ServerDslProperty;
-
-/**
- * DSL Properties passed to the DSL from the producer's perspective.
- * That means that on the input side {@code Request} for HTTP
- * or {@code Input} for messaging you have to have a concrete value.
- * On the {@code Response} for HTTP or {@code Output} for messaging
- * you can have a regular expression.
- *
- * @author Marcin Grzejszczak
- */
-//tag::impl[]
-public class ProducerUtils {
-
-	/**
-	 * Producer side property. By using the {@link ProducerUtils}
-	 * you can omit most of boilerplate code from the perspective
-	 * of dynamic values. Example
-	 *
-	 * <pre>
-	 * {@code
-	 * response {
-	 *     body(
-	 *         [ status: $(ProducerUtils.ok())]
-	 *     )
-	 * }
-	 * </pre>
-	 *
-	 * That way it's in the implementation that we decide what value we will pass to the consumer
-	 * and which one to the producer.
-	 */
-	public static ServerDslProperty ok() {
-		// this example is not the best one and
-		// theoretically you could just pass the regex instead of `ServerDslProperty` but
-		// it's just to show some new tricks :)
-		return new ServerDslProperty( PatternUtils.ok(), "OK");
-	}
-}
-//end::impl[]

9.1.2 Adding the Dependency to the Project

In order for the plugins and IDE to be able to reference the common JAR classes, you need +here.

9.1.1 Common JAR

The following examples show three classes that can be reused in the DSLs.

PatternUtils contains functions used by both the consumer and the producer.

Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/common/src/main/java/com/example/PatternUtils.java[]

ConsumerUtils contains functions used by the consumer.

Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/common/src/main/java/com/example/ConsumerUtils.java[]

ProducerUtils contains functions used by the producer.

Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/common/src/main/java/com/example/ProducerUtils.java[]

9.1.2 Adding the Dependency to the Project

In order for the plugins and IDE to be able to reference the common JAR classes, you need to pass the dependency to your project.

9.1.3 Test the Dependency in the Project’s Dependencies

First, add the common jar dependency as a test dependency. Because your contracts files are available on the test resources path, the common jar classes automatically become visible in your Groovy files. The following examples show how to test the dependency:

Maven.  -

<dependency>
-	<groupId>com.example</groupId>
-	<artifactId>beer-common</artifactId>
-	<version>${project.version}</version>
-	<scope>test</scope>
-</dependency>

+

Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/pom.xml[tags=test_dep,indent=0]

Gradle.  -

testCompile("com.example:beer-common:0.0.1-SNAPSHOT")

+

Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/build.gradle[tags=test_dep,indent=0]

9.1.4 Test a Dependency in the Plugin’s Dependencies

Now, you must add the dependency for the plugin to reuse at runtime, as shown in the following example:

Maven.  -

<plugin>
-	<groupId>org.springframework.cloud</groupId>
-	<artifactId>spring-cloud-contract-maven-plugin</artifactId>
-	<version>${spring-cloud-contract.version}</version>
-	<extensions>true</extensions>
-	<configuration>
-		<packageWithBaseClasses>com.example</packageWithBaseClasses>
-		<baseClassMappings>
-			<baseClassMapping>
-				<contractPackageRegex>.*intoxication.*</contractPackageRegex>
-				<baseClassFQN>com.example.intoxication.BeerIntoxicationBase</baseClassFQN>
-			</baseClassMapping>
-		</baseClassMappings>
-	</configuration>
-	<dependencies>
-		<dependency>
-			<groupId>com.example</groupId>
-			<artifactId>beer-common</artifactId>
-			<version>${project.version}</version>
-			<scope>compile</scope>
-		</dependency>
-	</dependencies>
-</plugin>

+

Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/pom.xml[tags=test_dep_in_plugin,indent=0]

Gradle.  -

classpath "com.example:beer-common:0.0.1-SNAPSHOT"

-

9.1.5 Referencing classes in DSLs

You can now reference your classes in your DSL, as shown in the following example:

package contracts.beer.rest
-
-import com.example.ConsumerUtils
-import com.example.ProducerUtils
-import org.springframework.cloud.contract.spec.Contract
-
-Contract.make {
-	description("""
-Represents a successful scenario of getting a beer
-
-```
-given:
-	client is old enough
-when:
-	he applies for a beer
-then:
-	we'll grant him the beer
-```
-
-""")
-	request {
-		method 'POST'
-		url '/check'
-		body(
-				age: $(ConsumerUtils.oldEnough())
-		)
-		headers {
-			contentType(applicationJson())
-		}
-	}
-	response {
-		status 200
-		body("""
-			{
-				"status": "${value(ProducerUtils.ok())}"
-			}
-			""")
-		headers {
-			contentType(applicationJson())
-		}
-	}
-}
\ No newline at end of file +

Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/build.gradle[tags=test_dep_in_plugin,indent=0]

+

9.1.5 Referencing classes in DSLs

You can now reference your classes in your DSL, as shown in the following example:

Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/src/test/resources/contracts/beer/rest/shouldGrantABeerIfOldEnough.groovy[indent=0]
\ No newline at end of file diff --git a/multi/multi__spring_cloud_contract_faq.html b/multi/multi__spring_cloud_contract_faq.html index 806a1eb2e2..c59cccfb0d 100644 --- a/multi/multi__spring_cloud_contract_faq.html +++ b/multi/multi__spring_cloud_contract_faq.html @@ -100,194 +100,14 @@ consumer will you break with your local changes.

As you can see the under the slash-delimited groupid / artifact id folder (com/example/server) you have expectations of the 3 consumers (client1, client2 and client3). Expectations are the standard Groovy DSL contract files as described throughout this documentation. This repository has to produce a JAR file that maps -one to one to the contents of the repo.

Example of a pom.xml inside the server folder.

<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-
-	<groupId>com.example</groupId>
-	<artifactId>server</artifactId>
-	<version>0.0.1-SNAPSHOT</version>
-
-	<name>Server Stubs</name>
-	<description>POM used to install locally stubs for consumer side</description>
-
-	<parent>
-		<groupId>org.springframework.boot</groupId>
-		<artifactId>spring-boot-starter-parent</artifactId>
-		<version>2.0.3.RELEASE</version>
-		<relativePath />
-	</parent>
-
-	<properties>
-		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-		<java.version>1.8</java.version>
-		<spring-cloud-contract.version>2.1.0.BUILD-SNAPSHOT</spring-cloud-contract.version>
-		<spring-cloud-release.version>Finchley.BUILD-SNAPSHOT</spring-cloud-release.version>
-		<excludeBuildFolders>true</excludeBuildFolders>
-	</properties>
-
-	<dependencyManagement>
-		<dependencies>
-			<dependency>
-				<groupId>org.springframework.cloud</groupId>
-				<artifactId>spring-cloud-dependencies</artifactId>
-				<version>${spring-cloud-release.version}</version>
-				<type>pom</type>
-				<scope>import</scope>
-			</dependency>
-		</dependencies>
-	</dependencyManagement>
-
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.springframework.cloud</groupId>
-				<artifactId>spring-cloud-contract-maven-plugin</artifactId>
-				<version>${spring-cloud-contract.version}</version>
-				<extensions>true</extensions>
-				<configuration>
-					<!-- By default it would search under src/test/resources/ -->
-					<contractsDirectory>${project.basedir}</contractsDirectory>
-				</configuration>
-			</plugin>
-		</plugins>
-	</build>
-
-	<repositories>
-		<repository>
-			<id>spring-snapshots</id>
-			<name>Spring Snapshots</name>
-			<url>https://repo.spring.io/snapshot</url>
-			<snapshots>
-				<enabled>true</enabled>
-			</snapshots>
-		</repository>
-		<repository>
-			<id>spring-milestones</id>
-			<name>Spring Milestones</name>
-			<url>https://repo.spring.io/milestone</url>
-			<snapshots>
-				<enabled>false</enabled>
-			</snapshots>
-		</repository>
-		<repository>
-			<id>spring-releases</id>
-			<name>Spring Releases</name>
-			<url>https://repo.spring.io/release</url>
-			<snapshots>
-				<enabled>false</enabled>
-			</snapshots>
-		</repository>
-	</repositories>
-	<pluginRepositories>
-		<pluginRepository>
-			<id>spring-snapshots</id>
-			<name>Spring Snapshots</name>
-			<url>https://repo.spring.io/snapshot</url>
-			<snapshots>
-				<enabled>true</enabled>
-			</snapshots>
-		</pluginRepository>
-		<pluginRepository>
-			<id>spring-milestones</id>
-			<name>Spring Milestones</name>
-			<url>https://repo.spring.io/milestone</url>
-			<snapshots>
-				<enabled>false</enabled>
-			</snapshots>
-		</pluginRepository>
-		<pluginRepository>
-			<id>spring-releases</id>
-			<name>Spring Releases</name>
-			<url>https://repo.spring.io/release</url>
-			<snapshots>
-				<enabled>false</enabled>
-			</snapshots>
-		</pluginRepository>
-	</pluginRepositories>
-
-</project>

As you can see there are no dependencies other than the Spring Cloud Contract Maven Plugin. +one to one to the contents of the repo.

Example of a pom.xml inside the server folder.

Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/contracts/com/example/server/pom.xml[indent=0]

As you can see there are no dependencies other than the Spring Cloud Contract Maven Plugin. Those poms are necessary for the consumer side to run mvn clean install -DskipTests to locally install - stubs of the producer project.

The pom.xml in the root folder can look like this:

<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-
-	<groupId>com.example.standalone</groupId>
-	<artifactId>contracts</artifactId>
-	<version>0.0.1-SNAPSHOT</version>
-
-	<name>Contracts</name>
-	<description>Contains all the Spring Cloud Contracts, well, contracts. JAR used by the producers to generate tests and stubs</description>
-
-	<properties>
-		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-	</properties>
-
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-assembly-plugin</artifactId>
-				<executions>
-					<execution>
-						<id>contracts</id>
-						<phase>prepare-package</phase>
-						<goals>
-							<goal>single</goal>
-						</goals>
-						<configuration>
-							<attach>true</attach>
-							<descriptor>${basedir}/src/assembly/contracts.xml</descriptor>
-							<!-- If you want an explicit classifier remove the following line -->
-							<appendAssemblyId>false</appendAssemblyId>
-						</configuration>
-					</execution>
-				</executions>
-			</plugin>
-		</plugins>
-	</build>
-
-</project>

It’s using the assembly plugin in order to build the JAR with all the contracts. Example of such setup is here:

<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 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
-	<id>project</id>
-	<formats>
-		<format>jar</format>
-	</formats>
-	<includeBaseDirectory>false</includeBaseDirectory>
-	<fileSets>
-		<fileSet>
-			<directory>${project.basedir}</directory>
-			<outputDirectory>/</outputDirectory>
-			<useDefaultExcludes>true</useDefaultExcludes>
-			<excludes>
-				<exclude>**/${project.build.directory}/**</exclude>
-				<exclude>mvnw</exclude>
-				<exclude>mvnw.cmd</exclude>
-				<exclude>.mvn/**</exclude>
-				<exclude>src/**</exclude>
-			</excludes>
-		</fileSet>
-	</fileSets>
-</assembly>

3.5.2 Workflow

The workflow would look similar to the one presented in the Step by step guide to CDC. The only difference + stubs of the producer project.

The pom.xml in the root folder can look like this:

Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/contracts/pom.xml[indent=0]

It’s using the assembly plugin in order to build the JAR with all the contracts. Example of such setup is here:

Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/contracts/src/assembly/contracts.xml[indent=0]

3.5.2 Workflow

The workflow would look similar to the one presented in the Step by step guide to CDC. The only difference is that the producer doesn’t own the contracts anymore. So the consumer and the producer have to work on common contracts in a common repository.

3.5.3 Consumer

When the consumer wants to work on the contracts offline, instead of cloning the producer code, the consumer team clones the common repository, goes to the required producer’s folder (e.g. com/example/server) and runs mvn clean install -DskipTests to install locally the stubs converted from the contracts.

[Tip]Tip

You need to have Maven installed locally

3.5.4 Producer

As a producer it’s enough to alter the Spring Cloud Contract Verifier to provide the URL and the dependency -of the JAR containing the contracts:

<plugin>
-	<groupId>org.springframework.cloud</groupId>
-	<artifactId>spring-cloud-contract-maven-plugin</artifactId>
-	<configuration>
-		<contractsMode>REMOTE</contractsMode>
-		<contractsRepositoryUrl>http://link/to/your/nexus/or/artifactory/or/sth</contractsRepositoryUrl>
-		<contractDependency>
-			<groupId>com.example.standalone</groupId>
-			<artifactId>contracts</artifactId>
-		</contractDependency>
-	</configuration>
-</plugin>

With this setup the JAR with groupid com.example.standalone and artifactid contracts will be downloaded +of the JAR containing the contracts:

Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/basic-remote-contracts/pom-with-repo.xml[tags=remote_config,indent=0]

With this setup the JAR with groupid com.example.standalone and artifactid contracts will be downloaded from http://link/to/your/nexus/or/artifactory/or/sth. It will be then unpacked in a local temporary folder and contracts present under the com/example/server will be picked as the ones used to generate the tests and the stubs. Due to this convention the producer team will know which consumer teams will be broken diff --git a/multi/multi__spring_cloud_contract_stub_runner.html b/multi/multi__spring_cloud_contract_stub_runner.html index c8f3a9b83e..4b8e8a30aa 100644 --- a/multi/multi__spring_cloud_contract_stub_runner.html +++ b/multi/multi__spring_cloud_contract_stub_runner.html @@ -71,73 +71,13 @@ versions, which are automatically uploaded after every successful build:

[Tip]Tip

For both Maven and Gradle, the setup comes ready to work. However, you can customize it if you want to.

Maven. 

<!-- First disable the default jar setup in the properties section -->
-<!-- we don't want the verifier to do a jar for us -->
-<spring.cloud.contract.verifier.skip>true</spring.cloud.contract.verifier.skip>
+Unresolved directive in verifier_stubrunner.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_with_restdocs/pom.xml[tags=skip_jar,indent=0]
 
 <!-- Next add the assembly plugin to your build -->
-<!-- we want the assembly plugin to generate the JAR -->
-<plugin>
-	<groupId>org.apache.maven.plugins</groupId>
-	<artifactId>maven-assembly-plugin</artifactId>
-	<executions>
-		<execution>
-			<id>stub</id>
-			<phase>prepare-package</phase>
-			<goals>
-				<goal>single</goal>
-			</goals>
-			<inherited>false</inherited>
-			<configuration>
-				<attach>true</attach>
-				<descriptors>
-					${basedir}/src/assembly/stub.xml
-				</descriptors>
-			</configuration>
-		</execution>
-	</executions>
-</plugin>
+Unresolved directive in verifier_stubrunner.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_with_restdocs/pom.xml[tags=assembly,indent=0]
 
 <!-- Finally setup your assembly. Below you can find the contents of src/main/assembly/stub.xml -->
-<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 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
-	<id>stubs</id>
-	<formats>
-		<format>jar</format>
-	</formats>
-	<includeBaseDirectory>false</includeBaseDirectory>
-	<fileSets>
-		<fileSet>
-			<directory>src/main/java</directory>
-			<outputDirectory>/</outputDirectory>
-			<includes>
-				<include>**com/example/model/*.*</include>
-			</includes>
-		</fileSet>
-		<fileSet>
-			<directory>${project.build.directory}/classes</directory>
-			<outputDirectory>/</outputDirectory>
-			<includes>
-				<include>**com/example/model/*.*</include>
-			</includes>
-		</fileSet>
-		<fileSet>
-			<directory>${project.build.directory}/snippets/stubs</directory>
-			<outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings</outputDirectory>
-			<includes>
-				<include>**/*</include>
-			</includes>
-		</fileSet>
-		<fileSet>
-			<directory>${basedir}/src/test/resources/contracts</directory>
-			<outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/contracts</outputDirectory>
-			<includes>
-				<include>**/*.groovy</include>
-			</includes>
-		</fileSet>
-	</fileSets>
-</assembly>

+Unresolved directive in verifier_stubrunner.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_with_restdocs/src/assembly/stub.xml[indent=0]

Gradle. 

ext {
 	contractsDir = file("mappings")
diff --git a/multi/multi__spring_cloud_contract_verifier_introduction.html b/multi/multi__spring_cloud_contract_verifier_introduction.html
index f5cc339660..485d088b1a 100644
--- a/multi/multi__spring_cloud_contract_verifier_introduction.html
+++ b/multi/multi__spring_cloud_contract_verifier_introduction.html
@@ -61,9 +61,7 @@ by running the following commands:

$ 
[Tip]Tip

The tests are being skipped because the Producer-side contract implementation is not in place yet, so the automatically-generated contract tests fail.

  • By getting already-existing producer service stubs from a remote repository. To do so, pass the stub artifact IDs and artifact repository URL as Spring Cloud Contract -Stub Runner properties, as shown in the following example:

    stubrunner:
    -  ids: 'com.example:http-server-dsl:+:stubs:8080'
    -  repositoryRoot: http://repo.spring.io/libs-snapshot
  • Now you can annotate your test class with @AutoConfigureStubRunner. In the annotation, +Stub Runner properties, as shown in the following example:

    Unresolved directive in verifier_introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/dsl/http-client/src/test/resources/application-test-repo.yaml[]

    Now you can annotate your test class with @AutoConfigureStubRunner. In the annotation, provide the group-id and artifact-id values for Spring Cloud Contract Stub Runner to run the collaborators' stubs for you, as shown in the following example:

    @RunWith(SpringRunner.class)
     @SpringBootTest(webEnvironment=WebEnvironment.NONE)
    @@ -222,9 +220,7 @@ stubs by running the following commands:

    $ 
    [Note]Note

    The tests are skipped because the Producer-side contract implementation is not yet in place, so the automatically-generated contract tests fail.

  • Getting already existing producer service stubs from a remote repository. To do so, pass the stub artifact IDs and artifact repository URl as Spring Cloud Contract Stub -Runner properties, as shown in the following example:

    stubrunner:
    -  ids: 'com.example:http-server-dsl:+:stubs:8080'
    -  repositoryRoot: http://repo.spring.io/libs-snapshot
  • Now you can annotate your test class with @AutoConfigureStubRunner. In the annotation, +Runner properties, as shown in the following example:

    Unresolved directive in verifier_introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/dsl/http-client/src/test/resources/application-test-repo.yaml[]

    Now you can annotate your test class with @AutoConfigureStubRunner. In the annotation, provide the group-id and artifact-id for Spring Cloud Contract Stub Runner to run the collaborators' stubs for you, as shown in the following example:

    @RunWith(SpringRunner.class)
     @SpringBootTest(webEnvironment=WebEnvironment.NONE)
    @@ -766,9 +762,7 @@ $ git merge --no-ff contract-change-pr

    Work where the repository with your stubs is located. At this moment the stubs of the server side are automatically downloaded from Nexus/Artifactory. You can set the value of stubsMode to REMOTE. The following code shows an example of -achieving the same thing by changing the properties.

    stubrunner:
    -  ids: 'com.example:http-server-dsl:+:stubs:8080'
    -  repositoryRoot: http://repo.spring.io/libs-snapshot

    That’s it!

    2.6 Dependencies

    The best way to add dependencies is to use the proper starter dependency.

    For stub-runner, use spring-cloud-starter-stub-runner. When you use a plugin, add +achieving the same thing by changing the properties.

    Unresolved directive in verifier_introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/dsl/http-client/src/test/resources/application-test-repo.yaml[]

    That’s it!

    2.6 Dependencies

    The best way to add dependencies is to use the proper starter dependency.

    For stub-runner, use spring-cloud-starter-stub-runner. When you use a plugin, add spring-cloud-starter-contract-verifier.

    2.7 Additional Links

    Here are some resources related to Spring Cloud Contract Verifier and Stub Runner. Note that some may be outdated, because the Spring Cloud Contract Verifier project is under constant development.

    2.7.1 Spring Cloud Contract video

    You can check out the video from the Warsaw JUG about Spring Cloud Contract:

    2.8 Samples

    You can find some samples at diff --git a/single/spring-cloud-contract.html b/single/spring-cloud-contract.html index 8d0c7a9820..4b976b27d4 100644 --- a/single/spring-cloud-contract.html +++ b/single/spring-cloud-contract.html @@ -66,9 +66,7 @@ by running the following commands:

    $ 
    [Tip]Tip

    The tests are being skipped because the Producer-side contract implementation is not in place yet, so the automatically-generated contract tests fail.

  • By getting already-existing producer service stubs from a remote repository. To do so, pass the stub artifact IDs and artifact repository URL as Spring Cloud Contract -Stub Runner properties, as shown in the following example:

    stubrunner:
    -  ids: 'com.example:http-server-dsl:+:stubs:8080'
    -  repositoryRoot: http://repo.spring.io/libs-snapshot
  • Now you can annotate your test class with @AutoConfigureStubRunner. In the annotation, +Stub Runner properties, as shown in the following example:

    Unresolved directive in verifier_introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/dsl/http-client/src/test/resources/application-test-repo.yaml[]

    Now you can annotate your test class with @AutoConfigureStubRunner. In the annotation, provide the group-id and artifact-id values for Spring Cloud Contract Stub Runner to run the collaborators' stubs for you, as shown in the following example:

    @RunWith(SpringRunner.class)
     @SpringBootTest(webEnvironment=WebEnvironment.NONE)
    @@ -227,9 +225,7 @@ stubs by running the following commands:

    $ 
    [Note]Note

    The tests are skipped because the Producer-side contract implementation is not yet in place, so the automatically-generated contract tests fail.

  • Getting already existing producer service stubs from a remote repository. To do so, pass the stub artifact IDs and artifact repository URl as Spring Cloud Contract Stub -Runner properties, as shown in the following example:

    stubrunner:
    -  ids: 'com.example:http-server-dsl:+:stubs:8080'
    -  repositoryRoot: http://repo.spring.io/libs-snapshot
  • Now you can annotate your test class with @AutoConfigureStubRunner. In the annotation, +Runner properties, as shown in the following example:

    Unresolved directive in verifier_introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/dsl/http-client/src/test/resources/application-test-repo.yaml[]

    Now you can annotate your test class with @AutoConfigureStubRunner. In the annotation, provide the group-id and artifact-id for Spring Cloud Contract Stub Runner to run the collaborators' stubs for you, as shown in the following example:

    @RunWith(SpringRunner.class)
     @SpringBootTest(webEnvironment=WebEnvironment.NONE)
    @@ -771,9 +767,7 @@ $ git merge --no-ff contract-change-pr

    Work where the repository with your stubs is located. At this moment the stubs of the server side are automatically downloaded from Nexus/Artifactory. You can set the value of stubsMode to REMOTE. The following code shows an example of -achieving the same thing by changing the properties.

    stubrunner:
    -  ids: 'com.example:http-server-dsl:+:stubs:8080'
    -  repositoryRoot: http://repo.spring.io/libs-snapshot

    That’s it!

    2.6 Dependencies

    The best way to add dependencies is to use the proper starter dependency.

    For stub-runner, use spring-cloud-starter-stub-runner. When you use a plugin, add +achieving the same thing by changing the properties.

    Unresolved directive in verifier_introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/dsl/http-client/src/test/resources/application-test-repo.yaml[]

    That’s it!

    2.6 Dependencies

    The best way to add dependencies is to use the proper starter dependency.

    For stub-runner, use spring-cloud-starter-stub-runner. When you use a plugin, add spring-cloud-starter-contract-verifier.

    2.7 Additional Links

    Here are some resources related to Spring Cloud Contract Verifier and Stub Runner. Note that some may be outdated, because the Spring Cloud Contract Verifier project is under constant development.

    2.7.1 Spring Cloud Contract video

    You can check out the video from the Warsaw JUG about Spring Cloud Contract:

    2.8 Samples

    You can find some samples at @@ -877,194 +871,14 @@ consumer will you break with your local changes.

    As you can see the under the slash-delimited groupid / artifact id folder (com/example/server) you have expectations of the 3 consumers (client1, client2 and client3). Expectations are the standard Groovy DSL contract files as described throughout this documentation. This repository has to produce a JAR file that maps -one to one to the contents of the repo.

    Example of a pom.xml inside the server folder.

    <?xml version="1.0" encoding="UTF-8"?>
    -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    -	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    -	<modelVersion>4.0.0</modelVersion>
    -
    -	<groupId>com.example</groupId>
    -	<artifactId>server</artifactId>
    -	<version>0.0.1-SNAPSHOT</version>
    -
    -	<name>Server Stubs</name>
    -	<description>POM used to install locally stubs for consumer side</description>
    -
    -	<parent>
    -		<groupId>org.springframework.boot</groupId>
    -		<artifactId>spring-boot-starter-parent</artifactId>
    -		<version>2.0.3.RELEASE</version>
    -		<relativePath />
    -	</parent>
    -
    -	<properties>
    -		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    -		<java.version>1.8</java.version>
    -		<spring-cloud-contract.version>2.1.0.BUILD-SNAPSHOT</spring-cloud-contract.version>
    -		<spring-cloud-release.version>Finchley.BUILD-SNAPSHOT</spring-cloud-release.version>
    -		<excludeBuildFolders>true</excludeBuildFolders>
    -	</properties>
    -
    -	<dependencyManagement>
    -		<dependencies>
    -			<dependency>
    -				<groupId>org.springframework.cloud</groupId>
    -				<artifactId>spring-cloud-dependencies</artifactId>
    -				<version>${spring-cloud-release.version}</version>
    -				<type>pom</type>
    -				<scope>import</scope>
    -			</dependency>
    -		</dependencies>
    -	</dependencyManagement>
    -
    -	<build>
    -		<plugins>
    -			<plugin>
    -				<groupId>org.springframework.cloud</groupId>
    -				<artifactId>spring-cloud-contract-maven-plugin</artifactId>
    -				<version>${spring-cloud-contract.version}</version>
    -				<extensions>true</extensions>
    -				<configuration>
    -					<!-- By default it would search under src/test/resources/ -->
    -					<contractsDirectory>${project.basedir}</contractsDirectory>
    -				</configuration>
    -			</plugin>
    -		</plugins>
    -	</build>
    -
    -	<repositories>
    -		<repository>
    -			<id>spring-snapshots</id>
    -			<name>Spring Snapshots</name>
    -			<url>https://repo.spring.io/snapshot</url>
    -			<snapshots>
    -				<enabled>true</enabled>
    -			</snapshots>
    -		</repository>
    -		<repository>
    -			<id>spring-milestones</id>
    -			<name>Spring Milestones</name>
    -			<url>https://repo.spring.io/milestone</url>
    -			<snapshots>
    -				<enabled>false</enabled>
    -			</snapshots>
    -		</repository>
    -		<repository>
    -			<id>spring-releases</id>
    -			<name>Spring Releases</name>
    -			<url>https://repo.spring.io/release</url>
    -			<snapshots>
    -				<enabled>false</enabled>
    -			</snapshots>
    -		</repository>
    -	</repositories>
    -	<pluginRepositories>
    -		<pluginRepository>
    -			<id>spring-snapshots</id>
    -			<name>Spring Snapshots</name>
    -			<url>https://repo.spring.io/snapshot</url>
    -			<snapshots>
    -				<enabled>true</enabled>
    -			</snapshots>
    -		</pluginRepository>
    -		<pluginRepository>
    -			<id>spring-milestones</id>
    -			<name>Spring Milestones</name>
    -			<url>https://repo.spring.io/milestone</url>
    -			<snapshots>
    -				<enabled>false</enabled>
    -			</snapshots>
    -		</pluginRepository>
    -		<pluginRepository>
    -			<id>spring-releases</id>
    -			<name>Spring Releases</name>
    -			<url>https://repo.spring.io/release</url>
    -			<snapshots>
    -				<enabled>false</enabled>
    -			</snapshots>
    -		</pluginRepository>
    -	</pluginRepositories>
    -
    -</project>

    As you can see there are no dependencies other than the Spring Cloud Contract Maven Plugin. +one to one to the contents of the repo.

    Example of a pom.xml inside the server folder.

    Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/contracts/com/example/server/pom.xml[indent=0]

    As you can see there are no dependencies other than the Spring Cloud Contract Maven Plugin. Those poms are necessary for the consumer side to run mvn clean install -DskipTests to locally install - stubs of the producer project.

    The pom.xml in the root folder can look like this:

    <?xml version="1.0" encoding="UTF-8"?>
    -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    -		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    -	<modelVersion>4.0.0</modelVersion>
    -
    -	<groupId>com.example.standalone</groupId>
    -	<artifactId>contracts</artifactId>
    -	<version>0.0.1-SNAPSHOT</version>
    -
    -	<name>Contracts</name>
    -	<description>Contains all the Spring Cloud Contracts, well, contracts. JAR used by the producers to generate tests and stubs</description>
    -
    -	<properties>
    -		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    -	</properties>
    -
    -	<build>
    -		<plugins>
    -			<plugin>
    -				<groupId>org.apache.maven.plugins</groupId>
    -				<artifactId>maven-assembly-plugin</artifactId>
    -				<executions>
    -					<execution>
    -						<id>contracts</id>
    -						<phase>prepare-package</phase>
    -						<goals>
    -							<goal>single</goal>
    -						</goals>
    -						<configuration>
    -							<attach>true</attach>
    -							<descriptor>${basedir}/src/assembly/contracts.xml</descriptor>
    -							<!-- If you want an explicit classifier remove the following line -->
    -							<appendAssemblyId>false</appendAssemblyId>
    -						</configuration>
    -					</execution>
    -				</executions>
    -			</plugin>
    -		</plugins>
    -	</build>
    -
    -</project>

    It’s using the assembly plugin in order to build the JAR with all the contracts. Example of such setup is here:

    <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 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    -	<id>project</id>
    -	<formats>
    -		<format>jar</format>
    -	</formats>
    -	<includeBaseDirectory>false</includeBaseDirectory>
    -	<fileSets>
    -		<fileSet>
    -			<directory>${project.basedir}</directory>
    -			<outputDirectory>/</outputDirectory>
    -			<useDefaultExcludes>true</useDefaultExcludes>
    -			<excludes>
    -				<exclude>**/${project.build.directory}/**</exclude>
    -				<exclude>mvnw</exclude>
    -				<exclude>mvnw.cmd</exclude>
    -				<exclude>.mvn/**</exclude>
    -				<exclude>src/**</exclude>
    -			</excludes>
    -		</fileSet>
    -	</fileSets>
    -</assembly>

    3.5.2 Workflow

    The workflow would look similar to the one presented in the Step by step guide to CDC. The only difference + stubs of the producer project.

    The pom.xml in the root folder can look like this:

    Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/contracts/pom.xml[indent=0]

    It’s using the assembly plugin in order to build the JAR with all the contracts. Example of such setup is here:

    Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/contracts/src/assembly/contracts.xml[indent=0]

    3.5.2 Workflow

    The workflow would look similar to the one presented in the Step by step guide to CDC. The only difference is that the producer doesn’t own the contracts anymore. So the consumer and the producer have to work on common contracts in a common repository.

    3.5.3 Consumer

    When the consumer wants to work on the contracts offline, instead of cloning the producer code, the consumer team clones the common repository, goes to the required producer’s folder (e.g. com/example/server) and runs mvn clean install -DskipTests to install locally the stubs converted from the contracts.

    [Tip]Tip

    You need to have Maven installed locally

    3.5.4 Producer

    As a producer it’s enough to alter the Spring Cloud Contract Verifier to provide the URL and the dependency -of the JAR containing the contracts:

    <plugin>
    -	<groupId>org.springframework.cloud</groupId>
    -	<artifactId>spring-cloud-contract-maven-plugin</artifactId>
    -	<configuration>
    -		<contractsMode>REMOTE</contractsMode>
    -		<contractsRepositoryUrl>http://link/to/your/nexus/or/artifactory/or/sth</contractsRepositoryUrl>
    -		<contractDependency>
    -			<groupId>com.example.standalone</groupId>
    -			<artifactId>contracts</artifactId>
    -		</contractDependency>
    -	</configuration>
    -</plugin>

    With this setup the JAR with groupid com.example.standalone and artifactid contracts will be downloaded +of the JAR containing the contracts:

    Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/basic-remote-contracts/pom-with-repo.xml[tags=remote_config,indent=0]

    With this setup the JAR with groupid com.example.standalone and artifactid contracts will be downloaded from http://link/to/your/nexus/or/artifactory/or/sth. It will be then unpacked in a local temporary folder and contracts present under the com/example/server will be picked as the ones used to generate the tests and the stubs. Due to this convention the producer team will know which consumer teams will be broken @@ -2397,73 +2211,13 @@ versions, which are automatically uploaded after every successful build:

    [Tip]Tip

    For both Maven and Gradle, the setup comes ready to work. However, you can customize it if you want to.

    Maven. 

    <!-- First disable the default jar setup in the properties section -->
    -<!-- we don't want the verifier to do a jar for us -->
    -<spring.cloud.contract.verifier.skip>true</spring.cloud.contract.verifier.skip>
    +Unresolved directive in verifier_stubrunner.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_with_restdocs/pom.xml[tags=skip_jar,indent=0]
     
     <!-- Next add the assembly plugin to your build -->
    -<!-- we want the assembly plugin to generate the JAR -->
    -<plugin>
    -	<groupId>org.apache.maven.plugins</groupId>
    -	<artifactId>maven-assembly-plugin</artifactId>
    -	<executions>
    -		<execution>
    -			<id>stub</id>
    -			<phase>prepare-package</phase>
    -			<goals>
    -				<goal>single</goal>
    -			</goals>
    -			<inherited>false</inherited>
    -			<configuration>
    -				<attach>true</attach>
    -				<descriptors>
    -					${basedir}/src/assembly/stub.xml
    -				</descriptors>
    -			</configuration>
    -		</execution>
    -	</executions>
    -</plugin>
    +Unresolved directive in verifier_stubrunner.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_with_restdocs/pom.xml[tags=assembly,indent=0]
     
     <!-- Finally setup your assembly. Below you can find the contents of src/main/assembly/stub.xml -->
    -<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 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    -	<id>stubs</id>
    -	<formats>
    -		<format>jar</format>
    -	</formats>
    -	<includeBaseDirectory>false</includeBaseDirectory>
    -	<fileSets>
    -		<fileSet>
    -			<directory>src/main/java</directory>
    -			<outputDirectory>/</outputDirectory>
    -			<includes>
    -				<include>**com/example/model/*.*</include>
    -			</includes>
    -		</fileSet>
    -		<fileSet>
    -			<directory>${project.build.directory}/classes</directory>
    -			<outputDirectory>/</outputDirectory>
    -			<includes>
    -				<include>**com/example/model/*.*</include>
    -			</includes>
    -		</fileSet>
    -		<fileSet>
    -			<directory>${project.build.directory}/snippets/stubs</directory>
    -			<outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings</outputDirectory>
    -			<includes>
    -				<include>**/*</include>
    -			</includes>
    -		</fileSet>
    -		<fileSet>
    -			<directory>${basedir}/src/test/resources/contracts</directory>
    -			<outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/contracts</outputDirectory>
    -			<includes>
    -				<include>**/*.groovy</include>
    -			</includes>
    -		</fileSet>
    -	</fileSets>
    -</assembly>

    +Unresolved directive in verifier_stubrunner.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_with_restdocs/src/assembly/stub.xml[indent=0]

    Gradle. 

    ext {
     	contractsDir = file("mappings")
    @@ -4968,29 +4722,12 @@ to work with Web Flux.

    Maven. 

    contracts {
     		testMode = 'EXPLICIT'
     }

    -

    The following example shows how to set up a base class and Rest Assured for Web Flux:

    @RunWith(SpringRunner.class)
    -@SpringBootTest(classes = BeerRestBase.Config.class,
    -		webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
    -		properties = "server.port=0")
    -public abstract class BeerRestBase {
    +

    The following example shows how to set up a base class and Rest Assured for Web Flux:

    Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_webflux/src/test/java/com/example/BeerRestBase.java[tags=annotations,indent=0]
     
         // your tests go here
     
         // in this config class you define all controllers and mocked services
    -@Configuration
    -@EnableAutoConfiguration
    -static class Config {
    -
    -	@Bean
    -	PersonCheckingService personCheckingService()  {
    -		return personToCheck -> personToCheck.age >= 20;
    -	}
    -
    -	@Bean
    -	ProducerController producerController() {
    -		return new ProducerController(personCheckingService());
    -	}
    -}
    +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_webflux/src/test/java/com/example/BeerRestBase.java[tags=config,indent=0]
     
     }

    8.10 Messaging Top-Level Elements

    The DSL for messaging looks a little bit different than the one that focuses on HTTP. The following sections explain the differences:

    8.10.1 Output Triggered by a Method

    The output message can be triggered by calling a method (such as a Scheduler when a was @@ -5298,218 +5035,19 @@ testCompile 'org }

    [Tip]Tip

    You don’t need to specify the output directory for the generated snippets since version 1.2.0.RELEASE of Spring REST Docs.

    9. Customization

    [Important]Important

    This section is valid only for Groovy DSL

    You can customize the Spring Cloud Contract Verifier by extending the DSL, as shown in the remainder of this section.

    9.1 Extending the DSL

    You can provide your own functions to the DSL. The key requirement for this feature is to maintain the static compatibility. Later in this document, you can see examples of:

    • Creating a JAR with reusable classes.
    • Referencing of these classes in the DSLs.

    You can find the full example -here.

    9.1.1 Common JAR

    The following examples show three classes that can be reused in the DSLs.

    PatternUtils contains functions used by both the consumer and the producer.

    package com.example;
    -
    -import java.util.regex.Pattern;
    -
    -/**
    - * If you want to use {@link Pattern} directly in your tests
    - * then you can create a class resembling this one. It can
    - * contain all the {@link Pattern} you want to use in the DSL.
    - *
    - * <pre>
    - * {@code
    - * request {
    - *     body(
    - *         [ age: $(c(PatternUtils.oldEnough()))]
    - *     )
    - * }
    - * </pre>
    - *
    - * Notice that we're using both {@code $()} for dynamic values
    - * and {@code c()} for the consumer side.
    - *
    - * @author Marcin Grzejszczak
    - */
    -//tag::impl[]
    -public class PatternUtils {
    -
    -	public static String tooYoung() {
    -		//remove::start[]
    -		return "[0-1][0-9]";
    -		//remove::end[return]
    -	}
    -
    -	public static Pattern oldEnough() {
    -		//remove::start[]
    -		return Pattern.compile("[2-9][0-9]");
    -		//remove::end[return]
    -	}
    -
    -	/**
    -	 * Makes little sense but it's just an example ;)
    -	 */
    -	public static Pattern ok() {
    -		//remove::start[]
    -		return Pattern.compile("OK");
    -		//remove::end[return]
    -	}
    -}
    -//end::impl[]

    ConsumerUtils contains functions used by the consumer.

    package com.example;
    -
    -import org.springframework.cloud.contract.spec.internal.ClientDslProperty;
    -
    -/**
    - * DSL Properties passed to the DSL from the consumer's perspective.
    - * That means that on the input side {@code Request} for HTTP
    - * or {@code Input} for messaging you can have a regular expression.
    - * On the {@code Response} for HTTP or {@code Output} for messaging
    - * you have to have a concrete value.
    - *
    - * @author Marcin Grzejszczak
    - */
    -//tag::impl[]
    -public class ConsumerUtils {
    -	/**
    -	 * Consumer side property. By using the {@link ClientDslProperty}
    -	 * you can omit most of boilerplate code from the perspective
    -	 * of dynamic values. Example
    -	 *
    -	 * <pre>
    -	 * {@code
    -	 * request {
    -	 *     body(
    -	 *         [ age: $(ConsumerUtils.oldEnough())]
    -	 *     )
    -	 * }
    -	 * </pre>
    -	 *
    -	 * That way it's in the implementation that we decide what value we will pass to the consumer
    -	 * and which one to the producer.
    -	 *
    -	 * @author Marcin Grzejszczak
    -	 */
    -	public static ClientDslProperty oldEnough() {
    -		//remove::start[]
    -		// this example is not the best one and
    -		// theoretically you could just pass the regex instead of `ServerDslProperty` but
    -		// it's just to show some new tricks :)
    -		return new ClientDslProperty(PatternUtils.oldEnough(), 40);
    -		//remove::end[return]
    -	}
    -
    -}
    -//end::impl[]

    ProducerUtils contains functions used by the producer.

    package com.example;
    -
    -import org.springframework.cloud.contract.spec.internal.ServerDslProperty;
    -
    -/**
    - * DSL Properties passed to the DSL from the producer's perspective.
    - * That means that on the input side {@code Request} for HTTP
    - * or {@code Input} for messaging you have to have a concrete value.
    - * On the {@code Response} for HTTP or {@code Output} for messaging
    - * you can have a regular expression.
    - *
    - * @author Marcin Grzejszczak
    - */
    -//tag::impl[]
    -public class ProducerUtils {
    -
    -	/**
    -	 * Producer side property. By using the {@link ProducerUtils}
    -	 * you can omit most of boilerplate code from the perspective
    -	 * of dynamic values. Example
    -	 *
    -	 * <pre>
    -	 * {@code
    -	 * response {
    -	 *     body(
    -	 *         [ status: $(ProducerUtils.ok())]
    -	 *     )
    -	 * }
    -	 * </pre>
    -	 *
    -	 * That way it's in the implementation that we decide what value we will pass to the consumer
    -	 * and which one to the producer.
    -	 */
    -	public static ServerDslProperty ok() {
    -		// this example is not the best one and
    -		// theoretically you could just pass the regex instead of `ServerDslProperty` but
    -		// it's just to show some new tricks :)
    -		return new ServerDslProperty( PatternUtils.ok(), "OK");
    -	}
    -}
    -//end::impl[]

    9.1.2 Adding the Dependency to the Project

    In order for the plugins and IDE to be able to reference the common JAR classes, you need +here.

    9.1.1 Common JAR

    The following examples show three classes that can be reused in the DSLs.

    PatternUtils contains functions used by both the consumer and the producer.

    Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/common/src/main/java/com/example/PatternUtils.java[]

    ConsumerUtils contains functions used by the consumer.

    Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/common/src/main/java/com/example/ConsumerUtils.java[]

    ProducerUtils contains functions used by the producer.

    Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/common/src/main/java/com/example/ProducerUtils.java[]

    9.1.2 Adding the Dependency to the Project

    In order for the plugins and IDE to be able to reference the common JAR classes, you need to pass the dependency to your project.

    9.1.3 Test the Dependency in the Project’s Dependencies

    First, add the common jar dependency as a test dependency. Because your contracts files are available on the test resources path, the common jar classes automatically become visible in your Groovy files. The following examples show how to test the dependency:

    Maven.  -

    <dependency>
    -	<groupId>com.example</groupId>
    -	<artifactId>beer-common</artifactId>
    -	<version>${project.version}</version>
    -	<scope>test</scope>
    -</dependency>

    +

    Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/pom.xml[tags=test_dep,indent=0]

    Gradle.  -

    testCompile("com.example:beer-common:0.0.1-SNAPSHOT")

    +

    Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/build.gradle[tags=test_dep,indent=0]

    9.1.4 Test a Dependency in the Plugin’s Dependencies

    Now, you must add the dependency for the plugin to reuse at runtime, as shown in the following example:

    Maven.  -

    <plugin>
    -	<groupId>org.springframework.cloud</groupId>
    -	<artifactId>spring-cloud-contract-maven-plugin</artifactId>
    -	<version>${spring-cloud-contract.version}</version>
    -	<extensions>true</extensions>
    -	<configuration>
    -		<packageWithBaseClasses>com.example</packageWithBaseClasses>
    -		<baseClassMappings>
    -			<baseClassMapping>
    -				<contractPackageRegex>.*intoxication.*</contractPackageRegex>
    -				<baseClassFQN>com.example.intoxication.BeerIntoxicationBase</baseClassFQN>
    -			</baseClassMapping>
    -		</baseClassMappings>
    -	</configuration>
    -	<dependencies>
    -		<dependency>
    -			<groupId>com.example</groupId>
    -			<artifactId>beer-common</artifactId>
    -			<version>${project.version}</version>
    -			<scope>compile</scope>
    -		</dependency>
    -	</dependencies>
    -</plugin>

    +

    Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/pom.xml[tags=test_dep_in_plugin,indent=0]

    Gradle.  -

    classpath "com.example:beer-common:0.0.1-SNAPSHOT"

    -

    9.1.5 Referencing classes in DSLs

    You can now reference your classes in your DSL, as shown in the following example:

    package contracts.beer.rest
    -
    -import com.example.ConsumerUtils
    -import com.example.ProducerUtils
    -import org.springframework.cloud.contract.spec.Contract
    -
    -Contract.make {
    -	description("""
    -Represents a successful scenario of getting a beer
    -
    -```
    -given:
    -	client is old enough
    -when:
    -	he applies for a beer
    -then:
    -	we'll grant him the beer
    -```
    -
    -""")
    -	request {
    -		method 'POST'
    -		url '/check'
    -		body(
    -				age: $(ConsumerUtils.oldEnough())
    -		)
    -		headers {
    -			contentType(applicationJson())
    -		}
    -	}
    -	response {
    -		status 200
    -		body("""
    -			{
    -				"status": "${value(ProducerUtils.ok())}"
    -			}
    -			""")
    -		headers {
    -			contentType(applicationJson())
    -		}
    -	}
    -}

    10. Using the Pluggable Architecture

    You may encounter cases where you have your contracts have been defined in other formats, +

    Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/build.gradle[tags=test_dep_in_plugin,indent=0]

    +

    9.1.5 Referencing classes in DSLs

    You can now reference your classes in your DSL, as shown in the following example:

    Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/src/test/resources/contracts/beer/rest/shouldGrantABeerIfOldEnough.groovy[indent=0]

    10. Using the Pluggable Architecture

    You may encounter cases where you have your contracts have been defined in other formats, such as YAML, RAML or PACT. In those cases, you still want to benefit from the automatic generation of tests and stubs. You can add your own implementation for generating both tests and stubs. Also, you can customize the way tests are generated (for example, you diff --git a/spring-cloud-contract.xml b/spring-cloud-contract.xml index 1e0806c216..b182c597fb 100644 --- a/spring-cloud-contract.xml +++ b/spring-cloud-contract.xml @@ -247,9 +247,7 @@ in place yet, so the automatically-generated contract tests fail. By getting already-existing producer service stubs from a remote repository. To do so, pass the stub artifact IDs and artifact repository URL as Spring Cloud Contract Stub Runner properties, as shown in the following example: -stubrunner: - ids: 'com.example:http-server-dsl:+:stubs:8080' - repositoryRoot: http://repo.spring.io/libs-snapshot +Unresolved directive in verifier_introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/dsl/http-client/src/test/resources/application-test-repo.yaml[] Now you can annotate your test class with @AutoConfigureStubRunner. In the annotation, @@ -493,9 +491,7 @@ in place, so the automatically-generated contract tests fail. Getting already existing producer service stubs from a remote repository. To do so, pass the stub artifact IDs and artifact repository URl as Spring Cloud Contract Stub Runner properties, as shown in the following example: -stubrunner: - ids: 'com.example:http-server-dsl:+:stubs:8080' - repositoryRoot: http://repo.spring.io/libs-snapshot +Unresolved directive in verifier_introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/dsl/http-client/src/test/resources/application-test-repo.yaml[] Now you can annotate your test class with @AutoConfigureStubRunner. In the annotation, @@ -1277,9 +1273,7 @@ where the repository with your stubs is located. At this moment the stubs of the side are automatically downloaded from Nexus/Artifactory. You can set the value of stubsMode to REMOTE. The following code shows an example of achieving the same thing by changing the properties. -stubrunner: - ids: 'com.example:http-server-dsl:+:stubs:8080' - repositoryRoot: http://repo.spring.io/libs-snapshot +Unresolved directive in verifier_introduction.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/dsl/http-client/src/test/resources/application-test-repo.yaml[] That’s it! @@ -1538,183 +1532,14 @@ expectations of the 3 consumers (client1, client2 Example of a pom.xml inside the server folder. -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>com.example</groupId> - <artifactId>server</artifactId> - <version>0.0.1-SNAPSHOT</version> - - <name>Server Stubs</name> - <description>POM used to install locally stubs for consumer side</description> - - <parent> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-parent</artifactId> - <version>2.0.3.RELEASE</version> - <relativePath /> - </parent> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <java.version>1.8</java.version> - <spring-cloud-contract.version>2.1.0.BUILD-SNAPSHOT</spring-cloud-contract.version> - <spring-cloud-release.version>Finchley.BUILD-SNAPSHOT</spring-cloud-release.version> - <excludeBuildFolders>true</excludeBuildFolders> - </properties> - - <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.springframework.cloud</groupId> - <artifactId>spring-cloud-dependencies</artifactId> - <version>${spring-cloud-release.version}</version> - <type>pom</type> - <scope>import</scope> - </dependency> - </dependencies> - </dependencyManagement> - - <build> - <plugins> - <plugin> - <groupId>org.springframework.cloud</groupId> - <artifactId>spring-cloud-contract-maven-plugin</artifactId> - <version>${spring-cloud-contract.version}</version> - <extensions>true</extensions> - <configuration> - <!-- By default it would search under src/test/resources/ --> - <contractsDirectory>${project.basedir}</contractsDirectory> - </configuration> - </plugin> - </plugins> - </build> - - <repositories> - <repository> - <id>spring-snapshots</id> - <name>Spring Snapshots</name> - <url>https://repo.spring.io/snapshot</url> - <snapshots> - <enabled>true</enabled> - </snapshots> - </repository> - <repository> - <id>spring-milestones</id> - <name>Spring Milestones</name> - <url>https://repo.spring.io/milestone</url> - <snapshots> - <enabled>false</enabled> - </snapshots> - </repository> - <repository> - <id>spring-releases</id> - <name>Spring Releases</name> - <url>https://repo.spring.io/release</url> - <snapshots> - <enabled>false</enabled> - </snapshots> - </repository> - </repositories> - <pluginRepositories> - <pluginRepository> - <id>spring-snapshots</id> - <name>Spring Snapshots</name> - <url>https://repo.spring.io/snapshot</url> - <snapshots> - <enabled>true</enabled> - </snapshots> - </pluginRepository> - <pluginRepository> - <id>spring-milestones</id> - <name>Spring Milestones</name> - <url>https://repo.spring.io/milestone</url> - <snapshots> - <enabled>false</enabled> - </snapshots> - </pluginRepository> - <pluginRepository> - <id>spring-releases</id> - <name>Spring Releases</name> - <url>https://repo.spring.io/release</url> - <snapshots> - <enabled>false</enabled> - </snapshots> - </pluginRepository> - </pluginRepositories> - -</project> +Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/contracts/com/example/server/pom.xml[indent=0] As you can see there are no dependencies other than the Spring Cloud Contract Maven Plugin. Those poms are necessary for the consumer side to run mvn clean install -DskipTests to locally install stubs of the producer project. The pom.xml in the root folder can look like this: -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>com.example.standalone</groupId> - <artifactId>contracts</artifactId> - <version>0.0.1-SNAPSHOT</version> - - <name>Contracts</name> - <description>Contains all the Spring Cloud Contracts, well, contracts. JAR used by the producers to generate tests and stubs</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-assembly-plugin</artifactId> - <executions> - <execution> - <id>contracts</id> - <phase>prepare-package</phase> - <goals> - <goal>single</goal> - </goals> - <configuration> - <attach>true</attach> - <descriptor>${basedir}/src/assembly/contracts.xml</descriptor> - <!-- If you want an explicit classifier remove the following line --> - <appendAssemblyId>false</appendAssemblyId> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - -</project> +Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/contracts/pom.xml[indent=0] It’s using the assembly plugin in order to build the JAR with all the contracts. Example of such setup is here: -<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 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> - <id>project</id> - <formats> - <format>jar</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <fileSets> - <fileSet> - <directory>${project.basedir}</directory> - <outputDirectory>/</outputDirectory> - <useDefaultExcludes>true</useDefaultExcludes> - <excludes> - <exclude>**/${project.build.directory}/**</exclude> - <exclude>mvnw</exclude> - <exclude>mvnw.cmd</exclude> - <exclude>.mvn/**</exclude> - <exclude>src/**</exclude> - </excludes> - </fileSet> - </fileSets> -</assembly> +Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/samples/standalone/contracts/src/assembly/contracts.xml[indent=0]

    Workflow @@ -1735,18 +1560,7 @@ and runs mvn clean install -DskipTests to install locally the Producer As a producer it’s enough to alter the Spring Cloud Contract Verifier to provide the URL and the dependency of the JAR containing the contracts: -<plugin> - <groupId>org.springframework.cloud</groupId> - <artifactId>spring-cloud-contract-maven-plugin</artifactId> - <configuration> - <contractsMode>REMOTE</contractsMode> - <contractsRepositoryUrl>http://link/to/your/nexus/or/artifactory/or/sth</contractsRepositoryUrl> - <contractDependency> - <groupId>com.example.standalone</groupId> - <artifactId>contracts</artifactId> - </contractDependency> - </configuration> -</plugin> +Unresolved directive in verifier_faq.adoc - include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-contract/master/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/basic-remote-contracts/pom-with-repo.xml[tags=remote_config,indent=0] With this setup the JAR with groupid com.example.standalone and artifactid contracts will be downloaded from http://link/to/your/nexus/or/artifactory/or/sth. It will be then unpacked in a local temporary folder and contracts present under the com/example/server will be picked as the ones used to generate the @@ -4116,73 +3930,13 @@ it if you want to. Maven <!-- First disable the default jar setup in the properties section --> -<!-- we don't want the verifier to do a jar for us --> -<spring.cloud.contract.verifier.skip>true</spring.cloud.contract.verifier.skip> +Unresolved directive in verifier_stubrunner.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_with_restdocs/pom.xml[tags=skip_jar,indent=0] <!-- Next add the assembly plugin to your build --> -<!-- we want the assembly plugin to generate the JAR --> -<plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-assembly-plugin</artifactId> - <executions> - <execution> - <id>stub</id> - <phase>prepare-package</phase> - <goals> - <goal>single</goal> - </goals> - <inherited>false</inherited> - <configuration> - <attach>true</attach> - <descriptors> - ${basedir}/src/assembly/stub.xml - </descriptors> - </configuration> - </execution> - </executions> -</plugin> +Unresolved directive in verifier_stubrunner.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_with_restdocs/pom.xml[tags=assembly,indent=0] <!-- Finally setup your assembly. Below you can find the contents of src/main/assembly/stub.xml --> -<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 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> - <id>stubs</id> - <formats> - <format>jar</format> - </formats> - <includeBaseDirectory>false</includeBaseDirectory> - <fileSets> - <fileSet> - <directory>src/main/java</directory> - <outputDirectory>/</outputDirectory> - <includes> - <include>**com/example/model/*.*</include> - </includes> - </fileSet> - <fileSet> - <directory>${project.build.directory}/classes</directory> - <outputDirectory>/</outputDirectory> - <includes> - <include>**com/example/model/*.*</include> - </includes> - </fileSet> - <fileSet> - <directory>${project.build.directory}/snippets/stubs</directory> - <outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings</outputDirectory> - <includes> - <include>**/*</include> - </includes> - </fileSet> - <fileSet> - <directory>${basedir}/src/test/resources/contracts</directory> - <outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/contracts</outputDirectory> - <includes> - <include>**/*.groovy</include> - </includes> - </fileSet> - </fileSets> -</assembly> +Unresolved directive in verifier_stubrunner.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_with_restdocs/src/assembly/stub.xml[indent=0] @@ -8098,29 +7852,12 @@ to work with Web Flux. The following example shows how to set up a base class and Rest Assured for Web Flux: -@RunWith(SpringRunner.class) -@SpringBootTest(classes = BeerRestBase.Config.class, - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = "server.port=0") -public abstract class BeerRestBase { +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_webflux/src/test/java/com/example/BeerRestBase.java[tags=annotations,indent=0] // your tests go here // in this config class you define all controllers and mocked services -@Configuration -@EnableAutoConfiguration -static class Config { - - @Bean - PersonCheckingService personCheckingService() { - return personToCheck -> personToCheck.age >= 20; - } - - @Bean - ProducerController producerController() { - return new ProducerController(personCheckingService()); - } -} +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer_webflux/src/test/java/com/example/BeerRestBase.java[tags=config,indent=0] }
    @@ -8549,142 +8286,11 @@ maintain the static compatibility. Later in this document, you can see examples Common JAR The following examples show three classes that can be reused in the DSLs. PatternUtils contains functions used by both the consumer and the producer. -package com.example; - -import java.util.regex.Pattern; - -/** - * If you want to use {@link Pattern} directly in your tests - * then you can create a class resembling this one. It can - * contain all the {@link Pattern} you want to use in the DSL. - * - * <pre> - * {@code - * request { - * body( - * [ age: $(c(PatternUtils.oldEnough()))] - * ) - * } - * </pre> - * - * Notice that we're using both {@code $()} for dynamic values - * and {@code c()} for the consumer side. - * - * @author Marcin Grzejszczak - */ -//tag::impl[] -public class PatternUtils { - - public static String tooYoung() { - //remove::start[] - return "[0-1][0-9]"; - //remove::end[return] - } - - public static Pattern oldEnough() { - //remove::start[] - return Pattern.compile("[2-9][0-9]"); - //remove::end[return] - } - - /** - * Makes little sense but it's just an example ;) - */ - public static Pattern ok() { - //remove::start[] - return Pattern.compile("OK"); - //remove::end[return] - } -} -//end::impl[] +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/common/src/main/java/com/example/PatternUtils.java[] ConsumerUtils contains functions used by the consumer. -package com.example; - -import org.springframework.cloud.contract.spec.internal.ClientDslProperty; - -/** - * DSL Properties passed to the DSL from the consumer's perspective. - * That means that on the input side {@code Request} for HTTP - * or {@code Input} for messaging you can have a regular expression. - * On the {@code Response} for HTTP or {@code Output} for messaging - * you have to have a concrete value. - * - * @author Marcin Grzejszczak - */ -//tag::impl[] -public class ConsumerUtils { - /** - * Consumer side property. By using the {@link ClientDslProperty} - * you can omit most of boilerplate code from the perspective - * of dynamic values. Example - * - * <pre> - * {@code - * request { - * body( - * [ age: $(ConsumerUtils.oldEnough())] - * ) - * } - * </pre> - * - * That way it's in the implementation that we decide what value we will pass to the consumer - * and which one to the producer. - * - * @author Marcin Grzejszczak - */ - public static ClientDslProperty oldEnough() { - //remove::start[] - // this example is not the best one and - // theoretically you could just pass the regex instead of `ServerDslProperty` but - // it's just to show some new tricks :) - return new ClientDslProperty(PatternUtils.oldEnough(), 40); - //remove::end[return] - } - -} -//end::impl[] +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/common/src/main/java/com/example/ConsumerUtils.java[] ProducerUtils contains functions used by the producer. -package com.example; - -import org.springframework.cloud.contract.spec.internal.ServerDslProperty; - -/** - * DSL Properties passed to the DSL from the producer's perspective. - * That means that on the input side {@code Request} for HTTP - * or {@code Input} for messaging you have to have a concrete value. - * On the {@code Response} for HTTP or {@code Output} for messaging - * you can have a regular expression. - * - * @author Marcin Grzejszczak - */ -//tag::impl[] -public class ProducerUtils { - - /** - * Producer side property. By using the {@link ProducerUtils} - * you can omit most of boilerplate code from the perspective - * of dynamic values. Example - * - * <pre> - * {@code - * response { - * body( - * [ status: $(ProducerUtils.ok())] - * ) - * } - * </pre> - * - * That way it's in the implementation that we decide what value we will pass to the consumer - * and which one to the producer. - */ - public static ServerDslProperty ok() { - // this example is not the best one and - // theoretically you could just pass the regex instead of `ServerDslProperty` but - // it's just to show some new tricks :) - return new ServerDslProperty( PatternUtils.ok(), "OK"); - } -} -//end::impl[] +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/common/src/main/java/com/example/ProducerUtils.java[]
    Adding the Dependency to the Project @@ -8699,18 +8305,13 @@ visible in your Groovy files. The following examples show how to test the depend Maven -<dependency> - <groupId>com.example</groupId> - <artifactId>beer-common</artifactId> - <version>${project.version}</version> - <scope>test</scope> -</dependency> +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/pom.xml[tags=test_dep,indent=0] Gradle -testCompile("com.example:beer-common:0.0.1-SNAPSHOT") +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/build.gradle[tags=test_dep,indent=0]
    @@ -8721,83 +8322,20 @@ following example: Maven -<plugin> - <groupId>org.springframework.cloud</groupId> - <artifactId>spring-cloud-contract-maven-plugin</artifactId> - <version>${spring-cloud-contract.version}</version> - <extensions>true</extensions> - <configuration> - <packageWithBaseClasses>com.example</packageWithBaseClasses> - <baseClassMappings> - <baseClassMapping> - <contractPackageRegex>.*intoxication.*</contractPackageRegex> - <baseClassFQN>com.example.intoxication.BeerIntoxicationBase</baseClassFQN> - </baseClassMapping> - </baseClassMappings> - </configuration> - <dependencies> - <dependency> - <groupId>com.example</groupId> - <artifactId>beer-common</artifactId> - <version>${project.version}</version> - <scope>compile</scope> - </dependency> - </dependencies> -</plugin> +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/pom.xml[tags=test_dep_in_plugin,indent=0] Gradle -classpath "com.example:beer-common:0.0.1-SNAPSHOT" +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/build.gradle[tags=test_dep_in_plugin,indent=0]
    Referencing classes in DSLs You can now reference your classes in your DSL, as shown in the following example: -package contracts.beer.rest - -import com.example.ConsumerUtils -import com.example.ProducerUtils -import org.springframework.cloud.contract.spec.Contract - -Contract.make { - description(""" -Represents a successful scenario of getting a beer - -``` -given: - client is old enough -when: - he applies for a beer -then: - we'll grant him the beer -``` - -""") - request { - method 'POST' - url '/check' - body( - age: $(ConsumerUtils.oldEnough()) - ) - headers { - contentType(applicationJson()) - } - } - response { - status 200 - body(""" - { - "status": "${value(ProducerUtils.ok())}" - } - """) - headers { - contentType(applicationJson()) - } - } -} +Unresolved directive in verifier_contract.adoc - include::https://raw.githubusercontent.com/spring-cloud-samples/spring-cloud-contract-samples/master/producer/src/test/resources/contracts/beer/rest/shouldGrantABeerIfOldEnough.groovy[indent=0]