Skip to content

Commit

Permalink
Coverage for Pact-JVM, in context of this issue: quarkusio/quarkus#9677
Browse files Browse the repository at this point in the history
  • Loading branch information
fedinskiy authored and Sgitario committed Sep 7, 2021
1 parent bf6e7e0 commit d9692c6
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,4 +653,9 @@ It covers different usages:
2. from a request scoped service
3. from a REST controller endpoint (using `@RestController)

More information about this extension in https://quarkus.io/guides/spring-cache.
More information about this extension in https://quarkus.io/guides/spring-cache.


### `test-tooling/pact`

Verifies, that quarkus works correctly with third-party tool called Pact-JVM
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,18 @@
<module>scheduling/spring</module>
</modules>
</profile>
<profile>
<id>test-tooling</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>all-modules</name>
</property>
</activation>
<modules>
<module>test-tooling/pact</module>
</modules>
</profile>
<profile>
<id>native</id>
<activation>
Expand Down
43 changes: 43 additions & 0 deletions test-tooling/pact/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus.ts.qe</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>pact</artifactId>
<packaging>jar</packaging>
<name>Quarkus QE TS: Test Tooling: Pact</name>
<properties>
<pact.version>4.0.10</pact.version>
</properties>
<dependencies>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-consumer-junit5</artifactId>
<version>${pact.version}</version>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-consumer-java8</artifactId>
<version>${pact.version}</version>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-junit5</artifactId>
<version>${pact.version}</version>
</dependency>
<!-- Required for native compilation -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.quarkus.ts.http.pact;

import java.util.HashMap;
import java.util.List;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import io.pactfoundation.consumer.dsl.LambdaDsl;
import io.quarkus.test.junit.QuarkusTest;

import au.com.dius.pact.consumer.MessagePactBuilder;
import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
import au.com.dius.pact.consumer.junit5.PactTestFor;
import au.com.dius.pact.consumer.junit5.ProviderType;
import au.com.dius.pact.core.model.annotations.Pact;
import au.com.dius.pact.core.model.messaging.Message;
import au.com.dius.pact.core.model.messaging.MessagePact;

@QuarkusTest
@Tag("QUARKUS-1024")
@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "TheProvider", providerType = ProviderType.ASYNCH)
public class ConsumerPactTest {

@Pact(consumer = "TheConsumer")
public MessagePact createPact(MessagePactBuilder builder) {
var body = LambdaDsl.newJsonBody((it) -> {
it.stringType("payload", "Hello there");
}).build();

return builder
.expectsToReceive("a message with a payload")
.withMetadata(new HashMap<>())
.withContent(body)
.toPact();
}

@Test
void test(List<Message> messages) {
Assertions.assertEquals(1, messages.size());
Assertions.assertEquals("{\"payload\":\"Hello there\"}", messages.get(0).contentsAsString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.quarkus.ts.http.pact;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;

import io.quarkus.test.junit.QuarkusTest;

import au.com.dius.pact.provider.PactVerifyProvider;
import au.com.dius.pact.provider.junit.Provider;
import au.com.dius.pact.provider.junit.loader.PactFolder;
import au.com.dius.pact.provider.junit5.AmpqTestTarget;
import au.com.dius.pact.provider.junit5.PactVerificationContext;
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;

@QuarkusTest
@Tag("QUARKUS-1024")
@Provider("TheProvider")
@PactFolder("src/test/resources/pacts")
public class ProviderPactTest {

@BeforeEach
void before(PactVerificationContext context) {
context.setTarget(new AmpqTestTarget());
}

@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void testTemplate(PactVerificationContext context) {
context.verifyInteraction();
}

@PactVerifyProvider("a message with a payload")
public String verifyMessageForOrder() {
return "{\"payload\": \"somepayload\"}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"consumer": {
"name": "TheConsumer"
},
"provider": {
"name": "TheProvider"
},
"messages": [
{
"description": "a message with a payload",
"metaData": {
"contentType": "application/json"
},
"contents": {
"payload": "thePayload"
},
"matchingRules": {
"body": {
"$.payload": {
"matchers": [
{
"match": "type"
}
],
"combine": "AND"
}
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "3.0.0"
},
"pact-jvm": {
"version": "4.0.6"
}
}
}

0 comments on commit d9692c6

Please sign in to comment.