Skip to content

Commit

Permalink
feat(V4): Add a JUnit 4 test using the status code matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Jun 27, 2023
1 parent d49675b commit 9097226
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
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 provider/junit/src/test/resources/pacts/v4-status-code-pact.json
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"
}
}

0 comments on commit 9097226

Please sign in to comment.