Is it possible with spring-cloud-contract to work on a contract branch for the producer? - spring-cloud-contract

Currently we have a github repo where we store all the contracts, another repo which contains the producer code, and last but not least another one which contains the consumer code.
On the consumer side working with branches when pointing to the contract repo is well supported by using properties like stubrunner.properties.git.branch (more info can be found here https://cloud.spring.io/spring-cloud-contract/reference/html/appendix.html#additional-application-properties)
But on the producer I can not see any way of using the contracts of a concrete branch, we just can point to the github repo where contracts are stored by using contractsRepositoryUrl of the spring-cloud-contract-maven-plugin
This will be very useful to create a flow of contract testing :
a PR to contract testing repo with the proposal
which will trigger the producer job (passing the pr branch name)
if the repo with the contracts contains the bindings, populated by the producer(previous step), then we could trigger the consumer job and validate if everything is fine with these proposed changes
once the 2 builds are green (producer and consumer) we can merge the changes on the contracts repo
UPDATE : the following spring-cloud-contract-maven-plugin config worked for me, also you can set this property through command line like this -Dstubrunner.properties.git.branch=other_branch_than_master
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${spring-cloud-contract.version}</version>
<extensions>true</extensions>
<configuration>
<baseClassMappings>
<baseClassMapping>
<contractPackageRegex>.*rest.*</contractPackageRegex>
<baseClassFQN>com.xxx.yyy.contract.ContentCheckBaseTestClass</baseClassFQN>
</baseClassMapping>
</baseClassMappings>
<basePackageForTests>com.xxx.yyy.contract</basePackageForTests>
<contractsRepositoryUrl>git://https://github.com/xxx/yyy.git</contractsRepositoryUrl>
<contractsRepositoryUsername>${GITHUB_USER}</contractsRepositoryUsername>
<contractsRepositoryPassword>${GITHUB_TOKEN}</contractsRepositoryPassword>
<contractsMode>REMOTE</contractsMode>
<testMode>EXPLICIT</testMode>
<testFramework>JUNIT5</testFramework>
<contractsProperties>
<git.branch>another_branch</git.branch>
</contractsProperties>
<contractDependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</contractDependency>
</configuration>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>pushStubsToScm</goal>
</goals>
</execution>
</executions>
</plugin>

You can reuse the same properties presented here (https://docs.spring.io/spring-cloud-contract/docs/2.2.6.RELEASE/reference/html/appendix.html#additional-application-properties) under the e.g. Spring Cloud Contract Maven's <configuration><contractProperties> section. That way you can pick which branch should be downloaded

Related

Karate: Karate-summary report missing CSS format [duplicate]

After running a test case with Karate, some html reports are published with surefire plugin. In particular, I've found that there is an html report for each feature file. This is inconvenient when tests are run from an automated pipeline, like in my case, where I use htmlpublish Jenkins plugin to get a public link to access reports and spread them across slack channels or emails.
I've tried to add this snippet in my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<aggregate>true</aggregate>
<!--also set this to link to generated source reports-->
<linkXRef>true</linkXRef>
</configuration>
</plugin>
But it had not the desired effect.
I'm trying to achieve a single index.html into the target/surefire-reports directory so i can publish and browse all test reports
Any suggestion?
Thanks
Are you using the parallel runner ? If not, please read up about it: https://github.com/intuit/karate#parallel-execution
Since we emit the cucumber-compatible JSON report in addition to the industry-standard JUnit XML format, you have the choice of any reporting solution that fits your needs. I think the maven-cucumber-reporting library should work for you - but you can decide: https://github.com/intuit/karate/tree/master/karate-demo#example-report
EDIT: For any other advanced needs, please consider writing your own report: https://stackoverflow.com/a/66773839/143475

Spring cloud contract with common contract repository

I Created a sperate repository to store the contract as descibed in this link:
https://github.com/spring-cloud/spring-cloud-contract/tree/main/samples/standalone/contracts
In the producer side, I added the generated jar of contract as follow:
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<configuration>
<contractsMode>LOCAL</contractsMode>
<contractDependency>
<groupId>com.example.standalone</groupId>
<artifactId>contracts</artifactId>
</contractDependency>
</configuration>
</plugin>
When I execute the maven install, this doesn't generate the contracts verifier classes in the target folder. any help?
Thanks
Please check the sample in spring-cloud-contract-samples repo producer with external contracts
The beer contracts folder contains only contract definitions - it will not generate any test classes.
This project producer with external contracts will generate test classes from the contracts defined in this beer contracts folder.

Spring Cloud contract jar versioning

I have established Spring cloud contract between two microservices in my project successfully. Everything was good until yesterday.
On consumer side, I am referencing the latest version of stubs like below:
#AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:8080"})
But this causes problem in some cases where the producer side reverted their latest version and switched back to previous version.
Or
somehow there is a situation that the jar that contains current stubs has a lower version than the latest version in maven repo.
Is there a way in Spring cloud contract to do either one of the following?
1) configure the consumer side to pick up the current project version (referring to project version in pom.xml) instead of the latest version from maven repo?
Or
2) configure the producer side to have a static version of stubs jar but keep dynamic version of other project jars. This would allow the consumer side to refer to the same static version of stubs jar
I read the documentation https://cloud.spring.io/spring-cloud-static/spring-cloud-contract/2.1.1.RELEASE/single/spring-cloud-contract.html#_jar_versioning but it did not help
You can play around with the provided version. We give + to always download the latest. You can set a concrete value e.g. 2.1.1.RELEASE. You can also set ranges. All in all we're using Ivy underneath so you can check out the rules of Ivy http://ant.apache.org/ivy/history/latest-milestone/settings/version-matchers.html
1) configure the consumer side to pick up the current project version instead of the latest one?
What does current mean? Is it the latest? Latest release? If it's the latest release pick + but point to the repo that contains release versions only without snapshots.
I read the documentation https://cloud.spring.io/spring-cloud-static/spring-cloud-contract/2.1.1.RELEASE/single/spring-cloud-contract.html#_jar_versioning but it did not help
What is missing in this section? You asked about static stubs, we describe it there too #AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:2.1.1:stubs:8080"}).
Following worked (for maven project).
Step1: Instead of specifying the ids in #AutoConfigureStubRunner, we can provide it inside application.properties file like below (notice #project.version#, this refers to maven project version )
stubrunner.ids=com.example:http-server-dsl:#project.version#:stubs:8080
Step2: To be able to use #project.version# in properties file, add the following in build section of pom.xml:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
And in plugins section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${mvn-resources-plugin.version}</version>
<configuration>
<delimiters>
<delimiter>#</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>

multiple pact version support from PACT-Broker

I am using JUnit for generating Pacts and Pacts maven plugin to post the pact into pact broker.
I am using below plugin Configuration
<plugin>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-maven_2.11</artifactId>
<version>3.3.9</version>
<configuration>
<projectVersion>2.0</projectVersion>
<pactBrokerUrl>https:example.com</pactBrokerUrl>
<pactBrokerUsername>username1</pactBrokerUsername>
<pactBrokerPassword>password1</pactBrokerPassword>
<trimSnapshot>true</trimSnapshot> <!-- Defaults to false -->
</configuration>
</plugin>
While Consumenr pact is getting uploaded in broker, I am able to see only single entry of consumer pact of version 2.0. Eirlier I have uploaded version 1.0 eirlier, which is not present in the UI. Is there any way to see the multiple version of same provider pact in HAL browser and get different version of PACTS by Https GET request? Currently I am getting only latest consumenr pact version by http://your-pact-broker/pacts/provider/PROVIDER/consumer/CONSUMER/latest
Please provide some info regurding this and let me know if you need any informaiton.
http://your-pact-broker/pacts/provider/PROVIDER/consumer/CONSUMER/versions will show you all the versions of the pact. You can retrieve a pact using the same URL that you used to PUT it to the broker eg. http://your-pact-broker/pacts/provider/PROVIDER/consumer/CONSUMER/version/CONSUMER_VERSION.
You can explore the Pact Broker API using the embedded HAL browser, by clicking the 'HAL browser' link from the index page of the broker.

SOAPUI: how to refer to external jars?

Commonly known, that for usage of different jars we need add them to SoapUI/../ext/ directory. for example, for correct work of jdbc requests with IBM/..AS400JDBC Driver we need to add jt400.jar to /ext dir.
But I have problem: my client implements new policy - direct forbidding of using any jars locally, only as dependencies like
<dependency>
<groupId>net.sf.jt400</groupId>
<artifactId>jt400-full</artifactId>
<version>6.0</version>
</dependency>
I successfully uses it in my POM's for CI, but I also need to run my projects in SOAPUI.
So, question is: is there any way to add dependency for external jars, - exists in SoapUI preferences somewhere/somehow? Goal is to remove all jars from soapui/../ext and somehow add dependencies on official.
Sincerely,
Dmitry.
I have thought about this some more: You should be able to roll your own soapui.bat, based on the provided one.
Copy the provided soapui.bat to your desktop.
Modify the variable SOAPUI_HOME to point to your install.
Modify the variable CLASSPATH to include your jars.
Run the modified soapui.bat.

Resources