1 package org.onap.integration.test.mocks.sniroemulator.extension;
3 import com.fasterxml.jackson.annotation.JsonCreator;
4 import com.fasterxml.jackson.annotation.JsonIgnore;
5 import com.fasterxml.jackson.annotation.JsonProperty;
6 import com.github.tomakehurst.wiremock.http.Body;
7 import com.github.tomakehurst.wiremock.http.HttpHeader;
8 import com.github.tomakehurst.wiremock.http.HttpHeaders;
9 import com.github.tomakehurst.wiremock.http.RequestMethod;
12 import java.util.List;
14 import static com.google.common.collect.Lists.newArrayList;
16 public class WebhookDefinition {
18 private RequestMethod method;
20 private List<HttpHeader> headers;
21 private Body body = Body.none();
24 public WebhookDefinition(@JsonProperty("method") RequestMethod method,
25 @JsonProperty("url") URI url,
26 @JsonProperty("headers") HttpHeaders headers,
27 @JsonProperty("body") String body,
28 @JsonProperty("base64Body") String base64Body) {
31 this.headers = newArrayList(headers.all());
32 this.body = Body.fromOneOf(null, body, null, base64Body);
35 public WebhookDefinition() {
38 public RequestMethod getMethod() {
46 public HttpHeaders getHeaders() {
47 return new HttpHeaders(headers);
50 public String getBase64Body() {
51 return body.isBinary() ? body.asBase64() : null;
54 public String getBody() {
55 return body.isBinary() ? null : body.asString();
59 public byte[] getBinaryBody() {
60 return body.asBytes();
63 public WebhookDefinition withMethod(RequestMethod method) {
68 public WebhookDefinition withUrl(URI url) {
73 public WebhookDefinition withUrl(String url) {
74 withUrl(URI.create(url));
78 public WebhookDefinition withHeaders(List<HttpHeader> headers) {
79 this.headers = headers;
83 public WebhookDefinition withHeader(String key, String... values) {
84 if (headers == null) {
85 headers = newArrayList();
88 headers.add(new HttpHeader(key, values));
92 public WebhookDefinition withBody(String body) {
93 this.body = new Body(body);
97 public WebhookDefinition withBinaryBody(byte[] body) {
98 this.body = new Body(body);