Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use quarkiverse pact extension #212

Merged
merged 5 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/quarkus-ecosystem-test
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ run_build() {
-Dquarkus.platform.group-id=io.quarkus \
-Dquarkus.platform.version=${QUARKUS_VERSION} \
-Dquarkus.http.host=0.0.0.0 \
-Dmaven.compiler.release=$java_version \
-DrunContractVerificationTests=true \
-DrunConsumerContractTests=true
-Dmaven.compiler.release=$java_version
done
}

Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/simple-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ jobs:
run: |
./mvnw -B clean verify \
-Dquarkus.http.host=0.0.0.0 \
-Dmaven.compiler.release=${{ matrix.java }} \
-DrunContractVerificationTests=true \
-DrunConsumerContractTests=true
-Dmaven.compiler.release=${{ matrix.java }}

native-build-test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -114,7 +112,5 @@ jobs:
run: |
./mvnw -B clean verify -Pnative \
-Dquarkus.http.host=0.0.0.0 \
-Dmaven.compiler.release=${{ matrix.java }} \
-DrunContractVerificationTests=true \
-DrunConsumerContractTests=true
-Dmaven.compiler.release=${{ matrix.java }}

7 changes: 5 additions & 2 deletions rest-fights/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ The contracts are committed into the provider's version control simply for easy

Additionally, the [Pact contract](src/test/resources/pacts/ui-super-heroes-rest-fights.json) is committed into this application's source tree inside the [`src/test/resources/pacts` directory](src/test/resources/pacts).

Pact tests don't currently work with Quarkus dev mode and continuous testing. Therefore, the consumer contract tests ([`HeroConsumerContractTests.java`](src/test/java/io/quarkus/sample/superheroes/fight/client/HeroConsumerContractTests.java) & [`VillainConsumerContractTests.java`](src/test/java/io/quarkus/sample/superheroes/fight/client/VillainConsumerContractTests.java)) are only executed if the `-DrunConsumerContractTests=true` flag is passed. The [contract verification tests](src/test/java/io/quarkus/sample/superheroes/fight/ContractVerificationTests.java) are only executed if the `-DrunContractVerificationTests=true` flag is passed. You could do this when running `./mvnw test`, `./mvnw verify`, or `./mvnw package`.
The Pact consumer contract tests don't currently work with Quarkus dev mode and continuous testing for this project, because of the [test profiles](https://github.com/quarkiverse/quarkus-pact/issues/58).
The consumer contract tests ([`HeroConsumerContractTests.java`](src/test/java/io/quarkus/sample/superheroes/fight/client/HeroConsumerContractTests.java) & [`VillainConsumerContractTests.java`](src/test/java/io/quarkus/sample/superheroes/fight/client/VillainConsumerContractTests.java)) are only executed in 'normal' testing, not continuous testing.

Provider tests do work, with the workaround that the scope of the extension to be more generous than the natural `test` scope.

The consumer contract tests and provider verification tests **ARE** executed during this project's CI/CD processes. They run against any pull requests and any commits back to the `main` branch.

There is a [Quarkus Pact extension](https://github.com/quarkiverse/quarkus-pact) under development aiming to make integration with Pact simple and easy. It will be integrated with this project once it becomes available.
The Pact tests use the [Quarkus Pact extension](https://github.com/quarkiverse/quarkus-pact). This extension is recommended to give the best user experience and ensure compatibility

## Running the Application
First you need to start up all of the downstream services ([Heroes Service](../rest-heroes) and [Villains Service](../rest-villains) - the [Event Statistics Service](../event-statistics) is optional).
Expand Down
17 changes: 6 additions & 11 deletions rest-fights/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<mapstruct.version>1.5.3.Final</mapstruct.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.release>11</maven.compiler.release>
<pact.version>4.4.3</pact.version>
<pact.version>0.2</pact.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
Expand Down Expand Up @@ -159,11 +159,6 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-mockito</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-mock</artifactId>
Expand Down Expand Up @@ -197,16 +192,16 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius.pact.consumer</groupId>
<artifactId>junit5</artifactId>
<groupId>io.quarkiverse.pact</groupId>
<artifactId>quarkus-pact-consumer</artifactId>
<version>${pact.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>junit5</artifactId>
<groupId>io.quarkiverse.pact</groupId>
<artifactId>quarkus-pact-provider</artifactId>
<version>${pact.version}</version>
<scope>test</scope>
<scope>provided</scope> <!-- See https://github.com/quarkiverse/quarkus-pact/issues/28 -->
</dependency>
</dependencies>
<build>
Expand Down
3 changes: 3 additions & 0 deletions rest-fights/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ quarkus.http.port=8082
quarkus.jackson.serialization-inclusion=non-empty
quarkus.http.test-port=0

## Test configuration
quarkus.test.exclude-tags=NotSafeForContinuousTesting

## Mongo
quarkus.mongodb.metrics.enabled=true
quarkus.mongodb.database=fights
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
@QuarkusTest
@Provider("rest-fights")
@PactFolder("pacts")
@EnabledIfSystemProperty(named = "runContractVerificationTests", matches = "true", disabledReason = "runContractVerificationTests system property not set or equals false")
// You could comment out the @PactFolder and above @EnabledIfSystemPropery annotations
// You could comment out the @PactFolder annotation
// if you'd like to use a Pact broker. You'd also un-comment the following 2 annotations
//@PactBroker(url = "https://quarkus-super-heroes.pactflow.io")
//@EnabledIfSystemProperty(named = "pactbroker.auth.token", matches = ".+", disabledReason = "pactbroker.auth.token system property not set")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.github.tomakehurst.wiremock.WireMockServer;

/**
* Quarkus {@link QuarkusTestResourceLifecycleManager} wrapping a {@link WireMockServer}, binding it's base url to both the heros and villains services, and exposing it to tests that want to inject it via {@link InjectWireMock}.
* Quarkus {@link QuarkusTestResourceLifecycleManager} wrapping a {@link WireMockServer}, binding its base url to both the heroes and villains services, and exposing it to tests that want to inject it via {@link InjectWireMock}.
*
* @see InjectWireMock
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.extension.ExtendWith;

import io.quarkus.test.junit.QuarkusTest;
Expand All @@ -20,7 +20,6 @@
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
import au.com.dius.pact.consumer.junit5.PactTestFor;
import au.com.dius.pact.core.model.PactSpecVersion;
import au.com.dius.pact.core.model.V4Pact;
import au.com.dius.pact.core.model.annotations.Pact;

Expand All @@ -29,17 +28,16 @@
*/
@QuarkusTest
@TestProfile(PactConsumerContractTestProfile.class)
@Tag("NotSafeForContinuousTesting") // See https://github.com/quarkiverse/quarkus-pact/issues/58
@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(
providerName = "rest-heroes",
pactVersion = PactSpecVersion.V4,
hostInterface = "localhost",
// Make an assumption and hard-code the Pact MockServer to be running on port 8081
// I don't like it but couldn't figure out any other way
port = "8081"
)
@EnabledIfSystemProperty(named = "runConsumerContractTests", matches = "true", disabledReason = "runConsumerContractTests system property not set or equals false")
public class HeroConsumerContractTests extends HeroClientTestRunner {

@Pact(consumer = "rest-fights")
public V4Pact helloPact(PactDslWithProvider builder) {
return builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.extension.ExtendWith;

import io.quarkus.test.junit.QuarkusTest;
Expand All @@ -20,25 +20,21 @@
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
import au.com.dius.pact.consumer.junit5.PactTestFor;
import au.com.dius.pact.core.model.PactSpecVersion;
import au.com.dius.pact.core.model.V4Pact;
import au.com.dius.pact.core.model.annotations.Pact;

/**
* Pact consumer contract tests for the {@link io.quarkus.sample.superheroes.fight.client.VillainClient}.
*/
@QuarkusTest
@Tag("NotSafeForContinuousTesting") // See https://github.com/quarkiverse/quarkus-pact/issues/58
@TestProfile(PactConsumerContractTestProfile.class)
@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(
providerName = "rest-villains",
pactVersion = PactSpecVersion.V4,
hostInterface = "localhost",
// Make an assumption and hard-code the Pact MockServer to be running on port 8081
// I don't like it but couldn't figure out any other way
port = "8081"
)
@EnabledIfSystemProperty(named = "runConsumerContractTests", matches = "true", disabledReason = "runConsumerContractTests system property not set or equals false")
port = "8081")
public class VillainConsumerContractTests extends VillainClientTestRunner {
@Pact(consumer = "rest-fights")
public V4Pact helloPact(PactDslWithProvider builder) {
Expand Down
9 changes: 3 additions & 6 deletions rest-heroes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,10 @@ As [this README states](src/test/resources/pacts/README.md), contracts generally

One of the main goals of the Superheroes application is to be super simple and just "work" by anyone who may clone this repo. That being said, we can't make any assumptions about where a Pact broker may be or any of the credentials required to access it.

Therefore, the [Pact contract](src/test/resources/pacts/rest-fights-rest-heroes.json) is committed into this application's source tree inside the [`src/test/resources/pacts` directory](src/test/resources/pacts).
Therefore, the [Pact contract](src/test/resources/pacts/rest-fights-rest-heroes.json) is committed into this application's source tree inside the [`src/test/resources/pacts` directory](src/test/resources/pacts). In a realistic
scenario, if a broker wasn't used, the consumer's CI/CD would commit the contracts into this repository's source control.

Additionally, Pact provider verification tests don't currently work with Quarkus dev mode and continuous testing. Therefore, the [contract verification tests](src/test/java/io/quarkus/sample/superheroes/hero/ContractVerificationTests.java) are only executed if the `-DrunContractVerificationTests=true` flag is passed. You could do this when running `./mvnw test`, `./mvnw verify`, or `./mvnw package`.

The provider verification tests **ARE** executed during this project's CI/CD processes. They run against any pull requests and any commits back to the `main` branch.

There is a [Quarkus Pact extension](https://github.com/quarkiverse/quarkus-pact) under development aiming to make integration with Pact simple and easy. It will be integrated with this project once it becomes available.
The Pact tests use the [Quarkus Pact extension](https://github.com/quarkiverse/quarkus-pact). This extension is recommended to give the best user experience and ensure compatibility

## Running the Application
The application runs on port `8083` (defined by `quarkus.http.port` in [`application.yml`](src/main/resources/application.yml)).
Expand Down
8 changes: 4 additions & 4 deletions rest-heroes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<mapstruct.version>1.5.3.Final</mapstruct.version>
<maven.compiler.release>11</maven.compiler.release>
<pact.version>4.4.3</pact.version>
<pact.version>0.2</pact.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
Expand Down Expand Up @@ -127,10 +127,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>junit5</artifactId>
<groupId>io.quarkiverse.pact</groupId>
<artifactId>quarkus-pact-provider</artifactId>
<version>${pact.version}</version>
<scope>test</scope>
<scope>provided</scope> <!-- See https://github.com/quarkiverse/quarkus-pact/issues/28 -->
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
@QuarkusTest
@Provider("rest-heroes")
@PactFolder("pacts")
@EnabledIfSystemProperty(named = "runContractVerificationTests", matches = "true", disabledReason = "runContractVerificationTests system property not set or equals false")
// You could comment out the @PactFolder and above @EnabledIfSystemPropery annotations
// You could comment out the @PactFolder annotation
// if you'd like to use a Pact broker. You'd also un-comment the following 2 annotations
//@PactBroker(url = "https://quarkus-super-heroes.pactflow.io")
//@EnabledIfSystemProperty(named = "pactbroker.auth.token", matches = ".+", disabledReason = "pactbroker.auth.token system property not set")
Expand Down
11 changes: 3 additions & 8 deletions rest-villains/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,10 @@ The `rest-villains` application is a [Pact _Provider_](https://docs.pact.io/prov

As [this README states](src/test/resources/pacts/README.md), contracts generally should be hosted in a [Pact Broker](https://docs.pact.io/pact_broker) and then automatically discovered in the provider verification tests.

One of the main goals of the Superheroes application is to be super simple and just "work" by anyone who may clone this repo. That being said, we can't make any assumptions about where a Pact broker may be or any of the credentials required to access it.
Therefore, the [Pact contract](src/test/resources/pacts/rest-fights-rest-heroes.json) is committed into this application's source tree inside the [`src/test/resources/pacts` directory](src/test/resources/pacts). In a realistic
scenario, if a broker wasn't used, the consumer's CI/CD would commit the contracts into this repository's source control.

Therefore, the [Pact contract](src/test/resources/pacts/rest-fights-rest-villains.json) is committed into this application's source tree inside the [`src/test/resources/pacts` directory](src/test/resources/pacts).

Additionally, Pact provider verification tests don't currently work with Quarkus dev mode and continuous testing. Therefore, the [contract verification tests](src/test/java/io/quarkus/sample/superheroes/villain/ContractVerificationTests.java) are only executed if the `-DrunContractVerificationTests=true` flag is passed. You could do this when running `./mvnw test`, `./mvnw verify`, or `./mvnw package`.

The provider verification tests **ARE** executed during this project's CI/CD processes. They run against any pull requests and any commits back to the `main` branch.

There is a [Quarkus Pact extension](https://github.com/quarkiverse/quarkus-pact) under development aiming to make integration with Pact simple and easy. It will be integrated with this project once it becomes available.
The Pact tests use the [Quarkus Pact extension](https://github.com/quarkiverse/quarkus-pact). This extension is recommended to give the best user experience and ensure compatibility

## Running the Application
The application runs on port `8084` (defined by `quarkus.http.port` in [`application.properties`](src/main/resources/application.properties)).
Expand Down
8 changes: 4 additions & 4 deletions rest-villains/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<mapstruct.version>1.5.3.Final</mapstruct.version>
<maven.compiler.release>11</maven.compiler.release>
<pact.version>4.4.3</pact.version>
<pact.version>0.2</pact.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
Expand Down Expand Up @@ -127,10 +127,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>junit5</artifactId>
<groupId>io.quarkiverse.pact</groupId>
<artifactId>quarkus-pact-provider</artifactId>
<version>${pact.version}</version>
<scope>test</scope>
<scope>provided</scope> <!-- See https://github.com/quarkiverse/quarkus-pact/issues/28 -->
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
@QuarkusTest
@Provider("rest-villains")
@PactFolder("pacts")
@EnabledIfSystemProperty(named = "runContractVerificationTests", matches = "true", disabledReason = "runContractVerificationTests system property not set or equals false")
// You could comment out the @PactFolder and above @EnabledIfSystemPropery annotations
// You could comment out the @PactFolder annotations
// if you'd like to use a Pact broker. You'd also un-comment the following 2 annotations
//@PactBroker(url = "https://quarkus-super-heroes.pactflow.io")
//@EnabledIfSystemProperty(named = "pactbroker.auth.token", matches = ".+", disabledReason = "pactbroker.auth.token system property not set")
Expand Down