packageWithBaseClasses = 'com.example.base'
+From 93652ac0fb4c791fe948a23ade2d0de4e747c91d Mon Sep 17 00:00:00 2001
From: Marcin Grzejszczak
Yes! Check out the Different base classes for contracts sections +of either Gradle or Maven plugins.
+basePackageForTests - specifies base package for all generated tests. By default set to org.springframework.cloud.verifier.tests
baseClassForTests - base class for generated tests. By default spock.lang.Specification if using Spock tests.
baseClassForTests - base class for all generated tests. By default spock.lang.Specification if using Spock tests.
packageWithBaseClasses - instead of providing a fixed value for base class you can provide a package where all the base classes lay. Takes precedence over baseClassForTests.
+baseClassMappings - explicitly map contract package to a FQN of a base class. Takes precedence over packageWithBaseClasses and baseClassForTests.
ruleClassForTests - specifies Rule which should be added to generated test classes.
@@ -2599,7 +2615,7 @@ publishing {When using Spring Cloud Contract Verifier in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified.
protected WebTarget webTarget field, right now the only option to test JAX-RS API is to start a web server.
If your base classes differ between contracts you can tell the Spring Cloud Contract plugin which class should get +extended by the autogenerated tests. You have two options:
+follow a convention by providing the packageWithBaseClasses
provide explicit mapping via baseClassMappings
Convention
+The convention is such that if you have a contract under e.g. src/test/resources/contract/foo/bar/baz/ and provide the value of the packageWithBaseClasses property
+to com.example.base then we will assume that there is a BarBazBase class under com.example.base package. In other words we take last two parts of package
+if they exist and form a class with a Base suffix. Takes precedence over baseClassForTests. Example of usage in the contracts closure:
packageWithBaseClasses = 'com.example.base'
+Mapping
+You can manually map a regular expression of the contract’s package to fully qualified name of the base class for the matched contract. +Let’s take a look at the following example:
+baseClassForTests = "com.example.FooBase"
+baseClassMappings {
+ baseClassMapping('.*/com/.*', 'com.example.ComBase')
+ baseClassMapping('.*/bar/.*':'com.example.BarBase')
+}
+Let’s assume that you have contracts under
+ - src/test/resources/contract/com/
+ - src/test/resources/contract/foo/
By providing the baseClassForTests we have a fallback in case mapping didn’t succeed (you could also provide
+the packageWithBaseClasses as fallback). That way the tests generated from src/test/resources/contract/com/ contracts
+will be extending the com.example.ComBase whereas the rest of tests will extend com.example.FooBase.
testFramework - the target test framework to be used; currently Spock and JUnit are supported with JUnit being the default framework
packageWithBaseClasses - instead of providing a fixed value for base class you can provide a package where all the base classes lay.
+The convention is such that if you have a contract under src/test/resources/contract/foo/bar/baz/ and provide the value of this property
+to com.example.base then we will assume that there is a BarBazBase class under com.example.base package. Takes precedence
+over baseClassForTests
baseClassMappings - list of base class mappings that where you have to provide contractPackageRegex which is checked
+against the package in which the contract lays and baseClassFQN that maps to fully qualified name of the base class for the matched
+contract. If you have a contract under src/test/resources/contract/foo/bar/baz/ and map the property .* → com.example.base.BaseClass then
+the test class generated from these contracts will extend com.example.base.BaseClass. Takes precedence over packageWithBaseClasses
+ and baseClassForTests.
When using Spring Cloud Contract Verifier in default MockMvc you need to create a base specification for all generated acceptance tests. In this class you need to point to endpoint which should be verified.
@@ -2914,6 +2999,81 @@ class MvcSpec extends Specification {In case of using Explicit mode, you can use base class to initialize the whole tested app similarly as in regular integration tests. In case of JAXRSCLIENT mode this base class should also contain protected WebTarget webTarget field, right now the only option to test JAX-RS API is to start a web server.
If your base classes differ between contracts you can tell the Spring Cloud Contract plugin which class should get +extended by the autogenerated tests. You have two options:
+follow a convention by providing the packageWithBaseClasses
provide explicit mapping via baseClassMappings
Convention
+The convention is such that if you have a contract under e.g. src/test/resources/contract/hello/v1/ and provide the value of the packageWithBaseClasses property
+to hello then we will assume that there is a HelloV1Base class under hello package. In other words we take last two parts of package
+if they exist and form a class with a Base suffix. Takes precedence over baseClassForTests. Example of usage in the contracts closure:
<plugin>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-contract-maven-plugin</artifactId>
+ <configuration>
+ <packageWithBaseClasses>hello</packageWithBaseClasses>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
+Mapping
+You can manually map a regular expression of the contract’s package to fully qualified name of the base class for the matched contract.
+You have to provide a list baseClassMappings of baseClassMapping that takes a contractPackageRegex to baseClassFQN mapping.
+Let’s take a look at the following example:
<plugin>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-contract-maven-plugin</artifactId>
+ <configuration>
+ <baseClassForTests>com.example.FooBase</baseClassForTests>
+ <baseClassMappings>
+ <baseClassMapping>
+ <contractPackageRegex>.*com.*</contractPackageRegex>
+ <baseClassFQN>com.example.TestBase</baseClassFQN>
+ </baseClassMapping >
+ </baseClassMappings>
+ </configuration>
+</plugin>
+Let’s assume that you have contracts under
+ - src/test/resources/contract/com/
+ - src/test/resources/contract/foo/
By providing the baseClassForTests we have a fallback in case mapping didn’t succeed (you could also provide
+the packageWithBaseClasses as fallback). That way the tests generated from src/test/resources/contract/com/ contracts
+will be extending the com.example.ComBase whereas the rest of tests will extend com.example.FooBase.