pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.07k stars 475 forks source link

Could not configure empty value "" for path() method, automatically converted to value "/" #740

Open minhdoan159 opened 5 years ago

minhdoan159 commented 5 years ago

I am writing a pact record for url: http://localhost:8080, so code is as below:

return builder
        .given("Server root URL")
        .uponReceiving("An request at server root)
        .path("")
         .method(HttpMethod.GET.name())

But when run @Test method to create the pact record, failure happens with log:

au.com.dius.pact.consumer.PactMismatchesException: The following mismatched requests occurred:
Unexpected Request:
    method: GET
    path: /
    query: [:]
    headers: [Accept:text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2, Connection:keep-alive, Host:localhost:8080, User-agent:Java/1.8.0_161]
    matchers: MatchingRules(rules={})
    generators: Generators(categories={})
at au.com.dius.pact.consumer.junit.JUnitTestSupport.validateMockServerResult(JUnitTestSupport.kt:41)
    at au.com.dius.pact.consumer.BaseProviderRule.validateResult(BaseProviderRule.java:164)
    at au.com.dius.pact.consumer.BaseProviderRule$1.evaluate(BaseProviderRule.java:81)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:106)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

I am using au.com.dius:pact-jvm-consumer-junit_2.11:3.5.19 Could you please help to clarify why the path value could not be set to empty ("")? Many thanks!

uglyog commented 5 years ago

The path is not empty, it is coming into the mock server as /

Unexpected Request:
    method: GET
    path: /   <------
    query: [:]
    headers: [Accept:text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2, Connection:keep-alive, Host:localhost:8080, User-agent:Java/1.8.0_161]
    matchers: MatchingRules(rules={})
    generators: Generators(categories={})