Denys
02/18/2025, 3:46 PM@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "P01823-TS-Trade-Store", pactVersion = PactSpecVersion.V4, providerType = ProviderType.SYNCH_MESSAGE)
class GetTradesByFilterProductTypeFXFWDTest {
ManagedChannel channel;
@BeforeEach
void setUp(MockServer mockServer) {
System.setProperty("pact_do_not_track", "true");
}
////////////////// 1. GetTradesByFilter product types
@Pact(consumer = "P01819-ipa-mi")
public V4Pact tradesByFilterProductTypeFXFWD(PactBuilder builder) {
return builder
.usingPlugin("protobuf")
.expectsToReceive("a get trade by filter request", "core/interaction/synchronous-message")
.with(Map.of(
"pact:proto", filePath("proto/tsServiceV2.proto"),
"pact:content-type", "application/grpc",
"pact:proto-service", "TradeStoreService/GetTradesByFilter",
"pact:protobuf-config", Map.of(
"additionalIncludes",
List.of(filePath("proto/tsService.proto"))),
// Details on the request message
"request", Map.of(
"productTypes",
Map.of("value",
"matching(equalTo, 'FXFWD')")),
// Details on the response
"response",
Map.of("trade_key",
Map.of("product_type", "matching(equalTo, 'FXFWD')")))
).toPact();
}
@Test
@PactTestFor(pactMethod = "tradesByFilterProductTypeFXFWD")
@MockServerConfig(implementation = MockServerImplementation.Plugin, registryEntry = "protobuf/transport/grpc")
void testTradesByFilterProductTypeFXFWD(MockServer mockServer, V4Interaction.SynchronousMessages interaction) throws InvalidProtocolBufferException, InterruptedException {
boolean success = false;
ManagedChannel channel = ManagedChannelBuilder.forTarget("127.0.0.1:" + mockServer.getPort())
.usePlaintext()
.build();
try {
TradeStoreServiceGrpc.TradeStoreServiceBlockingStub stub = TradeStoreServiceGrpc.newBlockingStub(channel);
ts.api.TsServiceV2.TradeFilter tradeFilter = ts.api.TsServiceV2.TradeFilter.parseFrom(interaction.getRequest().getContents().getValue());
Iterator<TsService.Trade> responseTrade = stub.getTradesByFilter(tradeFilter);
assertThat(responseTrade).as("getTradeByFilter is null").isNotNull();
} finally {
if (!success) {
channel.awaitTermination(10, TimeUnit.SECONDS);
channel.shutdown();
}
}
}
@Pact(consumer = "P01819-ipa-mi")
public V4Pact tradesByFilterProductTypeFXFWDONE(PactBuilder builder) {
return builder
.usingPlugin("protobuf")
.expectsToReceive("a get trade by filter request", "core/interaction/synchronous-message")
.with(Map.of(
"pact:proto", filePath("proto/tsServiceV2.proto"),
"pact:content-type", "application/grpc",
"pact:proto-service", "TradeStoreService/GetTradesByFilter",
"pact:protobuf-config", Map.of(
"additionalIncludes",
List.of(filePath("proto/tsService.proto"))),
// Details on the request message
"request", Map.of(
"productTypes",
Map.of("value",
"matching(equalTo, 'FXFWD')")),
// Details on the response
"response",
Map.of("trade_key",
Map.of("product_type", "matching(equalTo, 'FXFWD')")))
).toPact();
}
@Test
@PactTestFor(pactMethod = "tradesByFilterProductTypeFXFWDONE")
@MockServerConfig(implementation = MockServerImplementation.Plugin, registryEntry = "protobuf/transport/grpc")
void testTradesByFilterProductTypeFXFWDONE(MockServer mockServer, V4Interaction.SynchronousMessages interaction) throws InvalidProtocolBufferException, InterruptedException {
boolean success = false;
ManagedChannel channel = ManagedChannelBuilder.forTarget("127.0.0.1:" + mockServer.getPort())
.usePlaintext()
.build();
try {
TradeStoreServiceGrpc.TradeStoreServiceBlockingStub stub = TradeStoreServiceGrpc.newBlockingStub(channel);
ts.api.TsServiceV2.TradeFilter tradeFilter = ts.api.TsServiceV2.TradeFilter.parseFrom(interaction.getRequest().getContents().getValue());
Iterator<TsService.Trade> responseTrade = stub.getTradesByFilter(tradeFilter);
assertThat(responseTrade).as("getTradeByFilter is null").isNotNull();
} finally {
if (!success) {
channel.awaitTermination(10, TimeUnit.SECONDS);
channel.shutdown();
}
}
}
}
After running all class I have an error:
2025-02-18 17:34:46,081 ERROR [main] [:] io.pact.plugins.jvm.core.DefaultPluginManager: Failed to initialise the plugin
io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:351)
at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:332)
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:174)
at io.pact.plugin.PactPluginGrpc$PactPluginBlockingStub.initPlugin(PactPluginGrpc.java:641)
at io.pact.plugins.jvm.core.DefaultPluginManager.initPlugin$lambda$37(PluginManager.kt:913)
at io.pact.plugins.jvm.core.DefaultPactPlugin.withGrpcStub(PluginManager.kt:267)
at io.pact.plugins.jvm.core.DefaultPluginManager.initPlugin(PluginManager.kt:913)
at io.pact.plugins.jvm.core.DefaultPluginManager.tryInitPlugin(PluginManager.kt:892)
at io.pact.plugins.jvm.core.DefaultPluginManager.initialisePlugin(PluginManager.kt:866)
at io.pact.plugins.jvm.core.DefaultPluginManager.loadPlugin(PluginManager.kt:419)
at au.com.dius.pact.consumer.dsl.PactBuilder.usingPlugin(PactBuilder.kt:113)
at au.com.dius.pact.consumer.dsl.PactBuilder.usingPlugin$default(PactBuilder.kt:110)
at au.com.dius.pact.consumer.dsl.PactBuilder.usingPlugin(PactBuilder.kt)
at com.ing.ipami.pact.product_type.GetTradesByFilterProductTypeFXFWDTest.tradesByFilterProductTypeFXFWDONE(GetTradesByFilterProductTypeFXFWDTest.java:101)
Caused by: io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: getsockopt: /[00000001]52748
Caused by: java.net.ConnectException: Connection refused: getsockopt
Process finished with exit code 0
protobuf plugin V 0.5.4 is installed on my laptop
Do you have any ideas why after running tested class PACT framework generated only one tested method inside contract/.json file?
Thanksvicky
02/19/2025, 12:19 PMHaritima Haritima
02/19/2025, 5:01 PMBas Dijkstra
02/24/2025, 7:25 AMShrinivas Khawase
02/24/2025, 8:52 AMau.com.dius.pact.consumer:junit Version 4.6.14
but we often get the error mentioned below which blocks our pipeline , has anyone else faced this ?Its not consistent but occurs randomly
cc @Sitaram Appalla @Ramesh Kumar
Failed to transform java-semver-0.9.0.jar (com.github.zafarkhaja:java-semver:0.9.0) to match attributes {artifactType=android-classes-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Could not find java-semver-0.9.0.jar (com.github.zafarkhaja:java-semver:0.9.0).
Searched in the following locations:
<https://jitpack.io/com/github/zafarkhaja/java-semver/0.9.0/java-semver-0.9.0.jar>
Oleksandr Verdiev
02/24/2025, 9:58 AM"yyyy-MM-dd'T'HH:mm:ssZ"
"yyyy-MM-dd'T'HH:mm:ss.SSZ"
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
...
"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSZ"
I have tried these so far:
return new PactDslJsonBody()
.object("Data", looksLike()
.uuid("ConsentId")
.datetime("CreationDateTime", INSTANT_ISO_DATETIME_FORMAT, Instant.now())
// "yyyy-MM-dd'T'HH:mm:ss[.[SSSSSSSSS][SSSSSSSS][SSSSSSS][SSSSSS][SSSSS][SSSS][SSS][SS][S]]'Z'";
// static final String INSTANT_ISO_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSSZ";
// static final String INSTANT_ISO_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss[.SSSSSSSSS]Z";
static final String INSTANT_ISO_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss(.SSSSSSSSS)?Z";
Paul Sobocinski
02/24/2025, 7:00 PMprovider.getUrl()
is returning null
, which in turn causes the test to fail before the ConsumerClient
is even invoked.
I have it set up the test and example its own repo here. The full error message I'm getting follows:
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running exampleclients.ExampleJavaConsumerPactRuleTest
Provider URL: null
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.027 s <<< FAILURE! - in exampleclients.ExampleJavaConsumerPactRuleTest
[ERROR] runTest(exampleclients.ExampleJavaConsumerPactRuleTest) Time elapsed: 0.017 s <<< FAILURE!
java.lang.AssertionError: Provider URL is null! Aborting test.
at exampleclients.ExampleJavaConsumerPactRuleTest.runTest(ExampleJavaConsumerPactRuleTest.java:57)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] ExampleJavaConsumerPactRuleTest.runTest:57 Provider URL is null! Aborting test.
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
Versions used: JDK 1.8
; JUnit 4.8.2
; Pact-JVM 4.1.43
Kusuma Guntamadugu
02/25/2025, 4:15 AMval pactBody = PactDslJsonBody()
.stringMatcher("test", "^(test1|test2)$")
Przemyslaw Boszczyk
03/04/2025, 10:34 AMparameters
field is a Map<String, String> of undefined size and fields.
{
"id": "string"
"parameters": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
}
}
I'm banging my head how to tackle it:
@Pact(consumer = CONSUMER)
RequestResponsePact pact(PactDslWithProvider builder) {
return builder
.uponReceiving("Post message")
.path("/api/messages")
.method("POST")
.body(newJsonBody(body -> {
body.stringType("id", "example_id");
// body.object("parameters", values -> values.eachLike())
}).build())
.matchHeader("Content-Type", "application/json.*", "application/json")
.willRespondWith()
.status(200)
.toPact();
}
Martin Mineo
03/07/2025, 1:16 PMRuud Welling
03/14/2025, 11:10 AM@PactVerifyProvider("A command message")
public MessageAndMetadata processCommand(MessageContents messageContents) {
var jsonMessage = messageContents.getContents().valueAsString();
// this json message does not have the provider state applied
// instead it contains the example value provided by the consumer...
}
I tried to look for examples in the pact SDK, but could not really find any. Am I doing this in the right way? Is provider state supported in message pacts?Neha Munjal
03/14/2025, 11:47 PMRuud Welling
03/19/2025, 4:36 PM@Test
@PactTestFor(pactMethod = "mySyncMessagePact")
void mySyncMessagePact(V4Interaction.SynchronousMessages interaction) {
String request = "{}"; // 1: should call a method that produces the request
// 2: Validate that the request is okay according to the pact
// 3: Validate that the response message can be handled
}
How do I validate that the request message is compliant with the pact that I specified?
After looking at the library code I could not find a standard utility that allows me to easily validate thisRyan Quinn
03/25/2025, 4:19 AM@AllowOverridePactUrl
annotation set, how do I run that test class as part of my regular pipeline? It works fine when I get a request from a webhook, but I don't know how to create the appropriate URLs when running from my build pipeline. Am I confused about something?Chandramani Jha
03/26/2025, 1:22 PMSlackbot
03/26/2025, 1:22 PMErich Zimmerman
03/27/2025, 3:34 PM{
"plans": {
"ABCD32": {
"idRequired": true,
"ids": [
"1234"
]
}
}
}
I'm trying to use object(<name>)
for this, but the name isn't generally predictable.
rootResponseObject.object("plans", (plans) ->
plans.object("??????", (plan) -> {
ratePlan.booleanType("idRequired", true);
ratePlan.array("ids", (item) -> item.stringType("12345"));
})
);
I think I'm a bit confused on when we want things to be more general, and when "test by example" is the right way to go. Since I control the request and data, should I just match to that exact string as the result that fulfills the example?Adrien DEVILLERS
03/28/2025, 10:41 AMRuth
04/08/2025, 9:01 AMjava.lang.IllegalAccessException: class kotlin.reflect.jvm.internal.calls.CallerImpl$FieldGetter cannot access a member of class org.joda.time.LocalDate with modifiers "private final"
kotlin.reflect.full.IllegalCallableAccessException: java.lang.IllegalAccessException: class kotlin.reflect.jvm.internal.calls.CallerImpl$FieldGetter cannot access a member of class org.joda.time.LocalDate with modifiers "private final"
at kotlin.reflect.jvm.internal.KCallableImpl.call
Any idea what I can do? Can I use my own serializer, eg. objectMapper?Bas Dijkstra
04/08/2025, 2:11 PMmvn
, and because my provider is a Spring service, this works fine:
mvn clean "-Dpact.verifier.publishResults=true" "-Dpact.provider.version=1.0.0-address-ee07f8c04721b90be743fc1c08946663f01e6e46" test
However, I now also want to list the provider branch, but when I try this (following the docs):
mvn clean "-Dpact.verifier.publishResults=true" "-Dpact.provider.version=1.0.0-address-ee07f8c04721b90be743fc1c08946663f01e6e46" "-Dpactbroker.providerBranch=main" test
It does not record the provider branch. Any ideas? Is this even important? I know I will need it in the next step, when I'll introduce pending pacts...Shaiju B
04/21/2025, 4:02 AM<dependency>
<groupId>au.com.dius.pact.consumer</groupId>
<artifactId>junit5</artifactId>
<version>4.3.6</version>
<scope>test</scope>
</dependency>
Class
@au.com.dius.pact.consumer.junit5.Pact
Any suggestion on how I could resolve this ?Truth Opaleye
04/23/2025, 10:28 PMRishav Singh
05/14/2025, 3:49 PMjava.lang.UnsupportedOperationException: Method createPact does not conform required method signature 'public au.com.dius.pact.core.model.V4Pact xxx(PactBuilder builder)'
at au.com.dius.pact.consumer.junit.JUnitTestSupport.conformsToSignature(JUnitTestSupport.kt:35)
at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.lookupPact(PactConsumerTestExt.kt:504)
at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.setupPactForTest(PactConsumerTestExt.kt:270)
at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.setupMockServerForProvider(PactConsumerTestExt.kt:248)
at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.beforeTestExecution(PactConsumerTestExt.kt:223)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Simon Raess
05/16/2025, 1:15 PMRishav Singh
05/19/2025, 1:24 PMjava.lang.AssertionError: The following methods annotated with @Pact were not executed during the test: RulesApiConsumerTest.createPactFor200
If these are currently a work in progress, add a @Disabled annotation to the method
I don't see this error when I run them together
I have also used PactTestFor
to categorize the tests with their respective method inside my test classJames P
05/20/2025, 3:57 PMRequest to path '**********************************************contracts/publish' failed with HTTP response 500
JSON Response:
{
"error": {
"message": "source sequence is illegal/malformed utf-8",
"reference": "YeJQYFKhHV"
}
}
I think its related to use using the .matchQuery("version", "1.0.0")
as the value become encoded and then shows as "1\uB0D60\uB3DA0"
in the contract. We also have a header using .matchHeader("header", ".*")
which becomes encoded itself and then appears in the broker as "屏啾"
. We are publishing using the pact gradle plugin and the command ./gradlew pactPublish
. Weirdly though, the pipeline failed twice to publish and then with a retry for a third time it passed. I have suggested to the team to use encodedQuery
and to change the header value as its not important for the service we are using but I’m curious to know why it would fail to publish but then eventually pass with no changes, is there some sort of race condition there?GitHub
05/23/2025, 12:10 AMDeepak Chandh
05/26/2025, 12:09 PMKatrin Aleinik
06/10/2025, 3:09 PMImran Khan
06/16/2025, 11:45 AMpact.rootDir
and other configurations, but I’m still facing the same issue.
Even after adding sleep
before and after running the test cases, the tests pass, but the Pact contract file is not being generated.
Any help or pointers on how to resolve this would be greatly appreciated. Thanks in advance!
Logs when running TestCase (also looked for the path, by adding a print statement - but failed)
bazel test --nocache_test_results //access-control/contracts/openapi/v1:AccessControlConsumerPactTest
INFO: Invocation ID: 16bab404-9cf2-4e69-88d9-c46f58ef4b02
INFO: Analyzed target //access-control/contracts/openapi/v1:AccessControlConsumerPactTest (0 packages loaded, 252 targets configured).
INFO: Found 1 test target...
INFO: From Testing //access-control/contracts/openapi/v1:AccessControlConsumerPactTest:
==================== Test output for //access-control/contracts/openapi/v1:AccessControlConsumerPactTest:
OpenJDK 64-Bit Server VM warning: Ignoring option --illegal-access=debug; support was removed in 17.0
JUnit4 Test Runner
WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by com.google.testing.junit.runner.junit4.JUnit4Runner (file:/private/var/tmp/_bazel_imrankhan/b141c088e4409f9b6c4d0f13116258fa/external/remote_java_tools/java_tools/Runner_deploy.jar)
WARNING: Please consider reporting this to the maintainers of com.google.testing.junit.runner.junit4.JUnit4Runner
WARNING: System::setSecurityManager will be removed in a future release
.SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See <http://www.slf4j.org/codes.html#StaticLoggerBinder> for further details.
Pact files will be written to: /private/var/tmp/_bazel_imrankhan/b141c088e4409f9b6c4d0f13116258fa/sandbox/darwin-sandbox/28/execroot/harness_monorepo/bazel-out/darwin_arm64-fastbuild/bin/access-control/contracts/openapi/v1/AccessControlConsumerPactTest.runfiles/harness_monorepo/pacts
.Pact files will be written to: /private/var/tmp/_bazel_imrankhan/b141c088e4409f9b6c4d0f13116258fa/sandbox/darwin-sandbox/28/execroot/harness_monorepo/bazel-out/darwin_arm64-fastbuild/bin/access-control/contracts/openapi/v1/AccessControlConsumerPactTest.runfiles/harness_monorepo/pacts
.Pact files will be written to: /private/var/tmp/_bazel_imrankhan/b141c088e4409f9b6c4d0f13116258fa/sandbox/darwin-sandbox/28/execroot/harness_monorepo/bazel-out/darwin_arm64-fastbuild/bin/access-control/contracts/openapi/v1/AccessControlConsumerPactTest.runfiles/harness_monorepo/pacts
<http://localhost:60308/users/123>
Time: 0.957
OK (3 tests)
WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by com.google.testing.junit.runner.util.GoogleTestSecurityManager (file:/private/var/tmp/_bazel_imrankhan/b141c088e4409f9b6c4d0f13116258fa/external/remote_java_tools/java_tools/Runner_deploy.jar)
WARNING: Please consider reporting this to the maintainers of com.google.testing.junit.runner.util.GoogleTestSecurityManager
WARNING: System::setSecurityManager will be removed in a future release
BazelTestRunner exiting with a return value of 0
JVM shutdown hooks (if any) will run now.
The JVM will exit once they complete.
-- JVM shutdown starting at 2025-06-16 11:40:14 --
================================================================================
Target //access-control/contracts/openapi/v1:AccessControlConsumerPactTest up-to-date:
/private/var/tmp/_bazel_imrankhan/b141c088e4409f9b6c4d0f13116258fa/execroot/harness_monorepo/bazel-out/darwin_arm64-fastbuild/bin/access-control/contracts/openapi/v1/AccessControlConsumerPactTest.jar
/private/var/tmp/_bazel_imrankhan/b141c088e4409f9b6c4d0f13116258fa/execroot/harness_monorepo/bazel-out/darwin_arm64-fastbuild/bin/access-control/contracts/openapi/v1/AccessControlConsumerPactTest
INFO: Elapsed time: 3.016s, Critical Path: 2.82s
INFO: 2 processes: 1 internal, 1 darwin-sandbox.
INFO: Build completed successfully, 2 total actions
//access-control/contracts/openapi/v1:AccessControlConsumerPactTest PASSED in 2.7s
Executed 1 out of 1 test: 1 test passes.