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