Orhun Vatansever
10/18/2022, 7:51 PMpact-jvm-consumer-java8_2.12
, and the python one using pact-foundation package. I can see the pacts published on my broker, and when I want to verify my producer contract in python, I get an error called "no matched handler". I saw some github discussions about message queue contracts being v3 and python having ruby implementation which supports v2, could this error be about that? I'm also sharing my logs, can provide more info if needed. Many thanks
I, [2022-10-18T22:10:20.628161 #97499] INFO -- : Running example 'Verifying a pact between sms-consumer and sms-provider Given a user was created a create event has matching content'
I, [2022-10-18T22:10:20.629846 #97499] INFO -- : Sending POST request to path: "/" with headers: {"CONTENT_TYPE"=>"application/json", "HTTP_X_PACT_ORIGINAL_HEADER_NAMES"=>"Content-Type", "X_PACT_PROVIDER_STATES"=>[{"name"=>"a user was created"}]}, see debug logs for body
D, [2022-10-18T22:10:20.629899 #97499] DEBUG -- : body :{"description":"a create event","providerStates":[{"name":"a user was created","params":{}}],"metadata":{"Content-Type":"application/json; charset=UTF-8"}}
I, [2022-10-18T22:10:20.646374 #97499] INFO -- : Received response with status: 500, headers: {"Date"=>"Tue, 18 Oct 2022 19:10:20 GMT", "Server"=>"uvicorn", "Content-Length"=>"32", "Content-Type"=>"application/json"}, see debug logs for body
D, [2022-10-18T22:10:20.646463 #97499] DEBUG -- : body: {"detail":"No matched handler."}
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Orhun Vatansever
10/19/2022, 5:57 AMimport au.com.dius.pact.consumer.MessagePactBuilder
import au.com.dius.pact.consumer.MessagePactProviderRule
import au.com.dius.pact.consumer.Pact
import au.com.dius.pact.consumer.PactVerification
import au.com.dius.pact.model.v3.messaging.MessagePact
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.intenseye.notificationapi.model.EmailRequest
import com.intenseye.notificationapi.model.SmsRequest
import io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody
import org.junit.Rule
import org.junit.Test
class NotificationContractTest {
@get:Rule
val pactSmsRule = MessagePactProviderRule("sms-provider", this)
@get:Rule
val pactEmailRule = MessagePactProviderRule("email-provider", this)
@Pact(provider = "sms-provider", consumer = "sms-consumer")
fun createSmsEvent(builder: MessagePactBuilder): MessagePact {
val body = newJsonBody { body ->
body.stringType("to", "<mailto:email@mail.com|email@mail.com>")
body.stringValue("body", "Alert")
}.build()
return builder.given("a user was created")
.expectsToReceive("a create event")
.withContent(body)
.toPact()
}
@Pact(provider = "email-provider", consumer = "email-consumer")
fun createEmailEvent(builder: MessagePactBuilder): MessagePact {
val body = newJsonBody { body ->
body.array("to") {
it.stringValue("<mailto:email@mail.com|email@mail.com>")
}
body.stringValue("from", "Alert")
body.stringValue("senderName", "Alert")
body.stringValue("subject", "Alert")
body.stringValue("body", "Alert")
body.stringValue("templateName", "Alert")
body.`object`("templateParams") {
it.stringType("param1", "value1")
it.stringType("param2", "value2")
}
body.array("cc") {
it.stringValue("<mailto:email@mail.com|email@mail.com>")
}
body.array("bcc") {
it.stringValue("<mailto:email@mail.com|email@mail.com>")
}
}.build()
return builder.given("a user was created")
.expectsToReceive("a create event")
.withContent(body)
.toPact()
}
@Test
@PactVerification("sms-provider", fragment = "createSmsEvent")
fun canParseCreateSmsEvent() {
jacksonObjectMapper().readValue(pactSmsRule.message, SmsRequest::class.java)
}
@Test
@PactVerification("email-provider", fragment = "createEmailEvent")
fun canParseCreateEmailEvent() {
jacksonObjectMapper().readValue(pactEmailRule.message, EmailRequest::class.java)
}
}
and publish them with mvn verify:pact publishOrhun Vatansever
10/19/2022, 5:59 AMdef sms_notification_handler():
return {
"to": "<mailto:email@mail.com|email@mail.com>",
"body": "Alert"
}
def test_verify_success():
provider = MessageProvider(
message_providers={
'a create event': sms_notification_handler
},
provider='sms-provider',
consumer='sms-consumer',
)
with provider:
provider.verify_with_broker(broker_url='<http://10.102.127.5:80>',
log_level='DEBUG',
publish_version='0.0.1',
publish_verification_results=True)
Orhun Vatansever
10/19/2022, 7:03 AM{
"consumer": {
"name": "sms-consumer"
},
"provider": {
"name": "sms-provider"
},
"messages": [
{
"_id": "3a837aa529513ced39204e2ab42f06dd3dc63022",
"description": "a create event",
"metaData": {
"Content-Type": "application/json; charset=UTF-8"
},
"contents": {
"body": "Alert",
"to": "<mailto:email@mail.com|email@mail.com>"
},
"providerStates": [
{
"name": "a user was created"
}
],
"matchingRules": {
"body": {
"$.to": {
"matchers": [
{
"match": "type"
}
],
"combine": "AND"
}
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "3.0.0"
},
"pact-jvm": {
"version": "3.5.21"
}
}
}
Orhun Vatansever
10/19/2022, 8:08 AM{
"to": "<mailto:email@mail.com|email@mail.com>",
"body": "Alert"
}
)
to the one it receives from pact broker, am I thinking wrong? Btw I haven't observed a pact directory generation in my python project, but it might be normal behaviour since I don't need mocking in provider, I just want to verify that my provider model fits the consumer requirement in brokerMatt (pactflow.io / pact-js / pact-go)
a user was created
stateOrhun Vatansever
10/19/2022, 12:12 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Orhun Vatansever
10/19/2022, 12:34 PMD, [2022-10-18T22:10:20.629899 #97499] DEBUG -- : body :{"description":"a create event","providerStates":[{"name":"a user was created","params":{}}],"metadata":{"Content-Type":"application/json; charset=UTF-8"}}
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Orhun Vatansever
10/19/2022, 12:40 PMmessage_providers={
'a create event': sms_notification_handler
}
Orhun Vatansever
10/19/2022, 12:47 PMOrhun Vatansever
10/19/2022, 2:11 PMa user was created
. I found it after debugging def _match_states(payload):
method in http_proxy.py
.Orhun Vatansever
10/19/2022, 2:12 PMMatt (pactflow.io / pact-js / pact-go)