-
-
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.
chore: add a test to verify matching a number with a regular expression
- Loading branch information
Ronald Holshausen
committed
Aug 1, 2021
1 parent
e2970f3
commit 4cde881
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...r/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/MatchNumberWithRegexTest.groovy
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,47 @@ | ||
package au.com.dius.pact.provider.junit5 | ||
|
||
import au.com.dius.pact.provider.junitsupport.Provider | ||
import au.com.dius.pact.provider.junitsupport.loader.PactFolder | ||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import groovy.util.logging.Slf4j | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.TestTemplate | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import ru.lanwen.wiremock.ext.WiremockResolver | ||
import ru.lanwen.wiremock.ext.WiremockUriResolver | ||
|
||
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 | ||
|
||
@Provider('NumberService') | ||
@PactFolder('pacts') | ||
@ExtendWith([ | ||
WiremockResolver, | ||
WiremockUriResolver | ||
]) | ||
@Slf4j | ||
class MatchNumberWithRegexTest { | ||
|
||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider) | ||
void testTemplate(PactVerificationContext context) { | ||
context.verifyInteraction() | ||
} | ||
|
||
@BeforeEach | ||
void before(PactVerificationContext context, @WiremockResolver.Wiremock WireMockServer server, | ||
@WiremockUriResolver.WiremockUri String uri) throws MalformedURLException { | ||
context.setTarget(HttpTestTarget.fromUrl(new URL(uri))) | ||
|
||
server.stubFor( | ||
get(urlPathEqualTo('/data')) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader('Content-Type', 'application/json') | ||
.withBody('{\n' + | ||
' "number": 47576476.9092\n' + | ||
'}')) | ||
) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
provider/junit5/src/test/resources/pacts/match-numbers.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,40 @@ | ||
{ | ||
"provider": { | ||
"name": "NumberService" | ||
}, | ||
"consumer": { | ||
"name": "consumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "Get data", | ||
"request": { | ||
"method": "GET", | ||
"path": "/data" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"body": { | ||
"number": 1234.5677 | ||
}, | ||
"matchingRules": { | ||
"body": { | ||
"$.number": { | ||
"matchers": [ | ||
{ | ||
"match": "regex", | ||
"regex": "\\d+\\.\\d{4}" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"pact-specification": { | ||
"version": "3.0.0" | ||
} | ||
} | ||
} |