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