https://pact.io logo
Join Slack
Powered by
# pact-jvm
  • m

    Marcin Baranowski

    09/23/2021, 10:53 AM
    Hello, I have hard time with PactBroker annotation. When trying to run tests I get:
    Copy code
    Invalid pact broker host specified ('${pactbroker.host:}'). Please provide a valid host or specify the system property 'pactbroker.host'.
    java.lang.IllegalArgumentException: Invalid pact broker host specified ('${pactbroker.host:}'). Please provide a valid host or specify the system property 'pactbroker.host'.
    My application.yaml has:
    Copy code
    pactbroker:
      host: "<https://valid-host>"
      port: 443
      protocol: "https"
      auth:
        token: "tokenValue"
    I use gradle and my only pact dep is:
    Copy code
    testImplementation("au.com.dius.pact.provider:junit5spring:4.2.11")
    My Test:
    Copy code
    @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
    @Provider("provider")
    @PactBroker
    public class PactTest extends AbstractIntegrationTest {
    
      @LocalServerPort int port;
    
      @Value("${pactbroker.host}")
      String host;
    
      @BeforeEach
      public void setupTestTarget(PactVerificationContext context) {
        System.out.println("host");
        System.out.println(host);
        context.setTarget(new HttpTestTarget("localhost", port));
      }
    
      @TestTemplate
      @ExtendWith(PactVerificationSpringProvider.class)
      public void pactVerificationTestTemplate(PactVerificationContext context) {
        context.verifyInteraction();
      }
    }
    Host value is assigned correctly in test file. Why Pact doesn't see these values? What should I change?
    j
    m
    j
    • 4
    • 10
  • m

    Michael Branders

    01/21/2022, 1:49 PM
    Is there an V4 Pact example available like this for V3: https://github.com/pact-foundation/pact-jvm/blob/master/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/AsyncMessageTest.java ? Is there a wat to make a builder.toPact() give a MassagePact V4? Seems there is only a V4Pact and no V4MessagePact
    ✅ 1
    u
    t
    • 3
    • 10
  • s

    Shan

    01/28/2022, 2:42 AM
    Hello, I recently updated pact provider
    junit5spring
    from
    4.1.16
    to
    4.2.0
    , the problem is test hangs like 20s in certain tests. When I revert back my version to
    4.1.16
    or
    4.1.19
    it runs smoothly. Any idea why this is happening?
    u
    • 2
    • 13
  • e

    extra 2

    02/07/2022, 9:35 PM
    Hello! In this example https://docs.pact.io/implementation_guides/jvm/provider#an-example-of-running-provider-verification-with-junit we have this comment "// setup any provider state", how can I setup the provider state?? Thank you!
    m
    s
    • 3
    • 15
  • a

    Anna Khvorostianova

    02/08/2022, 12:22 PM
    Hello guys, I wonder is there any plans to add testng support in the nearest future? We use testng in Miro and it would be great not to reinvent the wheel and use your client)
    m
    p
    • 3
    • 8
  • p

    Pavlo Sprogis

    02/08/2022, 9:33 PM
    hi guys, I have noticed that by default pact will record
    Content-Type
    header in generated pact json during consumer tests, e.g.:
    Copy code
    "headers": {
         "Content-Type": "application/json; charset=UTF-8"
    },
    even though I do not mention this header explicitly. Is it possible to configure pact to skip content-type header and do not record it in generated pact json? Or omit content-type during pact verification tests in provider? I’m using
    <http://au.com|au.com>.dius.pact.consumer.junit5 4.2.17
    for consumer tests and
    <http://au.com|au.com>.dius.pact.provider.junit 4.1.17
    for provider tests
    u
    • 2
    • 2
  • c

    Christoph Oswald

    02/09/2022, 12:47 PM
    Hello, when reading the documentation https://docs.pact.io/implementation_guides/jvm/provider/junit/#tagging-the-provider-before-verification-results-are-published-401 I had difficulties finding out the differences between the properties ´`pact.provider.tag`´ and ´`pactbroker.providerTags`´. Could you explain the differences? Also I was wondering if there is an overview of system properties that are picked up the the pact-jvm implementation. For example I could not find any reference to the ´`pact.provider.name`´ besides https://github.com/pact-foundation/pact-jvm/issues/1160#issuecomment-657184770
    p
    u
    • 3
    • 4
  • a

    Ajay Kawde

    02/10/2022, 9:53 AM
    but during validation in provider side i get path expression ".age" does not start with a root marker "$"
    u
    • 2
    • 1
  • m

    ManuGu

    02/11/2022, 3:26 PM
    as you can see the only difference is when i send type = 400Type to API, it should give me 400 bad request response, but when generating contract it matches the first interaction
    u
    • 2
    • 1
  • a

    Ajay Kawde

    02/14/2022, 8:21 AM
    hi guys if a create a RequestReponseObject and want to use it to create pact contract json
    m
    s
    • 3
    • 19
  • m

    Mike

    02/17/2022, 9:56 AM
    Hi, I try to use Pact broker consumerVersionSelectors in kotlin. Seems its not working
    Copy code
    @PactBroker(
            authentication= @PactBrokerAuth(username = "", password = ""),
            port="8080",
            consumerVersionSelectors={ @VersionSelector(latest = "true") }
    )
    @TestInstance(TestInstance.Lifecycle.PER_CLASS)
    class PactCPEProviderTest {
    I take it from Docs https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/ But compiler argues on VersionSelector with An annotation can't be used as the annotations argument Is it possible to solve it somehow?
    p
    • 2
    • 7
  • a

    Ajay Kawde

    02/17/2022, 11:10 AM
    does anyone has any idea how to achieve it
    p
    b
    • 3
    • 12
  • g

    Guillermo

    02/17/2022, 8:12 PM
    Hello everyone. I'm attempting to create a body DSL closure to generate a contract. I am creating the closure using fields and an array. However, I would like the array to have matchers to uniquely match each index with a different object.
    eachLike
    only works when an array has the same object in each index. Here is an example JSON that needs to be matched :
    Copy code
    {
      "version": 1234,
      "data": [
        {
          "name": "someName"
        },
        {
          "name": "anotherName",
          "id": 131312
        }
      ]
    }
    As you see using an eachLike on data wouldn't work because of the extra
    id
    field. Does anyone know how I can achieve this? I've look at the documentation, but I can't seem to figure it out. Thanks!
    m
    • 2
    • 13
  • a

    André Sousa

    02/22/2022, 2:12 PM
    I'm starting to adopt contract testing through Pact framework. I've noted that Pact.io contract tests run with JUnit. Our services use TestNG to run unit tests. Do you see any problems or conflicts on still using testNG to run our current unit test suite and use junit to run contract tests exclusively on the same service repository?
    m
    • 2
    • 3
  • a

    André Sousa

    02/28/2022, 2:41 PM
    how can i match bets list as empty on the consumer side?
    p
    • 2
    • 2
  • m

    Matt (pactflow.io / pact-js / pact-go)

    03/01/2022, 3:14 AM
    Remember, what you put in your consumer contract is what is gonig to be replayed against your provider. So all it’s telling you is that given the request you defined, it should respond with your assertions. Obviously, that’s not the case (so Pact is telling you your assumptions are wrong)
    a
    • 2
    • 1
  • a

    Ayush

    03/01/2022, 3:57 AM
    Hey! I had question regarding pact junit If we’re writing producer code for pact verification is it mandate to spin up the server on localhost to validate the interactions or will it be possible to just call the resource methods to verify those interactions ?
    u
    • 2
    • 4
  • m

    Matt (pactflow.io / pact-js / pact-go)

    03/01/2022, 9:56 PM
    No, sorry. Please see https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes as to why (sorry for short response, have to run!)
    p
    • 2
    • 1
  • t

    Thomas K

    03/01/2022, 10:40 PM
    Hello, is it possible to set loose expectations on a range of status code like 2xx ? I stumbled across https://github.com/pact-foundation/pact-specification/issues/68 but it wasn't overly clear if this is possible now or not ?
    u
    • 2
    • 9
  • m

    Matt (pactflow.io / pact-js / pact-go)

    03/01/2022, 11:21 PM
    Anyone want to to a crack at answering this: https://stackoverflow.com/questions/71314140/pact-consumer-test-connection-refused ?
    u
    • 2
    • 2
  • r

    Rejeesh Gangadharan

    03/02/2022, 9:19 AM
    I saw this issue was earlier raised by another team https://github.com/pact-foundation/pact-jvm/issues/1265. And the issue is still open. Can you help us fix this issue ASAP.
    u
    • 2
    • 2
  • t

    Thomas K

    03/02/2022, 12:00 PM
    Hello, I am trying to write a consumer test which basically makes a POST request to get a token back, this POST request has an
    Authorization
    header where the value is a JWT. For it to be accepted fine by the provider, it needs to not be expired etc. Is there any way I can handle this with matchers etc? I have this regex
    Copy code
    .matchHeader("Authorization", "^[A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.?[A-Za-z0-9-_.+/=]*\$")
    but not sure about the JWT expiry part and obviously how the jwt would be decoded from that regex?
    u
    • 2
    • 4
  • a

    andrewhiles

    03/02/2022, 5:05 PM
    Hi folks. I'm experiencing an issue currently when trying to publish pacts via gradle. It looks like the request to the broker is dropping auth. If I try and publish to an existing broker that has no auth, it works but when publishing to our new auth’d broker, the request fails. I’m using pact-jvm version 4.2.20 which appears to have fixed some authentication issues but it doesn't appear so in my case. Has anybody else encountered this recently? Any info is appreciated.
    u
    m
    • 3
    • 15
  • a

    Abhay Tamboli

    03/03/2022, 12:35 AM
    Hi #C9UN99H24 , i am trying to write provider test for a spring rest controller. However the pact test are failing on http status code 404. It is expected to return 200. if i run with MockitoJunitRunner it works fine. Any idea how to troubleshoot this further or resolve it. Thanks in advance.
    u
    m
    • 3
    • 13
  • t

    Thomas K

    03/03/2022, 12:23 PM
    hi, is there any example of pact jvm v4 dsl versus v3 dsl, seems like a lot of v3 stuff (e.g.
    builder.given()...
    ) no longer is applied in the same way in V4 ? looking for example for setting consumer side expectations
    n
    u
    • 3
    • 4
  • r

    Reuben Tonna

    03/04/2022, 2:45 PM
    Hi. I'm on version 4.3.5 of pact libraries and am trying to define the following pact in my consumer using the LambdaDsl (in a java+spring boot project)
    Copy code
    final DslPart body = newJsonBody(root -> {
                root.stringMatcher("callCount", "\\d+", "10");
                root.unorderedMinArray("distribution", 0, item -> item.object(o -> {
                    o.stringMatcher("id", "\\d+", "1");
                    o.stringMatcher("callCount", "\\d+", "10");
                }));
            }).build();
            
            return builder
                .usingLegacyMessageDsl()
                .given("non-empty-greeting-usage-statistics")
                .expectsToReceive("private.metrics.greeting.usage")
                .withContent(body)
                .toPact(V4Pact.class);
    My intent is to state that this consumer accepts message content of the general shape { callCount: x, distribution: [] } where distribution array can be empty, and if not empty the items must match the general structure { id: x, callCount: y }. The pact generates and is loaded in the broker. However when in my provider I return payloads such as:
    Copy code
    "{\"callCount\":\"0\",\"distribution\":[]}";
    It is failing with:
    Copy code
    1) private.metrics.greeting.usage: generates a message which has a matching body
    
        1.1) body: $.distribution Expected [{"callCount":"10","id":"1"}] to match [] ignoring order of elements
    
            [
            -  {
            -    "callCount": "10",
            -    "id": "1"
            -  }
            +
            ]
    Any thoughts what I am missing? Maybe my expectation that in one pact I can define both scenarios were the array have items matching the example, or have no items is incorrect. Thoughts?
    m
    • 2
    • 2
  • h

    Harihara Raj LK

    03/05/2022, 1:22 PM
    Hi people, Is it possible to do pact testing with the use of pact files available on local if pact broker is not reachable or accessible or based on some configuration?
    m
    • 2
    • 6
  • t

    Thomas K

    03/07/2022, 11:29 AM
    hi are there any good tutorials on how to apply consumer versioning (branches) when publishing with pact (both/either via gradle ideally or pact cli) ?
    n
    • 2
    • 3
  • a

    Ankit Rawat

    03/07/2022, 8:05 PM
    Hello, I just want to understand how will the provider test will look like for a POST method. Any example, i want to validate that when the post method is called, a random id is generated in body along with status
    u
    • 2
    • 1
  • g

    gesellix

    03/08/2022, 1:20 PM
    Hey there, given a bigger multi-module project with multiple consumers and providers, I’d like to have a simple way of tagging the pacticipants after a deploy (everything is deployed together a the same time). I currently have to hard code the list of known pacticipant names and loop over that list, performing something similar to the snippet below:
    Copy code
    for pacticpant in "${pacticipants}"
    do
      pact-cli broker create-version-tag --pacticipant="${pacticipant}" --version="${version}" --tag=${tag}
    done
    Is there a simpler way of tagging every pacticipant in a Maven project or at least collecting the list of pacticipants?
    n
    m
    • 3
    • 9
12345...14Latest