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=========================================================
21 package org.onap.so.bpmn.mock;
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.containing;
25 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
26 import static com.github.tomakehurst.wiremock.client.WireMock.post;
27 import static com.github.tomakehurst.wiremock.client.WireMock.put;
28 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
29 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
30 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
33 * Please describe the StubResponseVNF.java class
35 public class StubResponseVNFAdapter {
37 public static void mockVNFAdapter() {
38 stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync"))
39 .willReturn(aResponse()
43 public static void mockVNFAdapter(String responseFile) {
44 stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync"))
45 .willReturn(aResponse()
47 .withHeader("Content-Type", "text/xml")
48 .withBodyFile(responseFile)));
51 public static void mockVNFAdapter_500() {
52 stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync"))
53 .willReturn(aResponse()
57 public static void mockVNFAdapterTransformer(String transformer, String responseFile) {
58 MockResource mockResource = new MockResource();
59 mockResource.updateProperties("vnf_delay", "300");
60 stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync"))
61 .willReturn(aResponse()
63 .withHeader("Content-Type", "application/soap+xml")
64 .withTransformers(transformer)
65 .withBodyFile(responseFile)));
68 public static void mockVNFAdapterTransformer(String transformer, String responseFile, String requestContaining) {
69 MockResource mockResource = new MockResource();
70 mockResource.updateProperties("vnf_delay", "300");
71 stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync"))
72 .withRequestBody(containing(requestContaining))
73 .willReturn(aResponse()
75 .withHeader("Content-Type", "application/soap+xml")
76 .withTransformers(transformer)
77 .withBodyFile(responseFile)));
80 public static void mockVNFPost(String vfModuleId, int statusCode, String vnfId) {
81 stubFor(post(urlEqualTo("/services/rest/v1/vnfs" + vnfId + "/vf-modules" + vfModuleId))
82 .willReturn(aResponse()
83 .withStatus(statusCode)
84 .withHeader("Content-Type", "application/xml")));
85 stubFor(post(urlEqualTo("/services/rest/v1/vnfs/" + vnfId + "/vf-modules" + vfModuleId))
86 .willReturn(aResponse()
87 .withStatus(statusCode)
88 .withHeader("Content-Type", "application/xml")));
91 public static void mockVNFPut(String vfModuleId, int statusCode) {
92 stubFor(put(urlEqualTo("/services/rest/v1/vnfsvnfId/vf-modules" + vfModuleId))
93 .willReturn(aResponse()
94 .withStatus(statusCode)
95 .withHeader("Content-Type", "application/xml")));
96 stubFor(put(urlEqualTo("/services/rest/v1/vnfs/vnfId/vf-modules" + vfModuleId))
97 .willReturn(aResponse()
98 .withStatus(statusCode)
99 .withHeader("Content-Type", "application/xml")));
102 public static void mockVNFPut(String vnfId, String vfModuleId, int statusCode) {
103 stubFor(put(urlEqualTo("/services/rest/v1/vnfs" + vnfId + "/vf-modules" + vfModuleId))
104 .willReturn(aResponse()
105 .withStatus(statusCode)
106 .withHeader("Content-Type", "application/xml")));
107 stubFor(put(urlEqualTo("/services/rest/v1/vnfs/" + vnfId + "/vf-modules" + vfModuleId))
108 .willReturn(aResponse()
109 .withStatus(statusCode)
110 .withHeader("Content-Type", "application/xml")));
113 public static void mockVNFDelete(String vnfId, String vfModuleId, int statusCode) {
114 stubFor(delete(urlEqualTo("/services/rest/v1/vnfs" + vnfId + "/vf-modules" + vfModuleId))
115 .willReturn(aResponse()
116 .withStatus(statusCode)
117 .withHeader("Content-Type", "application/xml")));
118 stubFor(delete(urlEqualTo("/services/rest/v1/vnfs/" + vnfId + "/vf-modules" + vfModuleId))
119 .willReturn(aResponse()
120 .withStatus(statusCode)
121 .withHeader("Content-Type", "application/xml")));
124 public static void mockVNFRollbackDelete(String vfModuleId, int statusCode) {
125 stubFor(delete(urlEqualTo("/services/rest/v1/vnfsvnfId/vf-modules" + vfModuleId + "/rollback"))
126 .willReturn(aResponse()
127 .withStatus(statusCode)
128 .withHeader("Content-Type", "application/xml")));
129 stubFor(delete(urlEqualTo("/services/rest/v1/vnfs/vnfId/vf-modules" + vfModuleId + "/rollback"))
130 .willReturn(aResponse()
131 .withStatus(statusCode)
132 .withHeader("Content-Type", "application/xml")));
135 public static void mockPutVNFVolumeGroup(String volumeGroupId, int statusCode) {
136 stubFor(put(urlEqualTo("/vnfs/v1/volume-groups/" + volumeGroupId))
137 .willReturn(aResponse()
138 .withStatus(statusCode)
139 .withHeader("Content-Type", "application/xml")));
140 stubFor(put(urlEqualTo("/vnfs/rest/v1/volume-groups/" + volumeGroupId))
141 .willReturn(aResponse()
142 .withStatus(statusCode)
143 .withHeader("Content-Type", "application/xml")));
146 public static void mockPutVNFVolumeGroupRollback(String volumeGroupId, int statusCode) {
147 stubFor(delete(urlMatching("/vnfs/v1/volume-groups/" + volumeGroupId + "/rollback"))
148 .willReturn(aResponse()
149 .withStatus(statusCode)
150 .withHeader("Content-Type", "application/xml")));
151 stubFor(delete(urlMatching("/vnfs/rest/v1/volume-groups/" + volumeGroupId + "/rollback"))
152 .willReturn(aResponse()
153 .withStatus(statusCode)
154 .withHeader("Content-Type", "application/xml")));
156 public static void mockPostVNFVolumeGroup(int statusCode) {
157 stubFor(post(urlEqualTo("/vnfs/v1/volume-groups"))
158 .willReturn(aResponse()
159 .withStatus(statusCode)
160 .withHeader("Content-Type", "application/xml")));
161 stubFor(post(urlEqualTo("/vnfs/rest/v1/volume-groups"))
162 .willReturn(aResponse()
163 .withStatus(statusCode)
164 .withHeader("Content-Type", "application/xml")));
167 public static void mockVNFAdapterRest(String vnfId) {
168 stubFor(post(urlEqualTo("/services/rest/v1/vnfs" + vnfId + "/vf-modules"))
169 .willReturn(aResponse()
171 stubFor(post(urlEqualTo("/services/rest/v1/vnfs/" + vnfId + "/vf-modules"))
172 .willReturn(aResponse()
176 public static void mockVNFAdapterRest_500(String vnfId) {
177 stubFor(post(urlEqualTo("/services/rest/v1/vnfs" + vnfId + "/vf-modules"))
178 .willReturn(aResponse()
180 stubFor(post(urlEqualTo("/services/rest/v1/vnfs/" + vnfId + "/vf-modules"))
181 .willReturn(aResponse()
185 public static void mockVfModuleDelete(String volumeGroupId) {
186 stubFor(delete(urlMatching("/vnfs/v1/volume-groups/"+ volumeGroupId))
187 .willReturn(aResponse()
189 .withHeader("Content-Type", "application/xml")));
190 stubFor(delete(urlMatching("/vnfs/rest/v1/volume-groups/"+ volumeGroupId))
191 .willReturn(aResponse()
193 .withHeader("Content-Type", "application/xml")));
196 public static void mockVfModuleDelete(String volumeGroupId, int statusCode) {
197 stubFor(delete(urlMatching("/vnfs/v1/volume-groups/78987"))
198 .willReturn(aResponse()
199 .withStatus(statusCode)
200 .withHeader("Content-Type", "application/xml")));
201 stubFor(delete(urlMatching("/vnfs/rest/v1/volume-groups/78987"))
202 .willReturn(aResponse()
203 .withStatus(statusCode)
204 .withHeader("Content-Type", "application/xml")));