691930240941b686109446f36f32bd46d546f2b6
[so.git] /
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.runtime.Execution\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 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
15 import org.openecomp.mso.bpmn.common.scripts.VidUtils\r
16 \r
17 import static org.junit.Assert.*;\r
18 import static org.mockito.Mockito.*\r
19 \r
20 import com.github.tomakehurst.wiremock.junit.WireMockRule\r
21 \r
22 class CreateGenericAlaCarteServiceInstanceTest  {\r
23         \r
24         @Rule\r
25         public WireMockRule wireMockRule = new WireMockRule(8090);\r
26         \r
27                 String Prefix="CRENI_"\r
28                 def utils = new MsoUtils()\r
29                 JsonUtils jsonUtil = new JsonUtils()\r
30                 VidUtils vidUtils = new VidUtils()\r
31                 \r
32         String createDBRequestError =\r
33 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">\r
34                                                 <soapenv:Header/>\r
35                                                 <soapenv:Body>\r
36                                                         <ns:updateInfraRequest xmlns:ns="http://org.openecomp.mso/requestsdb">\r
37                                                                 <requestId>88f65519-9a38-4c4b-8445-9eb4a5a5af56</requestId>\r
38                                                                 <lastModifiedBy>BPMN</lastModifiedBy>\r
39                                                                 <statusMessage>Received error from SDN-C: No availability zone available</statusMessage>\r
40                                                                 <responseBody></responseBody>\r
41                                                                 <requestStatus>FAILED</requestStatus>\r
42                                                                 <vnfOutputs>&lt;network-id&gt;&lt;/network-id&gt;&lt;network-name&gt;&lt;/network-names&gt;</vnfOutputs>\r
43                                                         </ns:updateInfraRequest>\r
44                                                 </soapenv:Body>\r
45                                            </soapenv:Envelope>"""\r
46 \r
47           String falloutHandlerRequest =\r
48                                            """<aetgt:FalloutHandlerRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
49                                                                      xmlns:ns="http://org.openecomp/mso/request/types/v1"\r
50                                                                      xmlns:wfsch="http://org.openecomp/mso/workflow/schema/v1">\r
51                                            <request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
52                                               <request-id>b69c9054-da09-4a2c-adf5-51042b62bfac</request-id>\r
53                                               <action>CREATE</action>\r
54                                               <source>VID</source>\r
55                                            </request-info>\r
56                                                 <aetgt:WorkflowException xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1">\r
57                                                         <aetgt:ErrorMessage>Received error from SDN-C: No availability zone available.</aetgt:ErrorMessage>\r
58                                                         <aetgt:ErrorCode>5300</aetgt:ErrorCode>\r
59                                                 </aetgt:WorkflowException>\r
60                                         </aetgt:FalloutHandlerRequest>"""\r
61                                         \r
62                 String completeMsoProcessRequest =\r
63                                            """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"\r
64                             xmlns:ns="http://org.openecomp/mso/request/types/v1"\r
65                             xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
66    <request-info>\r
67       <request-id>88f65519-9a38-4c4b-8445-9eb4a5a5af56</request-id>\r
68       <action>CREATE</action>\r
69       <source>VID</source>\r
70    </request-info>\r
71    <aetgt:status-message>Network has been created successfully.</aetgt:status-message>\r
72    <aetgt:mso-bpel-name>BPMN Network action: CREATE</aetgt:mso-bpel-name>\r
73 </aetgt:MsoCompletionRequest>"""\r
74 \r
75                 String jsonIncomingRequest =\r
76         """{\r
77   "variables": {\r
78     "bpmnRequest": {\r
79       "value": "{\"requestDetails\":{\"modelInfo\":{\"modelInvariantUuid\":\"1de901ed-17af-4b03-bc1f-41659cfa27cb\",\"modelType\":\"service\",\"modelName\":\"demoVLB\",\"modelVersion\":\"1.0\",\"modelUuid\":\"ace39141-09ec-4068-b06d-ac6b23bdc6e0\"},\"requestInfo\":{\"productFamilyId\":\"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb\",\"source\":\"VID\",\"instanceName\":\"sample-instance-2\",\"suppressRollback\":false,\"requestorId\":\"1234\"},\"subscriberInfo\":{\"globalSubscriberId\":\"Demonstration\",\"subscriberName\":\"Demonstration\"},\"cloudConfiguration\":{\"tenantId\":\"onap\",\"lcpCloudRegionId\":\"RegionOne\"},\"requestParameters\":{\"subscriptionServiceType\":\"vLB\",\"aLaCarte\":false,\"autoBuildVfModules\":false,\"cascadeDelete\":false,\"usePreload\":true,\"rebuildVolumeGroups\":false}}}",\r
80       "type": "String"\r
81     },\r
82     "requestId": {\r
83       "value": "786230f6-5120-4400-aa6b-92a0eb214685",\r
84       "type": "String"\r
85     },\r
86     "mso-request-id": {\r
87       "value": "786230f6-5120-4400-aa6b-92a0eb214685",\r
88       "type": "String"\r
89     },\r
90     "isBaseVfModule": {\r
91       "value": false,\r
92       "type": "Boolean"\r
93     },\r
94     "recipeTimeout": {\r
95       "value": 180,\r
96       "type": "Integer"\r
97     },\r
98     "requestAction": {\r
99       "value": "createInstance",\r
100       "type": "String"\r
101     },\r
102     "serviceInstanceId": {\r
103       "value": "",\r
104       "type": "String"\r
105     },\r
106     "vnfId": {\r
107       "value": "",\r
108       "type": "String"\r
109     },\r
110     "vfModuleId": {\r
111       "value": "",\r
112       "type": "String"\r
113     },\r
114     "volumeGroupId": {\r
115       "value": "",\r
116       "type": "String"\r
117     },\r
118     "networkId": {\r
119       "value": "",\r
120       "type": "String"\r
121     },\r
122     "serviceType": {\r
123       "value": "demoVLB",\r
124       "type": "String"\r
125     },\r
126     "vnfType": {\r
127       "value": "",\r
128       "type": "String"\r
129     },\r
130     "vfModuleType": {\r
131       "value": "",\r
132       "type": "String"\r
133     },\r
134     "networkType": {\r
135       "value": "",\r
136       "type": "String"\r
137     },\r
138     "host": {\r
139       "value": "mso",\r
140       "type": "String"\r
141     }\r
142   }\r
143 }"""\r
144 \r
145             @Before\r
146                 public void init()\r
147                 {\r
148                         MockitoAnnotations.initMocks(this)\r
149                         \r
150                 }\r
151 \r
152                 public void initializeVariables(Execution mockExecution) {\r
153                         \r
154                         verify(mockExecution).setVariable(Prefix + "Success", false)\r
155                         \r
156                         verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")\r
157                         verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")\r
158                         verify(mockExecution).setVariable(Prefix + "isSilentSuccess", false)\r
159                                 \r
160                 }\r
161                                 \r
162                 @Test\r
163                 //@Ignore  \r
164                 public void preProcessRequest() {\r
165                         \r
166                         println "************ preProcessRequest() ************* " \r
167                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
168                         // Initialize prerequisite variables\r
169                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
170                         when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)\r
171                         try{\r
172                                                                         \r
173                                 // preProcessRequest(Execution execution)                                               \r
174                                 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()\r
175                                 createGenericALaCarteServiceInstance.preProcessRequest(mockExecution)\r
176 \r
177                                 verify(mockExecution).getVariable("isDebugLogEnabled")\r
178                                 verify(mockExecution).setVariable("prefix", Prefix)\r
179                         \r
180                                 initializeVariables(mockExecution)\r
181                                 //verify(mockExecution).setVariable(Prefix + "Success", false)\r
182                         }catch(Exception e){\r
183                                 //ignore\r
184                         }                       \r
185                 }\r
186                 \r
187                 @Test\r
188                 //@Ignore\r
189                 public void sendSyncResponse() {\r
190                         \r
191                         println "************ sendSyncResponse ************* "\r
192                         \r
193                         ExecutionEntity mockExecution = setupMock()\r
194                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
195                         when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)\r
196                         when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")\r
197                         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")\r
198                         try{\r
199                                 // preProcessRequest(Execution execution)\r
200                                 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()\r
201                                 CreateNetworkInstance.sendSyncResponse(mockExecution)\r
202 \r
203                                 verify(mockExecution).setVariable("prefix", Prefix)\r
204                                 verify(mockExecution).setVariable("CreateNetworkInstanceResponseCode", "202")\r
205                         }catch(Exception e){\r
206                                 //ignore\r
207                         }\r
208                 }\r
209                 \r
210                 @Test\r
211                 //@Ignore\r
212                 public void sendSyncError() {\r
213                         \r
214                         println "************ sendSyncError ************* "\r
215                         \r
216                         ExecutionEntity mockExecution = setupMock()\r
217                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
218                         when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)\r
219                         when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")\r
220                         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")\r
221                         try{\r
222                                 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()\r
223                                 CreateNetworkInstance.sendSyncError(mockExecution)\r
224 \r
225                                 verify(mockExecution).setVariable("prefix", Prefix)\r
226                                 verify(mockExecution).setVariable("CreateNetworkInstanceResponseCode", "500")\r
227                         }catch(Exception e){\r
228                                 //ignore\r
229                         }\r
230                 }\r
231                 \r
232                 private ExecutionEntity setupMock() {\r
233                         \r
234                         ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)\r
235                         when(mockProcessDefinition.getKey()).thenReturn("CreateNetworkInstance")\r
236                         RepositoryService mockRepositoryService = mock(RepositoryService.class)\r
237                         when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)\r
238                         when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("CreateNetworkInstance")\r
239                         when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")\r
240                         ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)\r
241                         when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)\r
242                         \r
243                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
244                         // Initialize prerequisite variables\r
245                         \r
246                         when(mockExecution.getId()).thenReturn("100")\r
247                         when(mockExecution.getProcessDefinitionId()).thenReturn("CreateNetworkInstance")\r
248                         when(mockExecution.getProcessInstanceId()).thenReturn("CreateNetworkInstance")\r
249                         when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)\r
250                         when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)\r
251                         \r
252                         return mockExecution\r
253                 }\r
254 }\r