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

    Julián Álvarez

    01/20/2023, 10:38 AM
    Hi, we are facing many issues with writing the contracts and making it work because the DSL is quite intuitive when writing the contracts but they dont work straight forward as one would expect and we need to be changing things closeObject(), closeArray() .. and so on ... so the question is .. is there a way to see in a json format what the mock is expecting based on a defined contract? Thanks a lot in advance
    m
    • 2
    • 1
  • i

    Ivan Mikhalka

    01/21/2023, 2:30 PM
    Hi, all, I have a question about pact Gradle plugin, 4.1.39 version in use. I am wondering, how can I change some content of pact file that coming from Pactflow broker? We have endpoints, where user id changes instantly, so we decided to keep placeholder in pact file, like
    path/to/endpoint/userId/12345
    and then replace it on the fly. When storing pact file locally, we used to use
    sed
    for replacing placeholder with actual id, like
    sed s/12345/$ACTUAL_USERID/g
    , but it’s not the case when switching to pact broker. Could this be done via
    requestFilter
    from plugin or somehow else? I know it’s not the best practice, but we need some workaround for now
    m
    • 2
    • 5
  • o

    Onur

    01/23/2023, 1:06 PM
    Hi all, I hope you all are doing fine. We are currently moving the JDK 17, and we faced a strange problem. We cannot debug tests using pact provider and consumer junit5 dependencies. I tried many versions and faced the same problem. I debugged this problem by excluding each library that pact dependency is using, and in the end, I found the problematic area. If I use the below configuration, the problem disappears.
    Copy code
    <dependency>
        <groupId>au.com.dius.pact.provider</groupId>
        <artifactId>junit5</artifactId>
        <version>4.4.4</version>
        <exclusions>
            <exclusion>
                <groupId>io.ktor</groupId>
                <artifactId>ktor-network-tls-certificates</artifactId>
            </exclusion>
            <exclusion>
                <groupId>io.ktor</groupId>
                <artifactId>ktor-server-netty</artifactId>
            </exclusion>
            <exclusion>
                <groupId>au.com.dius.pact.core</groupId>
                <artifactId>model</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
    
    <dependency>
        <groupId>au.com.dius.pact.consumer</groupId>
        <artifactId>junit5</artifactId>
        <version>4.4.4</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>io.ktor</groupId>
                <artifactId>ktor-network-tls-certificates</artifactId>
            </exclusion>
            <exclusion>
                <groupId>io.ktor</groupId>
                <artifactId>ktor-server-netty</artifactId>
            </exclusion>
            <exclusion>
                <groupId>au.com.dius.pact.core</groupId>
                <artifactId>model</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    If I do not exclude any of these libraries, I am facing the below problem when I debug the tests in IntelliJ. This happens only for debugging, not running the tests. Connected to the target VM, address: ‘127.0.0.1:52632’, transport: ‘socket’ Internal Error occurred. org.junit.platform.commons.JUnitException: TestEngine with ID ‘junit-jupiter’ failed to discover tests at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:160) at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverSafely(EngineDiscoveryOrchestrator.java:132) at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:107) at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:78) at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:110) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86) at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86) at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) Caused by: org.junit.platform.commons.JUnitException: MethodSelector [className = ‘com.emirates.ocsl.skeleton.ct.tests.SkeletonCT’, methodName = ‘iGetResponseSuccessfully’, methodParameterTypes = ‘’] resolution failed at org.junit.platform.launcher.listeners.discovery.AbortOnFailureLauncherDiscoveryListener.selectorProcessed(AbortOnFailureLauncherDiscoveryListener.java:39) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:103) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequestResolution.java:83) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequestResolver.java:113) at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:46) at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:69) at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152) ... 13 more Caused by: java.lang.ClassCircularityError: java/lang/WeakPairMap$Pair$Weak at java.base/java.lang.WeakPairMap$Pair.weak(WeakPairMap.java:201) at java.base/java.lang.WeakPairMap.putIfAbsent(WeakPairMap.java:123) at java.base/java.lang.Module.implAddReads(Module.java:488) at java.base/java.lang.Module.implAddReads(Module.java:449) at java.base/java.lang.System$2.addReads(System.java:2335) at java.base/jdk.internal.module.Modules.addReads(Modules.java:90) at java.base/java.lang.reflect.Proxy$ProxyBuilder.lambda$getDynamicModule$1(Proxy.java:918) at java.base/jdk.internal.loader.AbstractClassLoaderValue$Memoizer.get(AbstractClassLoaderValue.java:329) at java.base/jdk.internal.loader.AbstractClassLoaderValue.computeIfAbsent(AbstractClassLoaderValue.java:205) at java.base/java.lang.reflect.Proxy$ProxyBuilder.getDynamicModule(Proxy.java:908) at java.base/java.lang.reflect.Proxy$ProxyBuilder.mapToModule(Proxy.java:846) at java.base/java.lang.reflect.Proxy$ProxyBuilder.<init>(Proxy.java:651) at java.base/java.lang.reflect.Proxy$ProxyBuilder.<init>(Proxy.java:656) at java.base/java.lang.reflect.Proxy.lambda$getProxyConstructor$0(Proxy.java:429) at java.base/jdk.internal.loader.AbstractClassLoaderValue$Memoizer.get(AbstractClassLoaderValue.java:329) at java.base/jdk.internal.loader.AbstractClassLoaderValue.computeIfAbsent(AbstractClassLoaderValue.java:205) at java.base/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:427) at java.base/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1037) at java.base/sun.reflect.annotation.AnnotationParser$1.run(AnnotationParser.java:302) at java.base/sun.reflect.annotation.AnnotationParser$1.run(AnnotationParser.java:300) at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) at java.base/sun.reflect.annotation.AnnotationParser.annotationForMap(AnnotationParser.java:300) at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:289) at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:121) at java.base/sun.reflect.annotation.AnnotationParser.parseSelectAnnotations(AnnotationParser.java:102) at java.base/sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:146) at java.base/sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:85) at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:262) at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:121) at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:73) at java.base/java.lang.Class.createAnnotationData(Class.java:4068) at java.base/java.lang.Class.annotationData(Class.java:4057) at java.base/java.lang.Class.getAnnotation(Class.java:3940) at java.base/java.lang.reflect.AnnotatedElement.isAnnotationPresent(AnnotatedElement.java:292) at java.base/java.lang.Class.isAnnotationPresent(Class.java:3950) at org.junit.platform.commons.util.AnnotationUtils.findAnnotation(AnnotationUtils.java:136) at org.junit.platform.commons.util.AnnotationUtils.isAnnotated(AnnotationUtils.java:105) at org.junit.jupiter.engine.discovery.predicates.IsTestableMethod.test(IsTestableMethod.java:52) at org.junit.jupiter.engine.discovery.predicates.IsTestMethod.test(IsTestMethod.java:23) at org.junit.jupiter.engine.discovery.predicates.IsTestableMethod.test(IsTestableMethod.java:26) at java.base/java.util.function.Predicate.lambda$or$2(Predicate.java:101) at java.base/java.util.function.Predicate.lambda$or$2(Predicate.java:101) at org.junit.platform.commons.util.ReflectionUtils.findMethod(ReflectionUtils.java:1368) at org.junit.platform.commons.util.ReflectionUtils.isMethodPresent(ReflectionUtils.java:1267) at org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests.hasTestOrTestFactoryOrTestTemplateMethods(IsTestClassWithTests.java:50) at org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests.test(IsTestClassWithTests.java:46) at org.junit.jupiter.engine.discovery.predicates.IsTestClassWithTests.test(IsTestClassWithTests.java:27) at java.base/java.util.function.Predicate.lambda$or$2(Predicate.java:101) at org.junit.jupiter.engine.discovery.MethodSelectorResolver.resolve(MethodSelectorResolver.java:87) at org.junit.jupiter.engine.discovery.MethodSelectorResolver.resolve(MethodSelectorResolver.java:75) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.lambda$resolve$2(EngineDiscoveryRequestResolution.java:150) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1602) at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129) at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:189) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:126) at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:92)
    • 1
    • 1
  • b

    BENJAMIN J HESS

    01/24/2023, 12:00 AM
    Hello - we're introducing Pact across several teams. One of the teams is using Pact .NET exclusively, and it's my understanding Pact-net provider tests only work with V3 Pactfiles. Is there a way to make a pact-junit5 consumer test generate V3 pacts?
    m
    • 2
    • 7
  • t

    Thibaut Bodart

    01/25/2023, 9:23 AM
    Hello. I have a question about
    arrayContaining
    . I need this logic for an array that is not defined as a value of an object property. Instead, the array is returned as the body of the response.
    Copy code
    [
      {....},
      {....}
    ]
    Ideally, I would need a
    newJsonArrayContaining
    method in
    LambdaDsl
    . See an example below.
    Copy code
    return logAndReturn(builder.given("multiple connections exists")
    				.uponReceiving("request to get all connections")
    				.method("GET")
    				.path("/connections")
    				.headers(headers())
    				.willRespondWith()
    				.status(200)
    				.headers(headers())
    				.body(newJsonArrayContaining(arr -> {
    					......
    					});
    				}).build()));
    As I understand it, there is currently no way to use
    arrayContaining
    in this situation. Is my understanding correct?
  • t

    Thibaut Bodart

    01/25/2023, 11:06 PM
    Hello. I am migrating from
    4.3.17
    to
    4.4.4
    since I would like to use the V4 Pact specifications. My response is in JSON format and only contains a UUID. See below a valid JSON response.
    Copy code
    "08f7a210-95db-4827-bcc8-d2025ba506cf"
    I am using the following code to define the interaction:
    Copy code
    ...
    .willRespondWith()
    .status(201)
    .headers(headers())
    .body(PactDslJsonRootValue.uuid(JOB_ID)));
    With
    4.3.17
    , using a Pact v3 contract, the generated contract looks like:
    Copy code
    "response": {
            "body": "\"08f7a210-95db-4827-bcc8-d2025ba506cf\"",
            .....
    }
    With
    4.4.4
    , using a Pact v4 contract, it looks like:
    Copy code
    "response": {
            "body": {
              "content": "08f7a210-95db-4827-bcc8-d2025ba506cf",
              "contentType": "application/json",
              "encoded": false
            },
    .....
    }
    The content value is not a valid JSON value in the case of
    4.4.4
    . For this reason, the contract cannot be verified by the provider (also using pact-jvm
    4.4.4
    ). See the exception below. This is expected since
    "08f7a210-95db-4827-bcc8-d2025ba506cf"
    is not a valid JSON document whereas
    "\"08f7a210-95db-4827-bcc8-d2025ba506cf\""
    is.
    Copy code
    1.1) Invalid JSON (1:5), found unexpected character '7'
    Am I doing something wrong? If I modify the contract manually as illustrated below, the provider can successfully verify it. Is there a way to generate the response below using the Pact DSL?
    Copy code
    "response": {
      "body": {
        "content": "\"08f7a210-95db-4827-bcc8-d2025ba506cf\"",
        "contentType": "application/json",
        "encoded": false
      },
    Thanks in advance!
  • i

    Ivan Mikhalka

    01/27/2023, 5:10 AM
    Hi, I am running pact tests using gradle plugin
    4.1.39
    , using Pactflow as a pact broker. There is a several consumers for same provider, and I can run verification for all consumers using similar config:
    Copy code
    fromPactBroker {
       withSelectors {
          selector('tagConsumer1', true, null, 'Consumer1')
          selector('tagConsumer2', true, null, 'Consumer2')
       }
    }
    via command `./gradlew pactVerify -Ppact.verifier.publishResults=true -Dpact.provider.branch=
    git branch --show-current
    -Dpact.provider.tag=`git branch --show-current`` How can I run verification for only one specified consumer?
    m
    • 2
    • 17
  • k

    Kevin de Boer

    01/30/2023, 1:48 PM
    Hi, I am learning the pact-jvm framework by rewriting some of our existing wiremock tests. I’ve noticed that in our wiremock tests, multiple services are mocked in a single test. So in pact-jvm terms, that would be a multiprovider test: https://docs.pact.io/implementation_guides/jvm/consumer/junit5#using-multiple-providers-in-a-test-425. Ive followed the instructions and I get the test running, however I’ve ran into problems when defining mock provider ports in case a multiprovider test. I assume that you have to run a different instance of mockserver for each provider, so that each provider will have their own contract. By default a random port is used for each mockserver instance launched during a test. However our application is configured to call the provider by a fixed port. In case of a single provider test, this would be resolved using “port = 1234” in the @PactTestFor annotation:
    Copy code
    @Test
    @PactTestFor(providerName = "provider1", port = "1234")
    public void example(MockServer provider1mock) {
        ...
    }
    However, when I do this in a multiprovider test:
    Copy code
    @Test
    @PactTestFor(pactMethods = {"createProvider1Pact", "createProvider2Pact"}, port = "1234")
    public void example(@ForProvider("provider1") MockServer provider1mock, @ForProvider("provider2") MockServer provider2mock) {
       ...
    }
    I get an “address already in used” exception. Which is logical since I instantiate 2 instances of mockserver, and only provide 1 port. It tries to launch both on the same port. However I have found no way of specifying which mockserver should use which port. Is there a way to do this? I could not find anything in the documentation or source code, though I am unfamiliar with kotlin, I may have missed something. I tried making a subclass of MockServer and set the port myself, but then I ran into injection/instantiation issues with my new class. Alternatively, i have also not found a way to let the application use whatever random port is chosen for the mock.
    g
    • 2
    • 5
  • o

    Onur

    01/31/2023, 6:13 AM
    Hi all, Is the JDK 17 (LTS) version supported? https://github.com/pact-foundation/pact-jvm#supported-jdk-and-specification-versions We cannot see the JDK 17 support on this page. We are moving from JDK 11 to JDK 17, and we would like to know if anyone has faced any issues with JDK 17?
    u
    r
    • 3
    • 3
  • c

    Chimein

    01/31/2023, 11:51 AM
    Hi, how to hit the actual api and generate contract instead of mock url for testing
    k
    m
    • 3
    • 2
  • s

    Sebastian Suarez

    01/31/2023, 6:25 PM
    Hi team 😎 🖖, I'm new with pact jvm; one question, the implementation with the local pact broker works for me. Do you know of any guide to publish my contracts in pact flow?
    m
    s
    • 3
    • 6
  • u

    Ulises Cervino

    02/01/2023, 10:33 AM
    x-posting from #C5F4KFKR8 because of pact-jvm; tl;dr: I'm writing a consumer test that on retrieval of an entity with ID
    ID
    it checks that the ID of the returned entity matches
  • u

    Ulises Cervino

    02/01/2023, 10:34 AM
    however it's not quite working for me (code examples in the thread)
  • u

    Ulises Cervino

    02/01/2023, 10:34 AM
    any thoughts/advice much appreciated
  • u

    Ulises Cervino

    02/01/2023, 10:34 AM
    final comment: if I relax the checks in the consumer (e.g. I check that the ID is any UUID) then the pact is verified no bother at all
  • g

    GitHub

    02/02/2023, 10:26 PM
    Release - 4.4.5 New release published by rholshausen Bugfix Release • 8c965dc - fix(regression): Changes for #1641 broke the use of plugin mock servers • f4d0171 - feat: support JSON encoded bodies with V4 Pact files • 3e63af6 - fix: correct how the bodies are presisted as per the spec #1658 • 4c74ef9 - fix: correctly decode Pact files with JSON string contents #1658 pact-foundation/pact-jvm
  • p

    Pavithra Navaneeth

    02/03/2023, 3:17 AM
    Hi, I am bit new to pact. I have a pact junit5 consumer test using 4.1.7 version and the moment I updrade to latest version - it throws error saying Method (pact method name) does not conform required method signature pact.core.model.V4Pact xxx (PactBuilder builder) Note: until pact junit5 consumer 4.2.21 - test works fine. How can I fix it with later junit5 consumer version ? Thanks
    u
    • 2
    • 6
  • u

    Ulises Cervino

    02/03/2023, 2:16 PM
    how does one effectively use
    valueFromProviderState
    in responses? I'm struggling to figure out how this work. The test I have in mind is a consumer saying "when I GET /entity/1 I expect a response like {id: 1}" for instance, where
    1
    in the path matches the
    1
    in the response (I already have
    pathFromProviderState
    working fine)
  • u

    Ulises Cervino

    02/03/2023, 2:17 PM
    this is the relevant bit in my consumer test:
    Copy code
    body.valueFromProviderState(
                                                                    "basketId",
                                                                    "basketId",
                                                                    existingBasketId.toString())
    • 1
    • 1
  • u

    Ulises Cervino

    02/03/2023, 2:17 PM
    however in my pact file I end up with
    Copy code
    "matchingRules": {
              "body": {
                "$.basketId": {
                  "combine": "AND",
                  "matchers": [
                    {
                      "match": "type"
                    }
                  ]
                },
  • u

    Ulises Cervino

    02/03/2023, 2:17 PM
    and the provider test fails with
    Copy code
    1.1) body: $.basketId Expected "698c7e00-1e27-436e-a2e6-f7dd94ea98a7" to be null
  • u

    Ulises Cervino

    02/03/2023, 2:18 PM
    this is the state method for the provider test:
    Copy code
    Map liveBasketExists(Map _ignored_params) {
            Map<String, Object> state = new HashMap<>();
    
            InternalBasket internalBasket =
                    repository.createBasket(TestSupport.Repository.basketWithDefaults()).orElseThrow();
    
            // the key in this state-map corresponds to the variable in the expression in the consumer
            // test, i.e. in the
            // example consumer test we have a call like .pathFromProviderState("/${basketId}", ...)
            state.put("basketId", internalBasket.getBasketId());
    
            return state;
        }
  • s

    Sebastian Suarez

    02/03/2023, 7:26 PM
    Hello team 😎, I am doing some tests from the consumer trying to generate the contract, it works perfectly for me, but when I want to add headers, it seems the mock response with a 500 error, do you have any idea what could be happening?
    Copy code
    package consumer.pact.springboot;
    
    import org.junit.jupiter.api.extension.ExtendWith;
    import au.com.dius.pact.consumer.MockServer;
    import au.com.dius.pact.core.model.RequestResponsePact;
    import au.com.dius.pact.core.model.annotations.Pact;
    import au.com.dius.pact.consumer.dsl.PactDslJsonBody;
    import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
    import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
    import au.com.dius.pact.consumer.junit5.PactTestFor;
    import org.junit.jupiter.api.Test;
    
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;
    
    import static org.hamcrest.MatcherAssert.assertThat;
    import static <http://org.hamcrest.Matchers.is|org.hamcrest.Matchers.is>;
    
    @ExtendWith(PactConsumerTestExt.class)
    @PactTestFor(providerName = "provider-springboot")
    class UserPactTest {
    
        @Pact(consumer="consumer-springboot")
        public RequestResponsePact getUser(PactDslWithProvider builder) {
    
            PactDslJsonBody body = new PactDslJsonBody();
            body.stringType("id", "1");
            body.stringType("name", "Sebastian Suarez");
            body.stringType("email", "<mailto:sebastian@email.com|sebastian@email.com>");
            body.stringType("phone", "3145289654");
            body.stringType("password", "xhzASfe&1");
    
            return builder
                    .given("a user with ID 1 exists")
                    .uponReceiving("a request to get a user")
                    .path("/api/v1/users/1")
                    .method("GET")
                    .headers(headers())
                    .willRespondWith()
                    .status(200)
                    .body(body)
                    .toPact();
        }
    
        @Test
        @PactTestFor(pactMethod = "getUser")
        void testGetProduct(MockServer mockServer) throws IOException {
            UserData user = new UserRequest().setUrl(mockServer.getUrl()).getUser(1);
    
            assertThat(user.getName(), is("Sebastian Suarez"));
        }
    
        private Map<String, String> headers() {
            Map<String, String> headers = new HashMap<>();
            headers.put("Content-Type", "application/json; charset=utf-8");
            return headers;
        }
    }
    Copy code
    package consumer.pact.springboot;
    
    import org.apache.http.client.fluent.Request;
    
    import com.fasterxml.jackson.core.type.TypeReference;
    import com.fasterxml.jackson.databind.JsonMappingException;
    import com.fasterxml.jackson.databind.ObjectMapper;
    
    import java.io.IOException;
    import java.util.List;
    
    public class UserRequest {
        private String url;
    
        public UserRequest setUrl(String url) {
            this.url = url;
    
            return this;
        }
    
    
        public UserData getUser(int id) throws IOException {
            return Request.Get(this.url + "/api/v1/users/" + id)
                    .addHeader("Accept", "application/json")
                    .execute().handleResponse(httpResponse -> {
                        try {
                            ObjectMapper mapper = new ObjectMapper();
                            return mapper.readValue(httpResponse.getEntity().getContent(), UserData.class);
                        } catch (JsonMappingException e) {
                            throw new IOException(e);
                        }
                    });
        }
    
    }
    t
    m
    • 3
    • 9
  • p

    Pavithra Navaneeth

    02/06/2023, 12:42 AM
    hi there, is there a way to define PactDslWithProvided builder with optional arrays ? { "data": { "titles": [ { "titleId": "1234", "parenttitleId": "5678", "titleName": "test", "titleOwner": "xyzb", "titleArchitect": "abcde", "titleLeads": [ //optional array -- how to mention this - if exist - example to be of this type , if not - ignore the verification { "lead1": "xyz", "isEndorsed": true }, { "lead2": "abcd", "isEndorsed": false } ] }, { "titleId": "12345", "parenttitleId": "5678", "titleName": "test", "titleOwner": "xyzba", "titleArchitect": "abcdef" } ] } }
    u
    m
    +2
    • 5
    • 41
  • i

    Itzhak Eretz Kdosha

    02/06/2023, 12:16 PM
    Hi 🙂 When using Pact Juni5 Consumer, is it possible to configure an external mock-server instead of the "in process" one? Thanks
    u
    • 2
    • 2
  • b

    Basu Silviu

    02/06/2023, 12:38 PM
    hello everyone. It seems that the PactBroker attributes
    scheme
    ,
    host
    ,
    port
    are deprecated, but the documentation doesn't explicitly say what replaced them. I do see a
    url
    , Can any of you please confirm if
    url
    replaces the other 3?
    u
    • 2
    • 1
  • b

    Basu Silviu

    02/06/2023, 12:38 PM
    message has been deleted
  • é

    Édouard Lopez

    02/06/2023, 4:10 PM
    I'm having trouble running a publishing task via `gradlew`:
    Copy code
    java.lang.IllegalArgumentException: Invalid pact broker host specified ('${pactbroker.host:}'). Please provide a valid host or specify the system property 'pactbroker.host'.
    with the command
    Copy code
    ./gradlew testContract \
     -Ppact.verifier.publishResults=true \
     -Ppactbroker.url="<http://foo.bar>" \
     --info
    u
    • 2
    • 5
  • u

    Ulises Cervino

    02/06/2023, 7:16 PM
    is this supposed to be there: https://github.com/pact-foundation/pact-jvm/commit/edb04a4d92cc44ed834ead5abf59b416c3baa476#diff-ead43181ee3e540bfeb20[…]17e94bca8521f84ddbb00684784
    🤔 1
  • u

    Ulises Cervino

    02/06/2023, 7:17 PM
    more specifically the use of
    <http://miningmadness.com|miningmadness.com>
    u
    • 2
    • 5
1...1011121314Latest