Migrated the destination for Pact to meta-data

This commit is contained in:
Marcin Grzejszczak
2019-01-08 15:08:51 +01:00
parent 70adb02ec9
commit e12b0b74b6
4 changed files with 17 additions and 13 deletions

View File

@@ -1559,6 +1559,11 @@ Next to that the request and path matchers are skipped during the conversion.
When using a date, time or datetime value generator with a given format,
the given format will be skipped and the ISO format will be used.
In order to properly support the Spring Cloud Contract way of doing messaging
with Pact you'll have to provide some additional meta data entries. Below you can find a list of such entries:
- to define the destination to which a message gets sent, you have to
set a `metaData` entry in the Pact file, with key `sentTo` equal to the destination to which a message is to be sent. E.g. `"metaData": { "sentTo": "activemq:output" }`
==== Pact Contract

View File

@@ -33,10 +33,10 @@ import au.com.dius.pact.model.v3.messaging.Message
import au.com.dius.pact.model.v3.messaging.MessagePact
import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import org.springframework.cloud.contract.spec.Contract
import org.springframework.cloud.contract.verifier.util.JsonPaths
import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter
/**
* Creator of {@link Contract} instances
*
@@ -48,6 +48,8 @@ import org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter
class MessagingSCContractCreator {
private static final String FULL_BODY = '$'
private static final String DESTINATION_KEY = "sentTo"
private static final List<String> NON_HEADER_META_DATA = [DESTINATION_KEY]
Collection<Contract> convertFrom(MessagePact pact) {
return pact.messages.collect({ Message message ->
@@ -68,7 +70,6 @@ class MessagingSCContractCreator {
if (ruleGroup.ruleLogic != RuleLogic.AND) {
throw new UnsupportedOperationException("Currently only the AND combination rule logic is supported")
}
if (FULL_BODY == key) {
JsonPaths jsonPaths = JsonToJsonPathsConverter.transformToJsonPathWithStubsSideValuesAndNoArraySizeCheck(message.contents.value)
jsonPaths.each {
@@ -127,15 +128,16 @@ class MessagingSCContractCreator {
message.metaData.each { String k, String v ->
if (k.equalsIgnoreCase("contentType")) {
messagingContentType(v)
} else {
} else if (!NON_HEADER_META_DATA.contains(k)) {
header(k, v)
}
}
}
}
sentTo(guessDestination(message));
String dest = findDestination(message)
if (dest) {
sentTo(dest)
}
}
}
})
@@ -150,12 +152,8 @@ class MessagingSCContractCreator {
.uncapitalize() + "()"
}
private String guessDestination(Message message) {
String[] outcomeParts = message.description.split(' ')
if (outcomeParts.length > 0) {
return outcomeParts[outcomeParts.length - 1]
}
return ''
private String findDestination(Message message) {
return message.metaData.get(DESTINATION_KEY) ?: ""
}
}

View File

@@ -650,10 +650,10 @@ class PactContractConverterSpec extends Specification {
}
def "should convert from pact v3 messaging to one SC message contract"() {
given:
Collection<Contract> expectedContracts = [
Contract.make {
description()
label 'message sent to activemq:output'
input {
triggeredBy('bookReturnedTriggered()')

View File

@@ -9,6 +9,7 @@
{
"description":"message sent to activemq:output",
"metaData":{
"sentTo": "activemq:output",
"BOOK-NAME":"foo",
"contentType":"application/json"
},