AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / UpdateNetworkInstanceTest.groovy
1 package org.openecomp.mso.bpmn.infrastructure.scripts\r
2 \r
3 import static org.mockito.Mockito.*\r
4 \r
5 import org.camunda.bpm.engine.ProcessEngineServices\r
6 import org.camunda.bpm.engine.RepositoryService\r
7 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity\r
8 import org.camunda.bpm.engine.repository.ProcessDefinition\r
9 import org.camunda.bpm.engine.delegate.DelegateExecution\r
10 import org.junit.Before\r
11 import org.junit.Ignore\r
12 import org.junit.Rule\r
13 import org.junit.Test\r
14 import org.junit.runner.RunWith\r
15 import org.mockito.MockitoAnnotations\r
16 import org.mockito.runners.MockitoJUnitRunner\r
17 import org.openecomp.mso.bpmn.common.scripts.MsoUtils\r
18 import org.openecomp.mso.bpmn.core.WorkflowException\r
19 \r
20 import com.github.tomakehurst.wiremock.junit.WireMockRule\r
21 import org.apache.commons.lang3.*\r
22 \r
23 \r
24 @RunWith(MockitoJUnitRunner.class)\r
25 class UpdateNetworkInstanceTest  {\r
26 \r
27         @Rule\r
28         public WireMockRule wireMockRule = new WireMockRule(8090);\r
29 \r
30                 String Prefix="UPDNI_"\r
31                 def utils = new MsoUtils()\r
32 \r
33                 String createDBRequestError =\r
34 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">\r
35                                                 <soapenv:Header/>\r
36                                                 <soapenv:Body>\r
37                                                         <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">\r
38                                                                 <requestId>88f65519-9a38-4c4b-8445-9eb4a5a5af56</requestId>\r
39                                                                 <lastModifiedBy>BPMN</lastModifiedBy>\r
40                                                                 <statusMessage>Received error from SDN-C: No availability zone available</statusMessage>\r
41                                                                 <responseBody></responseBody>\r
42                                                                 <requestStatus>FAILED</requestStatus>\r
43                                                                 <vnfOutputs>&lt;network-id&gt;&lt;/network-id&gt;&lt;network-name&gt;&lt;/network-names&gt;</vnfOutputs>\r
44                                                         </ns:updateInfraRequest>\r
45                                                 </soapenv:Body>\r
46                                            </soapenv:Envelope>"""\r
47 \r
48           String falloutHandlerRequest =\r
49                                            """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
50                                                                      xmlns:ns="http://org.openecomp/mso/request/types/v1"\r
51                                                                      xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">\r
52                                            <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
53                                               <request-id>b69c9054-da09-4a2c-adf5-51042b62bfac</request-id>\r
54                                               <action>UPDATE</action>\r
55                                               <source>VID</source>\r
56                                            </request-info>\r
57                                                 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
58                                                         <aetgt:ErrorMessage>Received error from SDN-C: No availability zone available.</aetgt:ErrorMessage>\r
59                                                         <aetgt:ErrorCode>5300</aetgt:ErrorCode>\r
60                                                 </aetgt:WorkflowException>\r
61                                         </aetgt:FalloutHandlerRequest>"""\r
62 \r
63            String completeMsoProcessRequest =\r
64                                            """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
65                             xmlns:ns="http://org.openecomp/mso/request/types/v1"\r
66                             xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
67    <request-info>\r
68       <request-id>88f65519-9a38-4c4b-8445-9eb4a5a5af56</request-id>\r
69       <action>UPDATE</action>\r
70       <source>VID</source>\r
71    </request-info>\r
72    <aetgt:status-message>Network has been updated successfully.</aetgt:status-message>\r
73    <aetgt:mso-bpel-name>BPMN Network action: UPDATE</aetgt:mso-bpel-name>\r
74 </aetgt:MsoCompletionRequest>"""\r
75 \r
76 \r
77 String jsonIncomingRequest =\r
78 """{ "requestDetails": {\r
79               "modelInfo": {\r
80                         "modelType": "networkTyp",\r
81                         "modelId": "modelId",\r
82                         "modelNameVersionId": "modelNameVersionId",\r
83                         "modelName": "CONTRAIL_EXTERNAL",\r
84                         "modelVersion": "1"\r
85                   },\r
86                   "cloudConfiguration": {\r
87                         "lcpCloudRegionId": "RDM2WAGPLCP",\r
88                         "tenantId": "7dd5365547234ee8937416c65507d266"\r
89                   },\r
90                   "requestInfo": {\r
91                         "instanceName": "MNS-25180-L-01-dmz_direct_net_1",\r
92                         "source": "VID",\r
93                         "callbackUrl": "",\r
94             "suppressRollback": true,\r
95                 "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"\r
96                   },\r
97                   "relatedInstanceList": [\r
98                         {\r
99                         "relatedInstance": {\r
100                                 "instanceId": "f70e927b-6087-4974-9ef8-c5e4d5847ca4",\r
101                                 "modelInfo": {\r
102                                         "modelType": "serviceT",\r
103                                         "modelId": "modelI",\r
104                                         "modelNameVersionId": "modelNameVersionI",\r
105                                         "modelName": "modleNam",\r
106                                         "modelVersion": "1"\r
107                                 }\r
108                         }\r
109                 }\r
110                   ],\r
111                   "requestParameters": {\r
112                         "userParams": [\r
113                {\r
114                                  "name": "someUserParam1",\r
115                                  "value": "someValue1"\r
116                            }\r
117             ]\r
118                   }\r
119   }}"""\r
120 \r
121             @Before\r
122                 public void init()\r
123                 {\r
124                         MockitoAnnotations.initMocks(this)\r
125 \r
126                 }\r
127 \r
128                 public void initializeVariables(DelegateExecution mockExecution) {\r
129 \r
130                         verify(mockExecution).setVariable(Prefix + "source", "")\r
131                         verify(mockExecution).setVariable(Prefix + "Success", false)\r
132 \r
133                         verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")\r
134                         verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")\r
135 \r
136                 }\r
137 \r
138                 @Test\r
139                 //@Ignore\r
140                 public void preProcessRequest() {\r
141 \r
142                         println "************ preProcessRequest() ************* "\r
143                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
144                         // Initialize prerequisite variables\r
145                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
146                         when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)\r
147 \r
148                         when(mockExecution.getVariable("URN_mso_adapters_db_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")\r
149                         when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")\r
150                         \r
151                         // preProcessRequest(DelegateExecution execution)\r
152                         UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()\r
153                         UpdateNetworkInstance.preProcessRequest(mockExecution)\r
154 \r
155                         verify(mockExecution).getVariable("isDebugLogEnabled")\r
156                         verify(mockExecution).setVariable("prefix", Prefix)\r
157 \r
158                         initializeVariables(mockExecution)\r
159                         //verify(mockExecution).setVariable(Prefix + "Success", false)\r
160 \r
161                 }\r
162 \r
163 \r
164                 @Test\r
165                 //@Ignore\r
166                 public void getNetworkModelInfo() {\r
167 \r
168                         println "************ getNetworkModelInfo() ************* "\r
169 \r
170                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
171                         // Initialize prerequisite variables\r
172                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
173 \r
174                         // preProcessRequest(DelegateExecution execution)\r
175                         UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()\r
176                         UpdateNetworkInstance.getNetworkModelInfo(mockExecution)\r
177 \r
178                         verify(mockExecution).getVariable("isDebugLogEnabled")\r
179                         verify(mockExecution).setVariable("prefix", Prefix)\r
180 \r
181                 }\r
182 \r
183                 @Test\r
184                 //@Ignore\r
185                 public void sendSyncResponse() {\r
186 \r
187                         println "************ sendSyncResponse ************* "\r
188 \r
189                         ExecutionEntity mockExecution = setupMock()\r
190                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
191                         when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)\r
192                         when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")\r
193                         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")\r
194 \r
195                         // preProcessRequest(DelegateExecution execution)\r
196                         UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()\r
197                         UpdateNetworkInstance.sendSyncResponse(mockExecution)\r
198 \r
199                         verify(mockExecution).setVariable("prefix", Prefix)\r
200                         verify(mockExecution).setVariable("UpdateNetworkInstanceResponseCode", "202")\r
201 \r
202                 }\r
203 \r
204                 @Test\r
205                 //@Ignore\r
206                 public void sendSyncError() {\r
207 \r
208                         println "************ sendSyncError ************* "\r
209 \r
210                         ExecutionEntity mockExecution = setupMock()\r
211                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
212                         when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)\r
213                         when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")\r
214                         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")\r
215 \r
216                         UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()\r
217                         UpdateNetworkInstance.sendSyncError(mockExecution)\r
218 \r
219                         verify(mockExecution).setVariable("prefix", Prefix)\r
220                         verify(mockExecution).setVariable("UpdateNetworkInstanceResponseCode", "500")\r
221 \r
222                 }\r
223 \r
224                 @Test\r
225                 //@Ignore\r
226                 public void prepareDBRequestError() {\r
227 \r
228                         println "************ prepareDBRequestError ************* "\r
229 \r
230                         WorkflowException sndcWorkflowException = new WorkflowException("UpdateNetworkInstance", 500, "Received error from SDN-C: No availability zone available")\r
231 \r
232                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
233                         // Initialize prerequisite variables\r
234                         when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)\r
235                         //when(mockExecution.getVariable("msoRequestId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")\r
236                         when(mockExecution.getVariable(Prefix + "requestId")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")\r
237                         when(mockExecution.getVariable("networkId")).thenReturn("")\r
238                         when(mockExecution.getVariable("networkName")).thenReturn("")\r
239                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
240 \r
241                         when(mockExecution.getVariable("URN_mso_adapters_db_auth")).thenReturn("757A94191D685FD2092AC1490730A4FC")\r
242                         when(mockExecution.getVariable("URN_mso_msoKey")).thenReturn("07a7159d3bf51a0e53be7a8f89699be7")\r
243                         \r
244                         // preProcessRequest(DelegateExecution execution)\r
245                         UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()\r
246                         UpdateNetworkInstance.prepareDBRequestError(mockExecution)\r
247 \r
248                         verify(mockExecution).setVariable("prefix", Prefix)\r
249                         verify(mockExecution).setVariable(Prefix + "createDBRequest", createDBRequestError)\r
250 \r
251                 }\r
252 \r
253 \r
254                 @Test\r
255                 //@Ignore\r
256                 public void prepareCompletion() {\r
257 \r
258                         println "************ postProcessResponse ************* "\r
259                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
260                         // Initialize prerequisite variables\r
261                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
262                         when(mockExecution.getVariable("mso-request-id")).thenReturn("88f65519-9a38-4c4b-8445-9eb4a5a5af56")\r
263                         when(mockExecution.getVariable(Prefix + "dbReturnCode")).thenReturn("200")\r
264 \r
265                         // postProcessResponse(DelegateExecution execution)\r
266                         UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()\r
267                         UpdateNetworkInstance.prepareCompletion(mockExecution)\r
268 \r
269                         // check the sequence of variable invocation\r
270                         //MockitoDebuggerImpl preDebugger = new MockitoDebuggerImpl()\r
271                         //preDebugger.printInvocations(mockExecution)\r
272 \r
273                         verify(mockExecution).setVariable("prefix", Prefix)\r
274                         verify(mockExecution).setVariable(Prefix + "Success", true)\r
275                         verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", completeMsoProcessRequest)\r
276 \r
277                 }\r
278 \r
279                 @Test\r
280                 //@Ignore\r
281                 public void buildErrorResponse() {\r
282 \r
283                         println "************ buildErrorResponse ************* "\r
284 \r
285 \r
286                         WorkflowException sndcWorkflowException = new WorkflowException("UpdateNetworkInstance", 5300, "Received error from SDN-C: No availability zone available.")\r
287 \r
288                         ExecutionEntity mockExecution = setupMock()\r
289                         // Initialize prerequisite variables\r
290                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
291                         when(mockExecution.getVariable("mso-request-id")).thenReturn("b69c9054-da09-4a2c-adf5-51042b62bfac")\r
292                         //when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)\r
293                         when(mockExecution.getVariable("WorkflowException")).thenReturn(sndcWorkflowException)\r
294 \r
295                         // buildErrorResponse(DelegateExecution execution)\r
296                         UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()\r
297                         UpdateNetworkInstance.buildErrorResponse(mockExecution)\r
298 \r
299                         verify(mockExecution, atLeast(1)).setVariable("prefix", Prefix)\r
300                         verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", falloutHandlerRequest)\r
301 \r
302                         //MockitoDebuggerImpl debugger = new MockitoDebuggerImpl()\r
303                         //debugger.printInvocations(mockExecution)\r
304 \r
305                 }\r
306 \r
307                 @Test\r
308                 //@Ignore\r
309                 public void postProcessResponse() {\r
310 \r
311                         println "************ postProcessResponse() ************* "\r
312                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
313                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
314                         when(mockExecution.getVariable("CMSO_ResponseCode")).thenReturn("200")\r
315 \r
316                         // postProcessResponse(DelegateExecution execution)\r
317                         UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()\r
318                         UpdateNetworkInstance.postProcessResponse(mockExecution)\r
319 \r
320                         //verify(mockExecution).getVariable("isDebugLogEnabled")\r
321                         //verify(mockExecution).setVariable("prefix", Prefix)\r
322 \r
323                         verify(mockExecution).setVariable(Prefix + "Success", true)\r
324 \r
325                 }\r
326 \r
327                 @Test\r
328                 //@Ignore\r
329                 public void processRollbackData() {\r
330 \r
331                         println "************ callDBCatalog() ************* "\r
332                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
333                         // Initialize prerequisite variables\r
334                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
335 \r
336                         // preProcessRequest(DelegateExecution execution)\r
337                         UpdateNetworkInstance UpdateNetworkInstance = new UpdateNetworkInstance()\r
338                         UpdateNetworkInstance.processRollbackData(mockExecution)\r
339 \r
340                         verify(mockExecution).getVariable("isDebugLogEnabled")\r
341                         verify(mockExecution).setVariable("prefix", Prefix)\r
342 \r
343                 }\r
344 \r
345                 private ExecutionEntity setupMock() {\r
346 \r
347                         ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)\r
348                         when(mockProcessDefinition.getKey()).thenReturn("UpdateNetworkInstance")\r
349                         RepositoryService mockRepositoryService = mock(RepositoryService.class)\r
350                         when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)\r
351                         when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("UpdateNetworkInstance")\r
352                         when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")\r
353                         ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)\r
354                         when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)\r
355 \r
356                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
357                         // Initialize prerequisite variables\r
358 \r
359                         when(mockExecution.getId()).thenReturn("100")\r
360                         when(mockExecution.getProcessDefinitionId()).thenReturn("UpdateNetworkInstance")\r
361                         when(mockExecution.getProcessInstanceId()).thenReturn("UpdateNetworkInstance")\r
362                         when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)\r
363                         when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)\r
364 \r
365                         return mockExecution\r
366                 }\r
367 \r
368 }