Containerization feature of SO
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / bpmn / mock / StubResponseVNFAdapter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.mock;
22
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;
31
32 /**
33  * Please describe the StubResponseVNF.java class
34  */
35 public class StubResponseVNFAdapter {
36
37         public static void mockVNFAdapter() {
38                 stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync"))
39                                 .willReturn(aResponse()
40                                                 .withStatus(200)));
41         }
42
43         public static void mockVNFAdapter(String responseFile) {
44                 stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync"))
45                                   .willReturn(aResponse()
46                                   .withStatus(200)
47                                   .withHeader("Content-Type", "text/xml")
48                                   .withBodyFile(responseFile)));
49         }
50
51         public static void mockVNFAdapter_500() {
52                 stubFor(post(urlEqualTo("/vnfs/VnfAdapterAsync"))
53                                 .willReturn(aResponse()
54                                                 .withStatus(500)));
55         }
56
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()
62                                                 .withStatus(200)
63                                                 .withHeader("Content-Type", "application/soap+xml")
64                                                 .withTransformers(transformer)
65                                                 .withBodyFile(responseFile)));
66         }
67
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()
74                                                 .withStatus(200)
75                                                 .withHeader("Content-Type", "application/soap+xml")
76                                                 .withTransformers(transformer)
77                                                 .withBodyFile(responseFile)));
78         }
79         
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")));
89         }
90         
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")));
100         }
101         
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")));
111         }
112         
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")));
122         }
123         
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")));
133         }
134         
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")));
144         }
145         
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")));
155         }
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")));
165         }
166         
167         public static void mockVNFAdapterRest(String vnfId) {
168                 stubFor(post(urlEqualTo("/services/rest/v1/vnfs" + vnfId + "/vf-modules"))
169                                 .willReturn(aResponse()
170                                                 .withStatus(200)));
171                 stubFor(post(urlEqualTo("/services/rest/v1/vnfs/" + vnfId + "/vf-modules"))
172                                 .willReturn(aResponse()
173                                                 .withStatus(200)));
174         }
175
176         public static void mockVNFAdapterRest_500(String vnfId) {
177                 stubFor(post(urlEqualTo("/services/rest/v1/vnfs" + vnfId + "/vf-modules"))
178                                 .willReturn(aResponse()
179                                                 .withStatus(500)));
180                 stubFor(post(urlEqualTo("/services/rest/v1/vnfs/" + vnfId + "/vf-modules"))
181                                 .willReturn(aResponse()
182                                                 .withStatus(500)));
183         }
184         
185         public static void mockVfModuleDelete(String volumeGroupId) {
186                 stubFor(delete(urlMatching("/vnfs/v1/volume-groups/"+ volumeGroupId))
187                                 .willReturn(aResponse()
188                                 .withStatus(202)
189                                 .withHeader("Content-Type", "application/xml")));
190                 stubFor(delete(urlMatching("/vnfs/rest/v1/volume-groups/"+ volumeGroupId))
191                                 .willReturn(aResponse()
192                                 .withStatus(202)
193                                 .withHeader("Content-Type", "application/xml")));
194         }
195         
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")));
205         }
206 }