Skip to content

Commit

Permalink
fix: MessagePactBuilder was not including the generators #1278
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Dec 27, 2020
1 parent 0c1eef4 commit bc73a74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import au.com.dius.pact.consumer.dsl.Matchers
import au.com.dius.pact.consumer.dsl.PactDslJsonBody
import au.com.dius.pact.consumer.xml.PactXmlBuilder
import au.com.dius.pact.core.model.OptionalBody
import au.com.dius.pact.core.model.generators.DateTimeGenerator
import au.com.dius.pact.core.model.messaging.Message
import au.com.dius.pact.core.model.ProviderState
import groovy.json.JsonSlurper
Expand Down Expand Up @@ -153,7 +154,7 @@ class MessagePactBuilderSpec extends Specification {
pact.providerStates.last() == expectedProviderState
}

def 'should support XML content'() {
def 'supports XML content'() {
given:
def xmlContent = new PactXmlBuilder("root")
.build(root -> {
Expand Down Expand Up @@ -185,4 +186,23 @@ class MessagePactBuilderSpec extends Specification {
] as Set

}

@Issue('#1278')
def 'Include any generators defined for the message contents'() {
given:
def body = new PactDslJsonBody()
.datetime('DT')
def category = au.com.dius.pact.core.model.generators.Category.BODY

when:
def pact = MessagePactBuilder
.consumer('MessagePactBuilderSpec')
.expectsToReceive('a message with generators')
.withContent(body).toPact()
Message message = pact.interactions.first()
def generators = message.generators

then:
generators.categories[category] == ['$.DT': new DateTimeGenerator("yyyy-MM-dd'T'HH:mm:ss")]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class MessagePactBuilder(
message.contents = OptionalBody.body(parent.toString().toByteArray(contentType.asCharset()), contentType)
message.metaData = metadata
message.matchingRules.addCategory(parent.matchers)
message.generators.addGenerators(parent.generators)

return this
}
Expand Down

0 comments on commit bc73a74

Please sign in to comment.