-
-
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.
refactor: support multiple providerinfo in JUnit 5 tests #1342
- Loading branch information
Ronald Holshausen
committed
May 8, 2021
1 parent
20da4aa
commit 4a6c7df
Showing
6 changed files
with
125 additions
and
48 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
74 changes: 74 additions & 0 deletions
74
consumer/junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/MultiProviderTest.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,74 @@ | ||
package au.com.dius.pact.consumer.junit5 | ||
|
||
import au.com.dius.pact.consumer.MockServer | ||
import au.com.dius.pact.consumer.dsl.PactDslWithProvider | ||
import au.com.dius.pact.core.model.RequestResponsePact | ||
import au.com.dius.pact.core.model.annotations.Pact | ||
import groovyx.net.http.FromServer | ||
import groovyx.net.http.HttpBuilder | ||
import org.junit.jupiter.api.Disabled | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonBody | ||
|
||
@SuppressWarnings('UnusedMethodParameter') | ||
@ExtendWith(PactConsumerTestExt) | ||
@Disabled | ||
class MultiProviderTest { | ||
|
||
@Pact(provider = 'provider1', consumer= 'consumer') | ||
RequestResponsePact pact1(PactDslWithProvider builder) { | ||
builder | ||
.uponReceiving('a new user') | ||
.path('/some-service/users') | ||
.method('POST') | ||
.body(newJsonBody { | ||
it.stringValue('name', 'bob') | ||
}.build()) | ||
.willRespondWith() | ||
.status(201) | ||
.matchHeader('Location', 'http(s)?://\\w+:\\d+//some-service/user/\\w{36}$') | ||
.toPact() | ||
} | ||
|
||
@Pact(provider = 'provider2', consumer= 'consumer') | ||
RequestResponsePact pact2(PactDslWithProvider builder) { | ||
builder | ||
.uponReceiving('a new user') | ||
.path('/some-service/users') | ||
.method('POST') | ||
.body(newJsonBody { | ||
it.numberType('id') | ||
}.build()) | ||
.willRespondWith() | ||
.status(204) | ||
.toPact() | ||
} | ||
|
||
@Test | ||
@PactTestFor(pactMethods = ['pact1', 'pact2']) | ||
void runTest1(MockServer mockServer1, MockServer mockServer2) { | ||
def http = HttpBuilder.configure { request.uri = mockServer1.url } | ||
|
||
http.post { | ||
request.uri.path = '/some-service/users' | ||
request.body = user() | ||
request.contentType = 'application/json' | ||
|
||
response.success { FromServer fs, Object body -> | ||
assert fs.statusCode == 201 | ||
assert fs.headers.find { it.key == 'Location' }?.value?.contains(SOME_SERVICE_USER) | ||
} | ||
} | ||
|
||
http.get { | ||
request.uri.path = SOME_SERVICE_USER + EXPECTED_USER_ID | ||
request.contentType = 'application/json' | ||
response.success { FromServer fs, Object body -> | ||
assert fs.statusCode == 200 | ||
} | ||
} | ||
|
||
} | ||
} |
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 |
---|---|---|
|
@@ -167,5 +167,4 @@ class MultiTest { | |
.status(404) | ||
.toPact() | ||
} | ||
|
||
} |
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
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
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