Added messagingContentType
without this change you can by mistake use the http headers in a messaging headers which will fail to work with this change we're adding the messagingContentType() method that allows to properly set the content type fixes #296
This commit is contained in:
@@ -34,6 +34,7 @@ class Headers {
|
||||
|
||||
@Delegate MediaTypes mediaTypes = new MediaTypes()
|
||||
@Delegate HttpHeaders httpHeaders = new HttpHeaders()
|
||||
@Delegate MessagingHeaders messagingHeaders = new MessagingHeaders()
|
||||
|
||||
Set<Header> entries = []
|
||||
|
||||
@@ -60,6 +61,10 @@ class Headers {
|
||||
header(httpHeaders.contentType(), matching(contentType))
|
||||
}
|
||||
|
||||
void messagingContentType(String contentType) {
|
||||
header(messagingHeaders.messagingContentType(), matching(contentType))
|
||||
}
|
||||
|
||||
/**
|
||||
* If for the consumer / producer you want to match exactly only
|
||||
* the root of content type. I.e. {@code application/json;charset=UTF8}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.springframework.cloud.contract.spec.internal
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import groovy.transform.EqualsAndHashCode
|
||||
import groovy.transform.ToString
|
||||
|
||||
/**
|
||||
* Contains most commonly used messaging headers
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
* @since 1.1.2
|
||||
*/
|
||||
@CompileStatic
|
||||
@EqualsAndHashCode
|
||||
@ToString(includePackage = false)
|
||||
class MessagingHeaders {
|
||||
|
||||
/**
|
||||
* The Content Type of a message
|
||||
* @return
|
||||
*/
|
||||
String messagingContentType() {
|
||||
return "contentType"
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ def contractDsl = Contract.make {
|
||||
body('''{ "bookName" : "foo" }''')
|
||||
headers {
|
||||
header('BOOK-NAME', 'foo')
|
||||
messagingContentType(applicationJson())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,6 +61,7 @@ def contractDsl = Contract.make {
|
||||
ContractVerifierMessage response = contractVerifierMessaging.receive('activemq:output')
|
||||
assert response != null
|
||||
response.getHeader('BOOK-NAME')?.toString() == 'foo'
|
||||
response.getHeader('contentType')?.toString() == 'application/json'
|
||||
and:
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.payload))
|
||||
assertThatJson(parsedJson).field("bookName").isEqualTo("foo")
|
||||
@@ -81,6 +83,7 @@ def contractDsl = Contract.make {
|
||||
body('''{ "bookName" : "foo" }''')
|
||||
headers {
|
||||
header('BOOK-NAME', 'foo')
|
||||
messagingContentType(applicationJson())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,6 +104,8 @@ def contractDsl = Contract.make {
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.getHeader("BOOK-NAME")).isNotNull();
|
||||
assertThat(response.getHeader("BOOK-NAME").toString()).isEqualTo("foo");
|
||||
assertThat(response.getHeader("contentType")).isNotNull();
|
||||
assertThat(response.getHeader("contentType").toString()).isEqualTo("application/json");
|
||||
// and:
|
||||
DocumentContext parsedJson = JsonPath.parse(contractVerifierObjectMapper.writeValueAsString(response.getPayload()));
|
||||
assertThatJson(parsedJson).field("bookName").isEqualTo("foo");
|
||||
|
||||
Reference in New Issue
Block a user