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

    Rubén Pérez

    06/07/2022, 2:21 PM
    Hi 🙂 I'm trying to use
    consumerVersionSelectors
    from the
    PactBroker
    annotation on my provider application, and I have a doubt. Looking into the VersionSelector code, it only allows you to select tags, not branches or environments. I think what I would need is to get the latest from the main branch (
    master
    ) and the latest from production. My question is, even if I'm using
    branches
    and
    environments
    , should I also add tags from my consumer for both branches and environments?
    b
    • 2
    • 4
  • r

    Rejeesh Gangadharan

    06/13/2022, 8:03 AM
    What is Pact Publish mvn command for Maven Pact library 4.1.33/4.2.19/4.3.4? Looks like it needs this https://github.com/pact-foundation/pact_broker/blob/master/lib/pact_broker/doc/views/index/publish-contracts.markdown. Pact Maven Plugin configuration is <plugin> <groupId>au.com.dius.pact.provider</groupId> <artifactId>maven</artifactId> <version>4.2.19</version> <configuration> <pactBrokerUrl>${pact.broker.url}</pactBrokerUrl> <pactBrokerToken>${pact.pactbroker.token}</pactBrokerToken> <latest>true</latest> <projectVersion>${pact.consumer.version}</projectVersion> <tags>${pact.tag}</tags> </configuration> </plugin> Currently mvn command I am using is "mvn pact:publish -Dpact.consumer.version=<Git Commit> -Dpact.tags=feature-XXX _Dpact.broker.url=<pactbrokerurl> -Dpact.broker.token=${token}. But i am getting error such as [Error] Response from Pact Broker was not in JSON format: au.com.dius.pact.core.json.JsonException: Invalid JSON (1:2), found unexpected character 'U' Failed - Request to path 'https://pactbrokerurl/contracts/publish' failed with response 'HTTP/1.1 401 Unauthorized' But the same mvn command works fine with plugin version au.com.dius.pact.providermaven4.2.9. Currently I am not enabling branches. Could you please share what is the mvn command for publish pacts when using version au.com.dius.pact.providermaven4.2.19 ?
    m
    • 2
    • 2
  • j

    Julián Álvarez

    06/13/2022, 5:15 PM
    Hi all, thanks in advance for the help! I am trying to debug a test that is failing and don't manage to print the request that the mock is receiving, I really feel like the issue is related to this. What I have tried is to set this property to true but no suceed: pact.showFullDiff .. any ideas? Thanks!
    u
    • 2
    • 1
  • q

    Qingyuan Liu

    06/16/2022, 5:09 PM
    Hi team, after adding a test configuration, I got the error msg: The following methods annotated with @Pact were not executed during the test:xxxx Any idea how to solve this problem? Thanks!
    r
    • 2
    • 1
  • p

    Paul

    06/20/2022, 2:08 PM
    Hi all, I have a couple of questions regarding the verification stage using Java and JUnit5. 1. I am having trouble with setting @IgnoreNoPactsToVerify in the test file (or -DfailIfNoPactsFound=false in the mvn command). With no consumer the test is still failing (context is being set to null). 2. I want to run the verify step against a given environment using the specified 'tag' (we still haven't moved across to environments / deployments). This tag though depends on which CI job is running (ie which environment is being deployed to). Thus I want to pass in the consumer version at run time - and cannot thus set it up in the PACTBroker consumerVersionSelectors annotation. Is there a way this can be passed in maven similar to setting -Dpact.verifier.publishResults=true ? So I can run as part of the mvn command from gitlab CI? Thanks
    r
    • 2
    • 2
  • f

    Francislainy Campos

    06/20/2022, 8:51 PM
    Hi, do we have any samples for java contracts using graphql apis? The samples I’ve found so far are all Javascript.
    • 1
    • 1
  • g

    Gaurav

    06/21/2022, 7:26 PM
    Hi Guys, I am trying to do a POC, writing pact test for services consuming and publishing AVRO messages to kafka, I have searched similar discussion that have already happened on this channel, I found this page created for json/json schema registry messages, does pact support AVRO or its still a work in process at this point? cc @Matt (pactflow.io / pact-js / pact-go) @Yousaf Nabi (pactflow.io) @Andy Muir
    m
    • 2
    • 4
  • q

    Qingyuan Liu

    06/22/2022, 10:29 AM
    Hi team, is there any document which introduces how message level contract work in pact? For example, I saw a blog mentioned that "Pact will pretend to be a message queue and get the message provider to send it a message." How does pact pretend to be a message queue?
  • m

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

    06/22/2022, 1:02 PM
    This video maybe:

    https://youtu.be/IetyhDr48RI?t=485▾

    Also the how it works section of docs.pact.io
    thankyou 3 1
    q
    • 2
    • 3
  • j

    João Luiz Vieira

    06/22/2022, 7:35 PM
    Hello, I hope this message finds you well. I observing a weird behaviour and I am not sure what I doing wrong. I am using
    Copy code
    testImplementation('au.com.dius.pact:consumer:4.3.9')
    testImplementation('au.com.dius.pact.consumer:junit:4.3.9'
    And creating two interactions for the same consumer and provider (one POST and other PUT). I am setting the same response header for both of the interactions but the second interaction, the
    response.headers
    are being generated different from what I am setting it. I am setting
    responseHeaders.put("Content-Type", "application/json; charset=utf-8");
    . The first interaction, the header is
    "Content-Type": "application/json; charset=utf-8",
    but in the second it is
    "Content-Type": "application/json;charset=utf-8"
    the difference being that the second there is no space after the
    ;
    . I added another header just for testing and in the second interaction it added an
    =
    at the end. Basically, I want that the space in
    "application/json; charset=utf-8"
    is not removed in second interaction. Do you what can I do to achieve this? I am not sure if I am doing something wrong or is some kind of bug. (code and image in the thread)
    t
    m
    u
    • 4
    • 37
  • r

    Robert

    06/23/2022, 10:15 AM
    Hey, I hope I didn't over read it somewhere, but is there a possibility to annotate one provider test with 2 or multiple consumers? The use case is I have a provider with several consumers, two of them have the exactly same contract, because they are using the endpoints in the exact same way. Currently I have to create 2 identically provider tests classes with the only difference that in one class I have `@Conumser("consumer1")`` and in the other
    @Consumer("consumer2")
    . Is there another way?
    t
    • 2
    • 2
  • s

    Srinivas Vaddi

    06/23/2022, 4:07 PM
    hi lil new here, I have created a pact using the junit5 library. How can I publish it to local pact broker? is there a way to do that without using the cli?
    m
    • 2
    • 1
  • b

    bstyle killa

    06/23/2022, 11:17 PM
    Hi I am working with a java service team, that wants to know if they can run the verify step with mvn test, instead of bringing up the entire service in localhost
    u
    • 2
    • 4
  • b

    bstyle killa

    06/23/2022, 11:18 PM
    is it mandatory to bring up the real service localhost for the provider verify step
  • b

    bstyle killa

    06/23/2022, 11:20 PM
    mvn clean test -PproducerContractTestWithBroker -Dusername=$username -Dpassword=$password -DapiKey=$key -Dpact.broker.url="<https://test.pactflow.io/>"  -Dpact.broker.token=$token -Dci.props.git.hash.short="0" -Dci.props.git.branch.name=$branchname -Dpact.verifier.publishResults=true
  • b

    bstyle killa

    06/23/2022, 11:25 PM
    that is the reason they wanted to use the pact maven plugin instead of the CLI
  • b

    bstyle killa

    06/23/2022, 11:25 PM
    Can you help straighten us around? Thanks in advance!
  • b

    bstyle killa

    06/23/2022, 11:52 PM
    I see this might be an option based on this thread https://github.com/pact-foundation/pact-jvm/issues/755#issuecomment-419682188
  • q

    Qingyuan Liu

    06/24/2022, 3:16 AM
    Hi team, how to perform an exact match for message pact, like: now it seems like pact will only verify the type of the field rather than the exact value.
    Copy code
    PactDslJsonBody body = new PactDslJsonBody();
     body.stringType("name", "almost-anything");
    u
    • 2
    • 2
  • s

    Sandor Arpa

    06/24/2022, 10:06 AM
    Good morning (evening, afternoon) 👋 We're on pact v3. I've got an issue with NumberTypeMatcher where the matcher does not recognise a negative number as Integer. The part of generated contract file (from MessageBuilder) that fails:
    Copy code
    $.event_details.net_amount=MatchingRuleGroup(rules=[NumberTypeMatcher(numberType=INTEGER)]
    The error I get:
    BodyMismatch(expected=-8000, actual=-8000, mismatch=Expected -8000 (JsonPrimitive) to be an integer
    m
    u
    • 3
    • 30
  • s

    Sandor Arpa

    06/24/2022, 10:06 AM
    (Yes, tried to search the documentation first)
  • g

    GitHub

    06/28/2022, 4:26 AM
    Release - 4.3.10 New release published by rholshausen Supports branches and releases with Gradle plugin • ba88e30 - feat: add Gradle DSL functions for deprecated tag forms of selectors • f927119 - Feat: Implement new Gradle DSL for consumer version selectors • 5acf7d2 - refactor(Gradle): use delegation instead of inheritance to allow supporting Gradle 8 changes • 8327184 - feat(Gradle): Add auth option for no auth • de753fc - feat: allow consumer version selector JSON to be provided with an environment variable • 0fa5b5e - fix: make the use of content type overrides consistent #1569 • 7a2a77b - docs: link to 'Using provider states effectively' #1571 (Édouard Lopez) • 0e41131 - chore: add example tests with attributes that contain slashes #1556 pact-foundation/pact-jvm
    🙌 2
    t
    u
    j
    • 4
    • 5
  • g

    Gustavs

    06/28/2022, 2:26 PM
    Hello, is there a flag or variable we can pass into the jvm build in order to completely avoid the pact tests for the providers?
    u
    • 2
    • 1
  • r

    Robert

    06/30/2022, 2:00 PM
    Hey, I have a question about verifying contracts on branches. I have a consumer branch A and a provider branch X. I would like to verify now that provider branch X works with the new contract on consumer branch A. I already checked the options: • Have the same branch name for provider and consumer --> That's not a possible option for me • Use the consumerVersionSelectors --> I'm using already "branches" and would need to implement this workaround. https://pact-foundation.slack.com/archives/C9UN99H24/p1654611672907539 OR stepping back and use tags again. My question now, is there any other option?
    u
    • 2
    • 2
  • m

    MHNOT

    07/04/2022, 2:10 PM
    Hi, My application calls a.o. a few file download endpoints that should be covered by consumer driven contract tests. I don't care about the downloaded content but want to verify that the body is not empty by checking that the Content-Length header is set to a value > 0. Used version: au.com.dius.pact.consumerjunit4.3.10 Consumer code:
    Copy code
    @Override
    protected RequestResponsePact createPact(final PactDslWithProvider aBuilder)
    {
      final Map<String, String> requestHeaders = ChatTestUtil.createRequestHeaderMap();
    
      return aBuilder//
        .given("A text prod finished successfully")//
        .uponReceiving("A request to download text")//
        .pathFromProviderState("/textresult/${jobId}", "/textresult/" + ChatTestUtil.DUMMY_JOB_ID)//
        .method("GET")//
        .headers(requestHeaders)
        .willRespondWith()//
        .status(200)//
        .headers(Map.of("Content-Type", "text/plain"))//
        .matchHeader("Content-Length", "[1-9][0-9]+")//
        .body(PactDslRootValue.stringType())
      //.body(PactDslRootValue.stringMatcher(".*", "whatever"))
      //.withBinaryData("FooBar".getBytes(), "text/plain")
        .toPact();
      }
    The variant with "*.body(PactDslRootValue.stringType())*" fails with following exception on provider side:
    Copy code
    java.lang.AssertionError: 
    	Failures:
    
    	1) Verifying a pact between Core_Chat_Client and Chat_Service - A request to download text
    
    		1.1) BodyMismatch: / BodyMismatch: Expected body 'string' to match 'Participants:
    	TestUser
    
    	TestUser sent message
    	16 Oct 2001 10:14 PM +02:00 Hello World
    
    	TestUser sent message
    	16 Oct 2001 10:14 PM +02:00 Lorem Ipsumupczl
    	' using equality but did not match
    The variant with "*.body(PactDslRootValue.stringMatcher(".*", "whatever")*" fails with also on provider side:
    Copy code
    java.lang.AssertionError:
    	Failures:
    	1) Verifying a pact between Core_Chat_Client and Chat_Service - A request to download text
    	    1.1) BodyMismatch: / BodyMismatch: Expected body 'whatever' to match 'Participants:
    	TestUser
    	TestUser sent message
    	16 Oct 2001 10:14 PM +02:00 Hello World
    	TestUser sent message
    	16 Oct 2001 10:14 PM +02:00 Lorem Ipsumphaai
    	' using regex '.*' but did not match
    And the last variant "*.withBinaryData("FooBar".getBytes(), "text/plain")*" fails also:
    Copy code
    java.lang.AssertionError:
    	Failures:
    
    	1) Verifying a pact between Core_Chat_Client and Chat_Service - A request to download text
    
    		1.1) BodyMismatch: / BodyMismatch: Expected body 'FooBar' to match 'Participants:
    	TestUser
    
    	TestUser sent message
    	16 Oct 2001 10:14 PM +02:00 Hello World
    
    	TestUser sent message
    	16 Oct 2001 10:14 PM +02:00 Lorem Ipsumxetoj
    	' using equality but did not match
    How can I verify that the body of a response is not empty?
    u
    • 2
    • 8
  • b

    bstyle killa

    07/06/2022, 5:53 PM
    Can we use can-i-deploy without the tags in java?
  • b

    bstyle killa

    07/06/2022, 5:55 PM
    https://docs.pactflow.io/docs/workshops/ci-cd/workshop/prerequisite-concepts INFO As of July 2021, recording deployments using the
    record-deployment
    command has just been released, and support for the corresponding selector
    { deployed: true }
    has not yet been added to all the Pact client libraries. The previous method of recording releases was to use tags. If you are not using one of the libraries that currently supports the
    { deployed: true}
    selector (currently Javscript and Ruby support it), you will need to use tags in the meantime as per the documentation in the Tags page.
  • b

    bstyle killa

    07/06/2022, 6:24 PM
    Based on this https://docs.pact.io/pact_broker/branches#support There has been no development on the jvm tag replacement for a year, that cant be right
    u
    • 2
    • 1
  • b

    bstyle killa

    07/07/2022, 6:47 PM
    How can you run the @AllowOverridePactUrl for pact-jvm in localhost. We are doing this and its not working
    Copy code
    PACT_URL="<https://blah.pactflow.io/ngc-provider-service/consumer/ngc-consumer/version/f8823729>" mvn clean test \
    -PproducerContractT ...
    https://github.com/pact-foundation/pact-jvm/commit/5b367c91e6c006542b6af197f0393c2cc64fc889
  • b

    bstyle killa

    07/07/2022, 7:32 PM
    We also looked at passing PACT_URL into the jvm vars based on this commit. We use maven and surefire-plugin. This also did not work.
    Copy code
    mvn clean test \
    -PproducerContractTestWithBroker \
    -Dtest=GetCartsProviderContractWithBrokerRunnerTest \
    -DPACT_URL="<https://blah.pactflow.io/pacts/provider/ngc-provider-service/consumer/ngc-consumer/version/12341234>" \
    u
    • 2
    • 27
1...456...14Latest