Update after code review comments

- Let client specify the full content type and take default value if the content type
   is null
 - Fixes #7
This commit is contained in:
Giri Dandu 2015-03-25 12:06:34 -04:00
parent 9920b2acdd
commit 871edc668e
3 changed files with 32 additions and 5 deletions

View File

@ -19,7 +19,7 @@ class HookRequest {
private DateTime deliverAfter
@JsonProperty
private String contentTypeParam
private String contentType
/** Constructor for Jackson */
HookRequest() { }
@ -28,10 +28,10 @@ class HookRequest {
* Default constructor for creating a simple HookRequest with a URL and the
* POST data to be delivered to that URL
*/
HookRequest(String hookUrl, String hookData, String contentTypeParam) {
HookRequest(String hookUrl, String hookData, String contentType) {
this.retries = 0
this.url = hookUrl
this.postData = hookData
this.contentTypeParam = contentTypeParam
this.contentType = contentType
}
}

View File

@ -13,6 +13,7 @@ import javax.ws.rs.ProcessingException
* request logic for Whoas
*/
class Publisher {
private final String DEFAULT_CONTENT_TYPE = 'application/json'
/** Maximum number of failures we will retry on */
private final int DEFAULT_MAX_RETRIES = 5
@ -102,7 +103,7 @@ class Publisher {
return jerseyClient.target(request.url)
.request()
.buildPost(Entity.entity(request.postData,
"application/vnd." + request.contentTypeParam + "+json"))
request.contentType? request.contentType: DEFAULT_CONTENT_TYPE))
}
}

View File

@ -49,7 +49,33 @@ class PublisherSpec extends Specification {
given:
Invocation inv
HookRequest request = new HookRequest('http://example.com',
'magic post data!','appname.event1.v1')
'magic post data!','application/vnd.appname.event1.v1+json')
when:
inv = publisher.buildInvocationFrom(request)
then:
inv instanceof Invocation
}
def "buildInvocationFrom() should create a valid Jersey Invocation when content type is null"() {
given:
Invocation inv
HookRequest request = new HookRequest('http://example.com',
'magic post data!', null)
when:
inv = publisher.buildInvocationFrom(request)
then:
inv instanceof Invocation
}
def "buildInvocationFrom() should create a valid Jersey Invocation when content type is empty"() {
given:
Invocation inv
HookRequest request = new HookRequest('http://example.com',
'magic post data!', '')
when:
inv = publisher.buildInvocationFrom(request)