-
-
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.
Merge pull request #1340 from keeping-it-up/1330-issue
issue # 1330 fixed and a test case added with expression in body with application/xthrift content type
- Loading branch information
Showing
3 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
...c/test/groovy/au/com/dius/pact/provider/junit5/ThriftStateInjectedProviderPostTest.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,53 @@ | ||
package au.com.dius.pact.provider.junit5 | ||
|
||
import au.com.dius.pact.provider.junitsupport.Provider | ||
import au.com.dius.pact.provider.junitsupport.State | ||
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.* | ||
|
||
@Provider('ThriftJsonPostService') | ||
@PactFolder('pacts') | ||
@ExtendWith([ | ||
WiremockResolver, | ||
WiremockUriResolver | ||
]) | ||
@Slf4j | ||
class ThriftStateInjectedProviderPostTest { | ||
|
||
@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))) | ||
System.setProperty('pact.content_type.override.application/x-thrift', 'json') | ||
|
||
server.stubFor( | ||
post(urlPathEqualTo('/data/1234')) | ||
.withRequestBody(containing("{\"id\":\"abc\"}")) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader('Content-Type', 'application/x-thrift') | ||
.withBody('{"accountId": "4545"}')) | ||
) | ||
} | ||
|
||
@State('default state') | ||
Map<String, Object> defaultState() { | ||
[ | ||
id: 'abc' | ||
] | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
provider/junit5/src/test/resources/pacts/thrift-pact-post.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,73 @@ | ||
{ | ||
"provider": { | ||
"name": "ThriftJsonPostService" | ||
}, | ||
"consumer": { | ||
"name": "ThriftJsonConsumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"providerStates": [ | ||
{ | ||
"name": "default state" | ||
} | ||
], | ||
"description": "Thrift request", | ||
"request": { | ||
"method": "POST", | ||
"path": "/data/1234", | ||
"body": { | ||
"id": "xyz" | ||
}, | ||
"generators": { | ||
"body": { | ||
"$.id": { | ||
"expression": "${id}", | ||
"type": "ProviderState" | ||
} | ||
} | ||
}, | ||
"headers": { | ||
"Content-Type": ["application/x-thrift"] | ||
} | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": ["application/x-thrift"] | ||
}, | ||
"body": { | ||
"accountId": "4beb44f1-53f7-4281-a78b-12c06d682067" | ||
}, | ||
"matchingRules": { | ||
"body": { | ||
"$.accountId": { | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
], | ||
"combine": "AND" | ||
} | ||
} | ||
}, | ||
"generators": { | ||
"body": { | ||
"$.accountId": { | ||
"type": "ProviderState", | ||
"expression": "${accountId}" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"pact-specification": { | ||
"version": "3.0.0" | ||
}, | ||
"pact-jvm": { | ||
"version": "4.2.2" | ||
} | ||
} | ||
} |