2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.integration.test.mocks.sniroemulator.extension;
22 import com.fasterxml.jackson.annotation.JsonCreator;
23 import com.fasterxml.jackson.annotation.JsonIgnore;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import com.github.tomakehurst.wiremock.http.Body;
26 import com.github.tomakehurst.wiremock.http.HttpHeader;
27 import com.github.tomakehurst.wiremock.http.HttpHeaders;
28 import com.github.tomakehurst.wiremock.http.RequestMethod;
31 import java.util.List;
33 import static com.google.common.collect.Lists.newArrayList;
35 public class WebhookDefinition {
37 private RequestMethod method;
39 private List<HttpHeader> headers;
40 private Body body = Body.none();
43 public WebhookDefinition(@JsonProperty("method") RequestMethod method,
44 @JsonProperty("url") URI url,
45 @JsonProperty("headers") HttpHeaders headers,
46 @JsonProperty("body") String body,
47 @JsonProperty("base64Body") String base64Body) {
50 this.headers = newArrayList(headers.all());
51 this.body = Body.fromOneOf(null, body, null, base64Body);
54 public WebhookDefinition() {
57 public RequestMethod getMethod() {
65 public HttpHeaders getHeaders() {
66 return new HttpHeaders(headers);
69 public String getBase64Body() {
70 return body.isBinary() ? body.asBase64() : null;
73 public String getBody() {
74 return body.isBinary() ? null : body.asString();
78 public byte[] getBinaryBody() {
79 return body.asBytes();
82 public WebhookDefinition withMethod(RequestMethod method) {
87 public WebhookDefinition withUrl(URI url) {
92 public WebhookDefinition withUrl(String url) {
93 withUrl(URI.create(url));
97 public WebhookDefinition withHeaders(List<HttpHeader> headers) {
98 this.headers = headers;
102 public WebhookDefinition withHeader(String key, String... values) {
103 if (headers == null) {
104 headers = newArrayList();
107 headers.add(new HttpHeader(key, values));
111 public WebhookDefinition withBody(String body) {
112 this.body = new Body(body);
116 public WebhookDefinition withBinaryBody(byte[] body) {
117 this.body = new Body(body);