0
votes

I have written a spring cloud contract in an server application running spring boot. This part is correctly generating the stubs into my local repo. Now I want to verify this contract from a client application running Spring 3.1 and Jersey.

As a workaround I evaluated the possibility of manually unpacking the stub jar into the mapping file and launch the verification using WireMockClassRule as it is done in this link

Is there some other easy way of reusing the AutoConfigureStubRunner to do this work for me, and still don't need to add a dependency to Spring Boot?

EDIT: I have been able to download and unpack stubs jars using maven dependency:unpack plugin, and later to run them using wiremock (similar to what is done here). The only problem that I still need to solve is how to dynamically pick the stub latest version. By using the maven dependency plugin I always need to provide the artifact version.

1
If you want to run the thing as a separate process you can use the Stub Runner Boot (cloud.spring.io/spring-cloud-contract/…) and allow it to download all stuff. If not you can use the JUnit Rule (I haven't checked it against Spring 3.1 though) - cloud.spring.io/spring-cloud-contract/… .Marcin Grzejszczak
Thanks a lot Marcin. I end up using the Jersey approach and used the dependency:unpack with LATEST in version to always download the last stub versionjesantana
Can you describe your approach in more depth as an answer to this issue? That way it will be profitable for other people.Marcin Grzejszczak
I finally did it, sorry for the delay.jesantana

1 Answers

0
votes

Let's suppose that need to consume a stub jar at the client. The stub among othet things has a json containing the data that your contract provides to do the integration test. This json has a format used by wiremock to publish an endpoint similar to our real backend. So the following steps need to be taken:

Download the stub jar from the repo to your local machine and copy it to wiremock internal folder

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-dependency-plugin</artifactId>
 <version>3.0.1</version>
 <executions>
  <execution>
   <phase>generate-test-resources</phase>
   <goals>
    <goal>unpack</goal>
   </goals>
   <configuration>
    <artifactItems>
     <artifactItem>
      <groupId>com.yourbackend.contract</groupId>
      <artifactId>contract-service</artifactId>
      <version>LATEST</version>
      <type>jar</type>
      <classifier>stubs</classifier>
     </artifactItem>
    </artifactItems>
    <overWriteReleases>true</overWriteReleases>
    <overWriteSnapshots>true</overWriteSnapshots>
    <excludeTransitive>true</excludeTransitive>
    <includes>META-INF/**/mappings/**</includes>
    <outputDirectory>${basedir}/target/mappings</outputDirectory>
   </configuration>
  </execution>
 </executions>
</plugin>

Note here that LATEST is set as the version of the stub to make sure that always the last stub jar is retrieved.

Start wiremock server in localhost

<dependency>
    <groupId>com.github.tomakehurst</groupId>
    <artifactId>wiremock</artifactId>
    <scope>test</scope>
</dependency>

and then in the test

@ClassRule
WireMockClassRule wireMockRule = new WireMockClassRule(port);

You are set, do the http calls in the tests