-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(V4): Add a JUnit 4 test using the status code matcher
- Loading branch information
1 parent
d49675b
commit 9097226
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
provider/junit/src/test/java/au/com/dius/pact/provider/junit/V4StatusCodeMatcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package au.com.dius.pact.provider.junit; | ||
|
||
import au.com.dius.pact.provider.junit.target.HttpTarget; | ||
import au.com.dius.pact.provider.junitsupport.Provider; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactFolder; | ||
import au.com.dius.pact.provider.junitsupport.target.Target; | ||
import au.com.dius.pact.provider.junitsupport.target.TestTarget; | ||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.runner.RunWith; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; | ||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; | ||
|
||
@RunWith(PactRunner.class) | ||
@Provider("V4Service") | ||
@PactFolder("pacts") | ||
public class V4StatusCodeMatcherTest { | ||
@Rule | ||
public WireMockRule wireMockRule = new WireMockRule(options().port(8888), false); | ||
|
||
@TestTarget | ||
public final Target httpTarget = new HttpTarget(8888); | ||
|
||
@Before | ||
public void before() { | ||
wireMockRule.stubFor( | ||
get(urlPathEqualTo("/test")) | ||
.willReturn(aResponse().withStatus(204)) | ||
); | ||
wireMockRule.stubFor( | ||
get(urlPathEqualTo("/test2")) | ||
.willReturn(aResponse().withStatus(404)) | ||
); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
provider/junit/src/test/resources/pacts/v4-status-code-pact.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"consumer": { | ||
"name": "V4Consumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "a test request, part 2", | ||
"key": "b3a96005", | ||
"pending": false, | ||
"request": { | ||
"method": "GET", | ||
"path": "/test2" | ||
}, | ||
"response": { | ||
"matchingRules": { | ||
"status": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "statusCode", | ||
"status": "clientError" | ||
} | ||
] | ||
} | ||
}, | ||
"status": 400 | ||
}, | ||
"type": "Synchronous/HTTP" | ||
}, | ||
{ | ||
"description": "a test request", | ||
"key": "a98bd112", | ||
"pending": false, | ||
"request": { | ||
"method": "GET", | ||
"path": "/test" | ||
}, | ||
"response": { | ||
"matchingRules": { | ||
"status": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "statusCode", | ||
"status": "success" | ||
} | ||
] | ||
} | ||
}, | ||
"status": 200 | ||
}, | ||
"type": "Synchronous/HTTP" | ||
} | ||
], | ||
"metadata": { | ||
"pact-jvm": { | ||
"version": "4.2.7" | ||
}, | ||
"pactSpecification": { | ||
"version": "4.0" | ||
} | ||
}, | ||
"provider": { | ||
"name": "V4Service" | ||
} | ||
} |