Merge "updated ARIA version"
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / DoCreateVfModuleVolumeV1Test.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * OPENECOMP - MSO 
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.openecomp.mso.bpmn.infrastructure;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
25 import static com.github.tomakehurst.wiremock.client.WireMock.get;
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 import java.io.IOException;
33 import java.util.HashMap;
34 import java.util.Map;
35 import java.util.UUID;
36
37 import org.camunda.bpm.engine.test.Deployment;
38 import org.junit.Test;
39 import org.openecomp.mso.bpmn.common.WorkflowTest;
40 import org.openecomp.mso.bpmn.common.WorkflowTest.CallbackSet;
41 import org.openecomp.mso.bpmn.mock.FileUtil;
42
43 public class DoCreateVfModuleVolumeV1Test extends WorkflowTest {
44         
45         public static final String _prefix = "CVFMODVOL2_";
46         
47         private final CallbackSet callbacks = new CallbackSet();
48
49         public DoCreateVfModuleVolumeV1Test() throws IOException {
50                 callbacks.put("volumeGroupCreate", FileUtil.readResourceFile(
51                                 "__files/DoCreateVfModuleVolumeV1/CreateVfModuleVolumeCallbackResponse.xml"));
52                 callbacks.put("volumeGroupRollback", FileUtil.readResourceFile(
53                                 "__files/DoCreateVfModuleVolumeV1/RollbackVfModuleVolumeCallbackResponse.xml"));
54         }
55
56         /**
57          * Happy Path
58          * @throws Exception
59          */
60         @Test
61         @Deployment(resources = {"subprocess/DoCreateVfModuleVolumeV1.bpmn",
62             "subprocess/FalloutHandler.bpmn",
63             "subprocess/CompleteMsoProcess.bpmn",
64             "subprocess/VnfAdapterRestV1.bpmn",
65             "subprocess/VnfAdapterRestV1.bpmn"})
66         public void TestHappyPath() throws Exception {
67
68                 logStart();
69                 
70                 DoCreateVfModuleVolume_Success();
71                 
72                 String businessKey = UUID.randomUUID().toString();
73                 String createVfModuleVolRequest = FileUtil.readResourceFile("__files/DoCreateVfModuleVolumeV1/CreateVfModuleVolumeRequest.xml");
74                 
75                 Map<String, Object> testVariables = new HashMap<String, Object>();
76                 testVariables.put("DCVFMODVOLV1_volumeGroupId", "TEST-VOLUME-VOLUME-GROUP-ID-0123");
77                 testVariables.put("vnf-id", "TEST-VNF-ID-0123");
78                 testVariables.put("volume-group-id", "TEST-VOLUME-GROUP-ID-0123");
79                 testVariables.put("test-volume-group-name", "TEST-MSOTESTVOL101a-vSAMP12_base_vol_module-0");
80                 //testVariables.put("test-volume-group-id", "TEST-VOLUME-GROUP-ID-0123");
81                 testVariables.put("DoCreateVfModuleVolumeV1Request", createVfModuleVolRequest);
82                 invokeAsyncProcess("DoCreateVfModuleVolumeV1", "v1", businessKey, createVfModuleVolRequest, testVariables);
83                 
84                 injectVNFRestCallbacks(callbacks, "volumeGroupCreate");
85                 
86                 waitForProcessEnd(businessKey, 100000);
87                 checkVariable(businessKey, "DCVFMODVOLV1_SuccessIndicator", true);
88                 
89                 logEnd();
90         }
91         
92         @Test
93         @Deployment(resources = {"subprocess/DoCreateVfModuleVolumeV1.bpmn",
94             "subprocess/FalloutHandler.bpmn",
95             "subprocess/CompleteMsoProcess.bpmn",
96             "subprocess/VnfAdapterRestV1.bpmn",
97             "subprocess/VnfAdapterRestV1.bpmn"})
98         public void TestVolumeGroupExistError() throws Exception {
99
100                 logStart();
101                 
102                 DoCreateVfModuleVolume_VolumeGroupExistsFail();
103                 
104                 String businessKey = UUID.randomUUID().toString();
105                 String createVfModuleVolRequest = FileUtil.readResourceFile("__files/DoCreateVfModuleVolumeV1/CreateVfModuleVolumeRequest.xml");
106                 
107                 Map<String, Object> testVariables = new HashMap<String, Object>();
108                 testVariables.put("DCVFMODVOLV1_volumeGroupId", "TEST-VOLUME-VOLUME-GROUP-ID-0123");
109                 testVariables.put("vnf-id", "TEST-VNF-ID-0123");
110                 testVariables.put("volume-group-id", "TEST-VOLUME-GROUP-ID-0123");
111                 testVariables.put("test-volume-group-name", "TEST-MSOTESTVOL101a-vSAMP12_base_vol_module-0");
112                 testVariables.put("DoCreateVfModuleVolumeV1Request", createVfModuleVolRequest);
113                 invokeAsyncProcess("DoCreateVfModuleVolumeV1", "v1", businessKey, createVfModuleVolRequest, testVariables);
114                 
115                 //injectVNFRestCallbacks(callbacks, "volumeGroupCreate");
116                 
117                 waitForProcessEnd(businessKey, 100000);
118                 checkVariable(businessKey, "DCVFMODVOLV1_SuccessIndicator", false);
119                 
120                 logEnd();
121         }
122         
123         /**
124          * Will trigger AAI create rollback
125          * @throws Exception
126          */
127         @Test
128         @Deployment(resources = {"subprocess/DoCreateVfModuleVolumeV1.bpmn",
129             "subprocess/FalloutHandler.bpmn",
130             "subprocess/CompleteMsoProcess.bpmn",
131             "subprocess/VnfAdapterRestV1.bpmn",
132             "subprocess/VnfAdapterRestV1.bpmn"})
133         public void TestVnfVolumeGroupCreateError() throws Exception {
134
135                 logStart();
136                 
137                 DoCreateVfModuleVolume_VnfCreateVolumeGroupFail();
138                 
139                 String businessKey = UUID.randomUUID().toString();
140                 String createVfModuleVolRequest = FileUtil.readResourceFile("__files/DoCreateVfModuleVolumeV1/CreateVfModuleVolumeRequest.xml");
141                 
142                 Map<String, Object> testVariables = new HashMap<String, Object>();
143                 testVariables.put("DCVFMODVOLV1_volumeGroupId", "TEST-VOLUME-VOLUME-GROUP-ID-0123");
144                 testVariables.put("vnf-id", "TEST-VNF-ID-0123");
145                 testVariables.put("volume-group-id", "TEST-VOLUME-GROUP-ID-0123");
146                 testVariables.put("test-volume-group-name", "TEST-MSOTESTVOL101a-vSAMP12_base_vol_module-0");
147                 testVariables.put("test-volume-group-id", "TEST-VOLUME-GROUP-ID-0123");
148                 testVariables.put("DoCreateVfModuleVolumeV1Request", createVfModuleVolRequest);
149                 invokeAsyncProcess("DoCreateVfModuleVolumeV1", "v1", businessKey, createVfModuleVolRequest, testVariables);
150                 
151                 //injectVNFRestCallbacks(callbacks, "volumeGroupCreate");
152                 
153                 waitForProcessEnd(businessKey, 100000);
154                 checkVariable(businessKey, "DCVFMODVOLV1_SuccessIndicator", false);
155                 
156                 logEnd();
157         }
158         
159         /**
160          * Will trigger AAI create rollback
161          * @throws Exception
162          */
163         @Test
164         @Deployment(resources = {"subprocess/DoCreateVfModuleVolumeV1.bpmn",
165             "subprocess/FalloutHandler.bpmn",
166             "subprocess/CompleteMsoProcess.bpmn",
167             "subprocess/VnfAdapterRestV1.bpmn",
168             "subprocess/VnfAdapterRestV1.bpmn"})
169         public void TestUpdateAaiVolumeGroupError() throws Exception {
170
171                 logStart();
172                 
173                 DoCreateVfModuleVolume_AaiVolumeGroupUpdateFail();
174                 
175                 String businessKey = UUID.randomUUID().toString();
176                 String createVfModuleVolRequest = FileUtil.readResourceFile("__files/DoCreateVfModuleVolumeV1/CreateVfModuleVolumeRequest.xml");
177                 
178                 Map<String, Object> testVariables = new HashMap<String, Object>();
179                 testVariables.put("DCVFMODVOLV1_volumeGroupId", "TEST-VOLUME-VOLUME-GROUP-ID-0123");
180                 testVariables.put("vnf-id", "TEST-VNF-ID-0123");
181                 testVariables.put("volume-group-id", "TEST-VOLUME-GROUP-ID-0123");
182                 testVariables.put("test-volume-group-name", "TEST-MSOTESTVOL101a-vSAMP12_base_vol_module-0");
183                 testVariables.put("test-volume-group-id", "TEST-VOLUME-GROUP-ID-0123");
184                 testVariables.put("DoCreateVfModuleVolumeV1Request", createVfModuleVolRequest);
185                 invokeAsyncProcess("DoCreateVfModuleVolumeV1", "v1", businessKey, createVfModuleVolRequest, testVariables);
186                 
187                 injectVNFRestCallbacks(callbacks, "volumeGroupCreate,volumeGroupRollback");
188                 
189                 waitForProcessEnd(businessKey, 100000);
190                 checkVariable(businessKey, "DCVFMODVOLV1_SuccessIndicator", false);
191                 
192                 logEnd();
193         }               
194
195         /**
196          * Will trigger not trigger rollback
197          * @throws Exception
198          */
199         @Test
200         @Deployment(resources = {"subprocess/DoCreateVfModuleVolumeV1.bpmn",
201             "subprocess/FalloutHandler.bpmn",
202             "subprocess/CompleteMsoProcess.bpmn",
203             "subprocess/VnfAdapterRestV1.bpmn",
204             "subprocess/VnfAdapterRestV1.bpmn"})
205         public void TestUpdateAaiVolumeGroupErrorNoRollback() throws Exception {
206
207                 logStart();
208                 
209                 DoCreateVfModuleVolume_AaiVolumeGroupUpdateFail();
210                 
211                 String businessKey = UUID.randomUUID().toString();
212                 String createVfModuleVolRequest = FileUtil.readResourceFile("__files/DoCreateVfModuleVolumeV1/CreateVfModuleVolumeNoRollbackRequest.xml");
213                 
214                 Map<String, Object> testVariables = new HashMap<String, Object>();
215                 testVariables.put("DCVFMODVOLV1_volumeGroupId", "TEST-VOLUME-VOLUME-GROUP-ID-0123");
216                 testVariables.put("vnf-id", "TEST-VNF-ID-0123");
217                 testVariables.put("volume-group-id", "TEST-VOLUME-GROUP-ID-0123");
218                 testVariables.put("test-volume-group-name", "TEST-MSOTESTVOL101a-vSAMP12_base_vol_module-0");
219                 testVariables.put("test-volume-group-id", "TEST-VOLUME-GROUP-ID-0123");
220                 testVariables.put("DoCreateVfModuleVolumeV1Request", createVfModuleVolRequest);
221                 invokeAsyncProcess("DoCreateVfModuleVolumeV1", "v1", businessKey, createVfModuleVolRequest, testVariables);
222                 
223                 injectVNFRestCallbacks(callbacks, "volumeGroupCreate");
224                 
225                 waitForProcessEnd(businessKey, 100000);
226                 checkVariable(businessKey, "DCVFMODVOLV1_SuccessIndicator", false);
227                 
228                 logEnd();
229         }
230
231         public static void DoCreateVfModuleVolume_Success() {
232                 // Notes:
233                 // 1. initial aai volume group by name - /aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups/volume-group?volume-group-name=TEST-MSOTESTVOL101a-vSAMP12_base_vol_module-0
234                 // 2. Create volume group - /aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups/volume-group
235                 // 3. Requery Volume Group - /aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups/volume-group?volume-group-name=MSOTESTVOL101a-vSAMP12_base_vol_module-0
236                 // 4. Update volume group (id from requery response - /aai/v8/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups/volume-group/8424bb3c-c3e7-4553-9662-469649ed9379
237
238                 //generic vnf
239                 stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/TEST-VNF-ID-0123"))
240                                   .willReturn(aResponse()
241                                   .withStatus(200)
242                                   .withHeader("Content-Type", "text/xml")
243                                   .withBodyFile("DoCreateVfModuleVolumeV1/GenericVnf.xml")));
244                 //create volume group
245                 stubFor(put(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups/volume-group/TEST-VOLUME-GROUP-ID-0123"))
246                                   .willReturn(aResponse()
247                                   .withStatus(201)
248                                   .withHeader("Content-Type", "text/xml")
249                                   .withBodyFile("DoCreateVfModuleVolumeV1/createVfModuleVolume_createVolumeName_AAIResponse_Success.xml")));
250                 //requery volume group
251                 stubFor(get(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups[?]volume-group-name=MSOTESTVOL101a-vSAMP12_base_vol_module-0"))
252                                   .willReturn(aResponse()
253                                   .withStatus(200)
254                                   .withHeader("Content-Type", "text/xml")
255                                   .withBodyFile("DoCreateVfModuleVolumeV1/createVfModuleVolume_queryVolumeName_AAIResponse_Success.xml")));
256                 //update volume group
257                 stubFor(put(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups/volume-group/8424bb3c-c3e7-4553-9662-469649ed9379"))
258                                   .willReturn(aResponse()
259                                   .withStatus(200)
260                                   .withHeader("Content-Type", "text/xml")
261                                   .withBodyFile("DoCreateVfModuleVolumeV1/createVfModuleVolume_updateVolumeName_AAIResponse_Success.xml")));
262                 // VNF rest Adapter
263                 stubFor(post(urlEqualTo("/vnfs/v1/volume-groups"))
264                                 .willReturn(aResponse()
265                                         .withStatus(202)
266                                         .withHeader("Content-Type", "application/xml")));
267         }
268
269         public static void DoCreateVfModuleVolume_VolumeGroupExistsFail() {
270                 //generic vnf
271                 stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/TEST-VNF-ID-0123"))
272                                   .willReturn(aResponse()
273                                   .withStatus(200)
274                                   .withHeader("Content-Type", "text/xml")
275                                   .withBodyFile("DoCreateVfModuleVolumeV1/GenericVnf.xml")));
276                 //initial volume group query
277                 stubFor(get(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups/volume-group[?]volume-group-name=TEST-MSOTESTVOL101a-vSAMP12_base_vol_module-0"))
278                                   .willReturn(aResponse()
279                                   .withStatus(200)
280                                   .withHeader("Content-Type", "text/xml")
281                                   .withBodyFile("DoCreateVfModuleVolumeV1/createVfModuleVolume_queryVolumeName_AAIResponse_Success.xml")));
282         }
283
284         public static void DoCreateVfModuleVolume_VnfCreateVolumeGroupFail() {
285                 //generic vnf
286                 stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/TEST-VNF-ID-0123"))
287                                   .willReturn(aResponse()
288                                   .withStatus(200)
289                                   .withHeader("Content-Type", "text/xml")
290                                   .withBodyFile("DoCreateVfModuleVolumeV1/GenericVnf.xml")));
291                 //create volume group
292                 stubFor(put(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups/volume-group/TEST-VOLUME-GROUP-ID-0123"))
293                                   .willReturn(aResponse()
294                                   .withStatus(201)
295                                   .withHeader("Content-Type", "text/xml")
296                                   .withBodyFile("DoCreateVfModuleVolumeV1/createVfModuleVolume_createVolumeName_AAIResponse_Success.xml")));
297                 //Query AAI volume group by name -- needed before delete
298                 stubFor(get(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups[?]volume-group-name=MSOTESTVOL101a-vSAMP12_base_vol_module-0"))
299                                   .willReturn(aResponse()
300                                   .withStatus(200)
301                                   .withHeader("Content-Type", "text/xml")
302                                   .withBodyFile("DoCreateVfModuleVolumeV1/createVfModuleVolume_queryVolumeName_AAIResponse_Success.xml")));
303                 //delete volume group in aai
304                 stubFor(delete(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups/volume-group/8424bb3c-c3e7-4553-9662-469649ed9379[?]resource-version=1460134360"))
305                                   .willReturn(aResponse()
306                                   .withStatus(200)
307                                   .withHeader("Content-Type", "text/xml")
308                                   .withBodyFile("DoCreateVfModuleVolumeV1/createVfModuleVolume_deleteVolumeName_AAIResponse_Success.xml")));
309                 stubFor(post(urlEqualTo("/vnfs/v1/volume-groups"))
310                                 .willReturn(aResponse()
311                                         .withStatus(404)
312                                         .withHeader("Content-Type", "application/xml")));
313         }
314
315         public static void DoCreateVfModuleVolume_AaiVolumeGroupUpdateFail() {
316                 //generic vnf
317                 stubFor(get(urlMatching("/aai/v[0-9]+/network/generic-vnfs/generic-vnf/TEST-VNF-ID-0123"))
318                                   .willReturn(aResponse()
319                                   .withStatus(200)
320                                   .withHeader("Content-Type", "text/xml")
321                                   .withBodyFile("DoCreateVfModuleVolumeV1/GenericVnf.xml")));
322                 //create volume group
323                 stubFor(put(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups/volume-group/TEST-VOLUME-GROUP-ID-0123"))
324                                   .willReturn(aResponse()
325                                   .withStatus(201)
326                                   .withHeader("Content-Type", "text/xml")
327                                   .withBodyFile("DoCreateVfModuleVolumeV1/createVfModuleVolume_createVolumeName_AAIResponse_Success.xml")));
328                 //requery volume group
329                 stubFor(get(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/volume-groups[?]volume-group-name=MSOTESTVOL101a-vSAMP12_base_vol_module-0"))
330                                   .willReturn(aResponse()
331                                   .withStatus(200)
332                                   .withHeader("Content-Type", "text/xml")
333                                   .withBodyFile("DoCreateVfModuleVolumeV1/createVfModuleVolume_queryVolumeName_AAIResponse_Success.xml")));
334                 //delete volume group in aai
335                 stubFor(delete(urlMatching("/aai/v[0-9]+/cloud-infrastructure/volume-groups/volume-group/8424bb3c-c3e7-4553-9662-469649ed9379[?]resource-version=1460134360"))
336                                   .willReturn(aResponse()
337                                   .withStatus(200)
338                                   .withHeader("Content-Type", "text/xml")
339                                   .withBodyFile("DoCreateVfModuleVolumeV1/createVfModuleVolume_deleteVolumeName_AAIResponse_Success.xml")));
340                 // VNF rest Adapter
341                 stubFor(post(urlEqualTo("/vnfs/v1/volume-groups"))
342                                 .willReturn(aResponse()
343                                         .withStatus(202)
344                                         .withHeader("Content-Type", "application/xml")));
345                 // VNF Rest Adapter rollback - vnfs/v1/volume-groups/STUB-TEST-8424bb3c-c3e7-4553-9662-469649ed9379/rollback
346                 stubFor(delete(urlEqualTo("/vnfs/v1/volume-groups/TEST-VOLUME-GROUP-ID-0123/rollback"))
347                                 .willReturn(aResponse()
348                                 .withStatus(202)
349                                 .withHeader("Content-Type", "application/xml")));
350         }
351 }