Pascal Brewing
03/07/2024, 5:44 PMCole Taylor
03/12/2024, 10:41 PMAllen Ayala
03/13/2024, 1:31 PMMartin Gallauner
03/14/2024, 10:45 AMCI
flag? I have no clue where that is coming fromMartin Gallauner
03/14/2024, 12:57 PMpactbroker.
properties are used correctly (pact is fetched from broker)
But all the pact.
properties are ignored (verification is not published)Martin Gallauner
03/14/2024, 2:49 PMPactBrokerConsumerVersionSelectors
as linked below?Martin Gallauner
03/14/2024, 2:50 PMCole Taylor
03/15/2024, 5:14 PMerror: cannot find symbol
symbol: class PactBrokerAuth
Yair Shkedi
03/18/2024, 7:43 PMEric Deandrea
03/18/2024, 7:44 PMprotobuf
plugin on the comsumer side, but I am not having much success. My consumer is a consumer of multiple different services - 3 REST and 1 gRPC.
My locationservice-v1.proto
file is in src/main/proto
and looks like this:
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.quarkus.sample.superheroes.location.grpc";
option java_outer_classname = "LocationServiceProto";
package io.quarkus.sample.superheroes.location.v1;
enum LocationType {
PLANET = 0;
CITY = 1;
}
message Location {
string name = 1;
string description = 2;
string picture = 3;
LocationType type = 4;
}
message RandomLocationRequest {}
message LocationsList {
repeated Location locations = 1;
}
message HelloRequest {}
message HelloReply {
string message = 1;
}
service Locations {
rpc GetRandomLocation(RandomLocationRequest) returns (Location) {}
rpc Hello(HelloRequest) returns (HelloReply) {}
}
The annotations on my test class are as follows:
@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(pactVersion = PactSpecVersion.V4)
@MockServerConfig(
providerName = "rest-heroes",
port = "9080",
hostInterface = "localhost",
implementation = MockServerImplementation.JavaHttpServer
)
@MockServerConfig(
providerName = "rest-villains",
port = "9083",
hostInterface = "localhost",
implementation = MockServerImplementation.JavaHttpServer
)
@MockServerConfig(
providerName = "rest-narration",
port = "9085",
hostInterface = "localhost",
implementation = MockServerImplementation.JavaHttpServer
)
@MockServerConfig(
providerName = "grpc-locations",
port = "9086", // Tried without this too without any change
hostInterface = "localhost",
implementation = MockServerImplementation.Plugin,
registryEntry = "protobuf/transport/grpc"
)
My pact method that creates the contract is
@Pact(consumer = "rest-fights", provider = "grpc-locations")
public V4Pact helloLocationsPact(PactBuilder builder) {
return builder
.usingPlugin("protobuf")
.expectsToReceive("A hello request", "core/interaction/synchronous-message")
.with(Map.of(
"pact:proto", filePath("src/main/proto/locationservice-v1.proto"),
"pact:content-type", "application/grpc",
"pact:proto-service", "Locations/Hello",
"request", Map.of(),
"response", Map.of(
"message", "matching(regex, '.+', '%s')".formatted(DEFAULT_HELLO_LOCATION_RESPONSE)
)
))
.toPact();
}
And my JUnit test method is
@Test
@PactTestFor(pactMethods = "helloLocationsPact", providerType = ProviderType.SYNCH_MESSAGE)
void helloLocationsSuccess() {
var message = this.fightService.helloLocations() // fightService is a bean thats autowired into the class
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertSubscribed()
.awaitItem(Duration.ofSeconds(5))
.getItem();
assertThat(message)
.isNotNull();
}
I’ll post the error I’m receiving in a nested comment as slack won’t let me paste the whole thing hereKranthi Mudireddy
03/19/2024, 12:15 PMRuth
03/19/2024, 2:27 PM@BeforeEach
void setup(PactVerificationContext pactContext) throws Exception {
when(mock.doSomething()).thenReturn(null);
Controller controller = new Controller();
//setup
pactContext.setTarget(new MockMvcTestTarget(standaloneSetup(controller).addFilters(new ContextPathMockFilter("/foo")).build()));
}
@State({"some state"})
void produkanbieterDoesNotExist(Map<String, Object> providerStateParameters) {
String id = (String) providerStateParameters.get("id");
when(mock.doSomething()).thenThrow(new RuntimeException(id));
}
I still get null as a result when using this state. I debugged it and it does enter the state method, but it does not seem to override it
mockito version: 4.0.0
pact version: 4.1.39
junit version: 5.7.1
java version: 1.8Dominic Behrig
03/19/2024, 7:26 PMJose Maria
03/21/2024, 5:12 PMRatna Jenisha
03/22/2024, 9:53 AMimport au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.consumer.junit.PactProviderRule;
import au.com.dius.pact.consumer.junit.PactVerification;
import au.com.dius.pact.core.model.RequestResponsePact;
import au.com.dius.pact.core.model.annotations.Pact;
import org.junit.Rule;
import org.junit.jupiter.api.Test;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
/**
* ConsumerApplicationTests
*/
public class ConsumerApplicationTests {
@Rule
public PactProviderRule mockProvider = new PactProviderRule("test_provider", "localhost", 9000, this);
@Pact(provider = "test_provider", consumer = "test_consumer")
public RequestResponsePact createPact(PactDslWithProvider builder) {
return builder
.given("test state")
.uponReceiving("ExampleJavaConsumerPactRuleTest test interaction")
.path("/")
.method("GET")
.willRespondWith()
.status(200)
.body("{\"responsetext\": true}")
.toPact();
}
@Test
@PactVerification("test_provider")
public void runTest() {
RestTemplate restCall = new RestTemplate();
String url = mockProvider.getConfig().url();
ResponseEntity<String> res = restCall.getForEntity(url + "/", String.class);
Object body = res.getBody();
}
}
Gradle file:
buildscript {
dependencies {
classpath 'au.com.dius.pact.provider:gradle:4.1.7'
}
}
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
}
repositories {
mavenCentral()
}
group = 'com.consumerApplication'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'au.com.dius:pact-jvm-consumer-junit:4.0.10'
testImplementation 'au.com.dius:pact-jvm-provider-junit:4.0.10'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'au.com.dius.pact.consumer:junit:4.6.7'
testImplementation('junit:junit:4.13.2')
}
test{
useJUnitPlatform()
}
Stack Error:
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:9000/": Connection refused: connect
at org.springframework.web.client.RestTemplate.createResourceAccessException(RestTemplate.java:915)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:895)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:790)
at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:431)
.......
Caused by: java.net.ConnectException: Connection refused: connect
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:568)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:593)
at java.base/java.net.Socket.connect(Socket.java:633)
at java.base/java.net.Socket.connect(Socket.java:583)
.......
Connection refused: connect
java.net.ConnectException: Connection refused: connect
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:568)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:593)
at java.base/java.net.Socket.connect(Socket.java:633)
.........
What am i missing?Ashley Gautama
03/22/2024, 10:08 AMSugi S
03/25/2024, 6:27 PMAntonio
03/26/2024, 2:02 PMPactDslJsonArray()
.object()
.stringType("budgetVersionId")
.booleanType("isLastVersion")
.integerType("orderNumber")
[...]
.closeObject
[...]
My expectation is that those methods will only bind the test to the type, in fact documentation hints at this being the case, however I see in the JSON interaction generated that the values are set to "string", "true" and 100 respectively. And that is how the (kotlin) source method seems to work, in fact when I peek I can see:
return integerType(name, 100 as Int)
As a result, my test fails because the JSON interaction field names with values:
"budgetVersionId": "string",
"isLastVersion": true,
"orderNumber": 100
So my question is: is this a bug? Unlikely I would say, so my next questions are: what am I doing wrong? How can I check that a returned has specific fields of specifc types rather than actual values?
Thank you in advance for your helpGitHub
03/27/2024, 4:15 AMRuth
03/28/2024, 10:34 AM@Pact(consumer = CONSUMER, provider = "Provider")
RequestResponsePact getProvider(PactDslWithProvider builder) {
return builder
.uponReceiving("call provider")
.method("POST")
.path("/graphql")
.headers("Content-Type", "application/json")
.body(new PactDslJsonBody()
.stringValue("query", "query")
.object("variables", new PactDslJsonBody()
.stringValue("variable", "foo")))
.willRespondWith()
.status(200)
.body(new PactDslJsonBody()
.object("data", new PactDslJsonBody()
.object("object", new PactDslJsonBody()
.object("object", new PactDslJsonBody()
.minArrayLike("array", 0, 2)
.object("objectArray", new PactDslJsonBody()
.stringType("id", "produktanbieterId")
)))))
.toPact()
}
When calling I would expect the response to be:
{
"data": {
"object": {
"object": {
"array": [
{
"objectArray": {
"id": "produktanbieterId"
}
},
{
"objectArray": {
"id": "produktanbieterId"
}
}
]
}
}
}
}
But when I then call that mocked endpoint I retrieve the following response:
{
"data": {
"object": {
"object": [
{
"objectArray": {
"id": "produktanbieterId"
}
},
{
"objectArray": {
"id": "produktanbieterId"
}
}
]
}
}
}
so the "array":[]
seems to be migrated into the opject before it....
Any idea what I am doing wrong?Sugi S
04/02/2024, 8:44 PMNithin
04/05/2024, 6:58 AMRico Lang
04/05/2024, 11:28 AMEvan Rademacher
04/05/2024, 4:22 PMUlises Cervino
04/12/2024, 4:30 PM-Dpact.verifier.publishResults -Dpact.provider.version=$CI_COMMIT_SHA -Dpact.provider.branch=${BRANCH}
Those flags work very well for provider tests, not so much for producer tests. Am I using the wrong ones?Martin Gallauner
04/17/2024, 8:07 AM.matchingBranch();
to the ConsumerVersionSelector of the Producer, the test fails because the request to /for-verification
fails with response 400.
But when I do the same request with the Broker API Browser I get a 200 and a useful response.
Do you know what I'm missing here?GitHub
04/18/2024, 4:45 AMMichael Strasser
04/19/2024, 5:33 AMGitHub
04/22/2024, 7:37 AMMurilo Caruy
04/23/2024, 6:45 PM