e5d9d62392ac532eeb1bea88eee84b3e8be951cf
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / CreateGenericAlaCarteServiceInstanceTest.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.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="CRESI_"\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         "requestDetails": {\r
78         "modelInfo": {\r
79         "modelType": "service",\r
80         "modelInvariantId": "1de901ed-17af-4b03-bc1f-41659cfa27cb",\r
81         "modelVersionId": "ace39141-09ec-4068-b06d-ac6b23bdc6e0",\r
82         "modelName": "demoVLB",\r
83         "modelVersion": "1.0"\r
84         },\r
85         "cloudConfiguration" : {\r
86         "lcpCloudRegionId": "RegionOne",\r
87         "tenantId": "onap"\r
88         },\r
89         "subscriberInfo": {\r
90         "globalSubscriberId": "Demonstration",\r
91         "subscriberName": "Demonstration"\r
92         },\r
93         "requestInfo": {\r
94         "instanceName": "sample-instance-2",\r
95         "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",\r
96         "source": "VID",\r
97         "requestorId":"1234",\r
98         "suppressRollback": "false"\r
99         },\r
100         "requestParameters": {\r
101         "subscriptionServiceType": "vLB"\r
102         }\r
103         }\r
104         }"""\r
105 \r
106             @Before\r
107                 public void init()\r
108                 {\r
109                         MockitoAnnotations.initMocks(this)\r
110                         \r
111                 }\r
112 \r
113                 public void initializeVariables(Execution mockExecution) {\r
114                         \r
115                         //verify(mockExecution).setVariable(Prefix + "Success", false)\r
116                         \r
117                         //verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")\r
118                         //verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")\r
119                         //verify(mockExecution).setVariable(Prefix + "isSilentSuccess", false)\r
120                                 \r
121                 }\r
122                                 \r
123                 @Test\r
124                 //@Ignore  \r
125                 public void preProcessRequest() {\r
126                         \r
127                         println "************ preProcessRequest() ************* " \r
128                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
129                         // Initialize prerequisite variables\r
130                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
131                         when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)\r
132                         try{\r
133                                                                         \r
134                                 // preProcessRequest(Execution execution)                                               \r
135                                 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()\r
136                                 createGenericALaCarteServiceInstance.preProcessRequest(mockExecution)\r
137 \r
138                                 //verify(mockExecution).getVariable("isDebugLogEnabled")\r
139                                 //verify(mockExecution).setVariable("prefix", Prefix)\r
140                         \r
141                                 initializeVariables(mockExecution)\r
142                                 //verify(mockExecution).setVariable(Prefix + "Success", false)\r
143                         }catch(Exception e){\r
144                                 //ignore\r
145                         }                       \r
146                 }\r
147                 \r
148                 @Test\r
149                 //@Ignore\r
150                 public void sendSyncResponse() {\r
151                         \r
152                         println "************ sendSyncResponse ************* "\r
153                         \r
154                         ExecutionEntity mockExecution = setupMock()\r
155                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
156                         when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)\r
157                         when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")\r
158                         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")\r
159                         try{\r
160                                 // preProcessRequest(Execution execution)\r
161                                 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()\r
162                                 createGenericALaCarteServiceInstance.sendSyncResponse(mockExecution)\r
163 \r
164                                 //verify(mockExecution).setVariable("prefix", Prefix)\r
165                                 //verify(mockExecution).setVariable("createServiceRestRequest", "202")\r
166                         }catch(Exception e){\r
167                                 //ignore\r
168                         }\r
169                 }\r
170                 \r
171                 @Test\r
172                 //@Ignore\r
173                 public void sendSyncError() {\r
174                         \r
175                         println "************ sendSyncError ************* "\r
176                         \r
177                         ExecutionEntity mockExecution = setupMock()\r
178                         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")\r
179                         when(mockExecution.getVariable("isAsyncProcess")).thenReturn(true)\r
180                         when(mockExecution.getVariable("mso-request-id")).thenReturn("e8ebf6a0-f8ea-4dc0-8b99-fe98a87722d6")\r
181                         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("f70e927b-6087-4974-9ef8-c5e4d5847ca4")\r
182                         try{\r
183                                 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()\r
184                                 createGenericALaCarteServiceInstance.sendSyncError(mockExecution)\r
185 \r
186                                 //verify(mockExecution).setVariable("prefix", Prefix)\r
187                                 //verify(mockExecution).setVariable("createServiceRestRequest", "500")\r
188                         }catch(Exception e){\r
189                                 //ignore\r
190                         }\r
191                 }\r
192                 \r
193                 private ExecutionEntity setupMock() {\r
194                         \r
195                         ProcessDefinition mockProcessDefinition = mock(ProcessDefinition.class)\r
196                         when(mockProcessDefinition.getKey()).thenReturn("CreateGenericALaCarteSeviceInstance")\r
197                         RepositoryService mockRepositoryService = mock(RepositoryService.class)\r
198                         when(mockRepositoryService.getProcessDefinition()).thenReturn(mockProcessDefinition)\r
199                         when(mockRepositoryService.getProcessDefinition().getKey()).thenReturn("CreateGenericALaCarteSeviceInstance")\r
200                         when(mockRepositoryService.getProcessDefinition().getId()).thenReturn("100")\r
201                         ProcessEngineServices mockProcessEngineServices = mock(ProcessEngineServices.class)\r
202                         when(mockProcessEngineServices.getRepositoryService()).thenReturn(mockRepositoryService)\r
203                         \r
204                         ExecutionEntity mockExecution = mock(ExecutionEntity.class)\r
205                         // Initialize prerequisite variables\r
206                         \r
207                         when(mockExecution.getId()).thenReturn("100")\r
208                         when(mockExecution.getProcessDefinitionId()).thenReturn("CreateGenericALaCarteSeviceInstance")\r
209                         when(mockExecution.getProcessInstanceId()).thenReturn("CreateGenericALaCarteSeviceInstance")\r
210                         when(mockExecution.getProcessEngineServices()).thenReturn(mockProcessEngineServices)\r
211                         when(mockExecution.getProcessEngineServices().getRepositoryService().getProcessDefinition(mockExecution.getProcessDefinitionId())).thenReturn(mockProcessDefinition)\r
212                         \r
213                         return mockExecution\r
214                 }\r
215 }\r