-
-
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: Add tests for supportingmultiple test targets with JUnit 5 #1708
- Loading branch information
1 parent
4687d96
commit 9a8d121
Showing
13 changed files
with
388 additions
and
3 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
21 changes: 21 additions & 0 deletions
21
provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/HttpTestTargetSpec.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,21 @@ | ||
package au.com.dius.pact.provider.junit5 | ||
|
||
import au.com.dius.pact.core.model.RequestResponseInteraction | ||
import au.com.dius.pact.core.model.V4Interaction | ||
import au.com.dius.pact.core.model.messaging.Message | ||
import spock.lang.Specification | ||
|
||
class HttpTestTargetSpec extends Specification { | ||
def 'supports any HTTP interaction'() { | ||
expect: | ||
new HttpTestTarget().supportsInteraction(interaction) == result | ||
|
||
where: | ||
interaction | result | ||
new RequestResponseInteraction('test') | true | ||
new Message('test') | false | ||
new V4Interaction.AsynchronousMessage('test') | false | ||
new V4Interaction.SynchronousMessages('test') | false | ||
new V4Interaction.SynchronousHttp('test') | true | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/MessageTestTargetSpec.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,21 @@ | ||
package au.com.dius.pact.provider.junit5 | ||
|
||
import au.com.dius.pact.core.model.RequestResponseInteraction | ||
import au.com.dius.pact.core.model.V4Interaction | ||
import au.com.dius.pact.core.model.messaging.Message | ||
import spock.lang.Specification | ||
|
||
class MessageTestTargetSpec extends Specification { | ||
def 'supports any message interaction'() { | ||
expect: | ||
new MessageTestTarget().supportsInteraction(interaction) == result | ||
|
||
where: | ||
interaction | result | ||
new RequestResponseInteraction('test') | false | ||
new Message('test') | true | ||
new V4Interaction.AsynchronousMessage('test') | true | ||
new V4Interaction.SynchronousMessages('test') | true | ||
new V4Interaction.SynchronousHttp('test') | false | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PluginTestTargetSpec.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,21 @@ | ||
package au.com.dius.pact.provider.junit5 | ||
|
||
import au.com.dius.pact.core.model.V4Interaction | ||
import spock.lang.Specification | ||
import au.com.dius.pact.core.model.RequestResponseInteraction | ||
import au.com.dius.pact.core.model.messaging.Message | ||
|
||
class PluginTestTargetSpec extends Specification { | ||
def 'supports any V4 interaction'() { | ||
expect: | ||
new PluginTestTarget().supportsInteraction(interaction) == result | ||
|
||
where: | ||
interaction | result | ||
new RequestResponseInteraction('test') | false | ||
new Message('test') | false | ||
new V4Interaction.AsynchronousMessage('test') | true | ||
new V4Interaction.SynchronousMessages('test') | true | ||
new V4Interaction.SynchronousHttp('test') | true | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...der/junit5/src/test/java/au/com/dius/pact/provider/junit5/CombinedHttpAndMessageTest.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,65 @@ | ||
package au.com.dius.pact.provider.junit5; | ||
|
||
import au.com.dius.pact.provider.MessageAndMetadata; | ||
import au.com.dius.pact.provider.PactVerifyProvider; | ||
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 org.apache.hc.core5.http.HttpRequest; | ||
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 java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Map; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
import static java.lang.String.format; | ||
|
||
@Provider("test_provider_combined") | ||
@PactFolder("pacts") | ||
@ExtendWith({ | ||
WiremockResolver.class, | ||
WiremockUriResolver.class | ||
}) | ||
public class CombinedHttpAndMessageTest { | ||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider.class) | ||
void testTemplate(HttpRequest request, PactVerificationContext context) { | ||
if (request != null) { | ||
request.addHeader("X-ContractTest", "true"); | ||
} | ||
|
||
context.verifyInteraction(); | ||
} | ||
|
||
@BeforeEach | ||
void before(PactVerificationContext context, | ||
@WiremockResolver.Wiremock WireMockServer server, | ||
@WiremockUriResolver.WiremockUri String uri) throws MalformedURLException { | ||
context.setTarget(HttpTestTarget.fromUrl(new URL(uri))); | ||
context.addAdditionalTarget(new MessageTestTarget()); | ||
|
||
server.stubFor( | ||
get(urlPathEqualTo("/data")) | ||
.withHeader("X-ContractTest", equalTo("true")) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("content-type", "application/json") | ||
.withBody("{}") | ||
) | ||
); | ||
} | ||
|
||
@State("message exists") | ||
public void messageExits() { } | ||
|
||
@PactVerifyProvider("Test Message") | ||
public MessageAndMetadata message() { | ||
return new MessageAndMetadata("{\"a\": \"1234-1234\"}".getBytes(), Map.of("destination", "a/b/c")); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
provider/junit5/src/test/resources/pacts/v4-combined-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,61 @@ | ||
{ | ||
"provider": { | ||
"name": "test_provider_combined" | ||
}, | ||
"consumer": { | ||
"name": "test_consumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"type": "Synchronous/HTTP", | ||
"key": "001", | ||
"description": "test http interaction", | ||
"request": { | ||
"method": "GET", | ||
"path": "/data" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"body": { | ||
"contentType": "application/json", | ||
"encoded": false, | ||
"content": { | ||
|
||
} | ||
} | ||
} | ||
}, { | ||
"type": "Asynchronous/Messages", | ||
"key": "m_001", | ||
"metadata": { | ||
"contentType": "application/json", | ||
"destination": "a/b/c" | ||
}, | ||
"providerStates": [ | ||
{ | ||
"name": "message exists" | ||
} | ||
], | ||
"contents": { | ||
"contentType": "application/json", | ||
"encoded": false, | ||
"content": { | ||
"a": "1234-1234" | ||
} | ||
}, | ||
"generators": { | ||
"content": { | ||
"a": { | ||
"type": "Uuid" | ||
} | ||
} | ||
}, | ||
"description": "Test Message" | ||
} | ||
], | ||
"metadata": { | ||
"pactSpecification": { | ||
"version": "4.0" | ||
} | ||
} | ||
} |
8 changes: 7 additions & 1 deletion
8
...5spring/src/main/kotlin/au/com/dius/pact/provider/spring/junit5/WebFluxBasedTestTarget.kt
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
Oops, something went wrong.