forked from quarkus-qe/quarkus-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coverage for Pact-JVM, in context of this issue: quarkusio/quarkus#9677
- Loading branch information
Showing
6 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
46 changes: 46 additions & 0 deletions
46
test-tooling/pact/src/test/java/io/quarkus/ts/http/pact/ConsumerPactTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
test-tooling/pact/src/test/java/io/quarkus/ts/http/pact/ProviderPactTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\"}"; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
test-tooling/pact/src/test/resources/pacts/TheConsumer-TheProvider.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |