|
1 | 1 | package au.com.dius.pact.provider.junit5
|
2 | 2 |
|
| 3 | +import au.com.dius.pact.core.matchers.DefaultResponseGenerator |
3 | 4 | import au.com.dius.pact.core.model.Interaction
|
4 | 5 | import au.com.dius.pact.core.model.PactSource
|
5 | 6 | import au.com.dius.pact.core.model.RequestResponseInteraction
|
@@ -77,36 +78,55 @@ data class PactVerificationContext @JvmOverloads constructor(
|
77 | 78 | request: Any?,
|
78 | 79 | context: MutableMap<String, Any>
|
79 | 80 | ): List<VerificationResult> {
|
80 |
| - if (providerInfo.verificationType == null || providerInfo.verificationType == PactVerification.REQUEST_RESPONSE) { |
81 |
| - var interactionMessage = "Verifying a pact between ${consumer.name} and ${providerInfo.name}" + |
82 |
| - " - ${interaction.description}" |
83 |
| - if (interaction.isV4() && interaction.asV4Interaction().pending) { |
84 |
| - interactionMessage += " [PENDING]" |
85 |
| - } |
86 |
| - return try { |
87 |
| - val reqResInteraction = if (interaction is V4Interaction.SynchronousHttp) { |
88 |
| - interaction.asV3Interaction() |
89 |
| - } else { |
90 |
| - interaction as RequestResponseInteraction |
| 81 | + when (providerInfo.verificationType) { |
| 82 | + null, PactVerification.REQUEST_RESPONSE -> { |
| 83 | + var interactionMessage = "Verifying a pact between ${consumer.name} and ${providerInfo.name}" + |
| 84 | + " - ${interaction.description}" |
| 85 | + if (interaction.isV4() && interaction.asV4Interaction().pending) { |
| 86 | + interactionMessage += " [PENDING]" |
91 | 87 | }
|
92 |
| - val expectedResponse = reqResInteraction.response.generatedResponse(context, GeneratorTestMode.Provider) |
93 |
| - val actualResponse = target.executeInteraction(client, request) |
| 88 | + return try { |
| 89 | + val reqResInteraction = if (interaction is V4Interaction.SynchronousHttp) { |
| 90 | + interaction.asV3Interaction() |
| 91 | + } else { |
| 92 | + interaction as RequestResponseInteraction |
| 93 | + } |
| 94 | + val expectedResponse = DefaultResponseGenerator.generateResponse(reqResInteraction.response, context, GeneratorTestMode.Provider) |
| 95 | + val actualResponse = target.executeInteraction(client, request) |
94 | 96 |
|
95 |
| - listOf(verifier!!.verifyRequestResponsePact(expectedResponse, actualResponse, interactionMessage, mutableMapOf(), |
96 |
| - reqResInteraction.interactionId.orEmpty(), consumer.pending)) |
97 |
| - } catch (e: Exception) { |
98 |
| - verifier!!.reporters.forEach { |
99 |
| - it.requestFailed(providerInfo, interaction, interactionMessage, e, |
100 |
| - verifier!!.projectHasProperty.apply(ProviderVerifier.PACT_SHOW_STACKTRACE)) |
| 97 | + listOf( |
| 98 | + verifier!!.verifyRequestResponsePact( |
| 99 | + expectedResponse, actualResponse, interactionMessage, mutableMapOf(), |
| 100 | + reqResInteraction.interactionId.orEmpty(), consumer.pending |
| 101 | + ) |
| 102 | + ) |
| 103 | + } catch (e: Exception) { |
| 104 | + verifier!!.reporters.forEach { |
| 105 | + it.requestFailed( |
| 106 | + providerInfo, interaction, interactionMessage, e, |
| 107 | + verifier!!.projectHasProperty.apply(ProviderVerifier.PACT_SHOW_STACKTRACE) |
| 108 | + ) |
| 109 | + } |
| 110 | + listOf( |
| 111 | + VerificationResult.Failed( |
| 112 | + "Request to provider failed with an exception", interactionMessage, |
| 113 | + mapOf( |
| 114 | + interaction.interactionId.orEmpty() to |
| 115 | + listOf(VerificationFailureType.ExceptionFailure("Request to provider failed with an exception", e)) |
| 116 | + ), |
| 117 | + consumer.pending |
| 118 | + ) |
| 119 | + ) |
101 | 120 | }
|
102 |
| - listOf(VerificationResult.Failed("Request to provider failed with an exception", interactionMessage, |
103 |
| - mapOf(interaction.interactionId.orEmpty() to |
104 |
| - listOf(VerificationFailureType.ExceptionFailure("Request to provider failed with an exception", e))), |
105 |
| - consumer.pending)) |
106 | 121 | }
|
107 |
| - } else { |
108 |
| - return listOf(verifier!!.verifyResponseByInvokingProviderMethods(providerInfo, consumer, interaction, |
109 |
| - interaction.description, mutableMapOf(), false)) |
| 122 | + PactVerification.PLUGIN -> { |
| 123 | + return listOf(verifier!!.verifyInteractionViaPlugin(providerInfo, consumer, interaction, |
| 124 | + client, request, context + ("userConfig" to target.userConfig))) |
| 125 | + } |
| 126 | + else -> { |
| 127 | + return listOf(verifier!!.verifyResponseByInvokingProviderMethods(providerInfo, consumer, interaction, |
| 128 | + interaction.description, mutableMapOf(), false)) |
| 129 | + } |
110 | 130 | }
|
111 | 131 | }
|
112 | 132 |
|
|
0 commit comments