Skip to content

warmuuh/pactbroker-maven-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pactbroker Maven Plugin

Pactbroker Maven Plugin integrates with PactBroker and allows to upload pacts created by consumer rsp download pacts that are verified against providers.

It also allows to use a git-repository instead of a PactBroker-instance as simplification so no additional infrastructure is needed.

Installation

add on-demand-repository (using https://jitpack.io/)

<pluginRepositories>
	<pluginRepository>
		<id>jitpack.io</id>
		<url>https://jitpack.io</url>
	</pluginRepository>
</pluginRepositories>

or install locally

git clone ...
cd pactbroker-maven-plugin
mvn install

##Usage

###Consumer

Configure plugin in your pom.xml using the upload-pacts goal:

<build>
  <plugins>
    <plugin>
      <groupId>com.github.warmuuh</groupId>
      <artifactId>pactbroker-maven-plugin</artifactId>
      <version>0.0.10</version>
      <executions>
        <execution>
          <id>upload-pacts</id>
          <phase>test</phase>
          <goals><goal>upload-pacts</goal></goals>
          <configuration>
            <brokerUrl>ssh://gitlab/pact-repo.git</brokerUrl>
            <pacts>${project.build.directory}/pacts</pacts>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

###Producer

Configure plugin in your pom.xml. This time, the download-pacts goal is used:

<build>
  <plugins>
    <plugin>
      <groupId>com.github.warmuuh</groupId>
      <artifactId>pactbroker-maven-plugin</artifactId>
      <version>0.0.10</version>
      <executions>
        <execution>
          <id>download-pacts</id>
          <phase>generate-resources</phase>
          <goals><goal>download-pacts</goal></goals>
          <configuration>
            <brokerUrl>ssh://gitlab/pact-repo.git</brokerUrl>
            <pacts>${project.build.testOutputDirectory}/pacts-dependents</pacts>
            <provider>provider</provider>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

###Having consumer and producer in a multi-module project Configure plugin at the parent pom

<build>
  <plugins>
      <plugin>
            <groupId>com.github.warmuuh</groupId>
            <artifactId>pactbroker-maven-plugin</artifactId>
            <version>0.0.10</version>
            <executions>
                <execution>
                    <goals>
                        <goal>upload-pacts</goal>
                    </goals>
                    <phase>none</phase>
                </execution>
                <execution>
                    <id>download-pacts</id>
                    <phase>none</phase>
                    <goals>
                        <goal>download-pacts</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
  </plugins>
</build>

At generate-test-resources phase the relevant provider pacts will be downloaded to the providerPacts directory to be able to verify provider behavior against consumers, meanwhile consumer pacts will be uploaded at the verify phase from the consumerPacts directory which was previously generated by tests. With this approach there is no need for profiles. A simple mvn clean install does the job.

<build>
  <plugins>
    <plugin>
      <groupId>com.github.warmuuh</groupId>
      <artifactId>pactbroker-maven-plugin</artifactId>
      <version>0.0.10</version>
          <executions>
              <execution>
                  <goals>
                      <goal>upload-pacts</goal>
                  </goals>
                  <phase>verify</phase>
                  <configuration>
                    <brokerUrl>ssh://gitlab/pact-repo.git</brokerUrl>
                    <pacts>${project.build.directory}/pacts</pacts>
                  </configuration>
              </execution>
              <execution>
                  <id>download-pacts</id>
                  <phase>generate-test-resources</phase>
                  <goals>
                      <goal>download-pacts</goal>
                  </goals>
                  <configuration>
                    <brokerUrl>ssh://gitlab/pact-repo.git</brokerUrl>
                    <pacts>${project.build.testOutputDirectory}/pacts-dependents</pacts>
                    <provider>provider</provider>
                  </configuration>
              </execution>
          </executions>
    </plugin>
  </plugins>
</build>

If you are using scala-pact from ITV to generate pacts than it generates separate pact file for all the tests. Before you upload it to the broker you might want to group and merge them based on the provider and customer name. Use mergePacts config element to force pact merge before upload to the broker

<build>
  <plugins>
    <plugin>
      <groupId>com.github.warmuuh</groupId>
      <artifactId>pactbroker-maven-plugin</artifactId>
      <version>0.0.10</version>
      <executions>
        <execution>
          <id>upload-pacts</id>
          <goals><goal>upload-pacts</goal></goals>
          <configuration>
            <brokerUrl>ssh://gitlab/pact-repo.git</brokerUrl>
            <pacts>${project.build.directory}/pacts</pacts>
            <mergePacts>true</mergePacts>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

To provide credentials when using git repository while uploading or downloading pacts, use the configuration sections as below:

    <configuration>
      <brokerUrl>https://github.com/pact-repo.git</brokerUrl>
      <pacts>target/pacts-dependents</pacts>
	  <provider>provider</provider>
      <username>user</username>
	  <password>password</password>
    </configuration>

To provide credentials when using a pact broker with HTTP basic auth, use the configuration sections as below:

    <configuration>
      <brokerUrl>https://yourbroker.pact.dius.com.au</brokerUrl>
      <pacts>target/pacts-dependents</pacts>
	  <provider>provider</provider>
      <username>user</username>
	  <password>password</password>
    </configuration>

you can also supply <insecure>true</insecure> to ignore certificate validation