1 package org.openecomp.mso.bpmn.infrastructure.scripts
\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
17 import static org.junit.Assert.*;
\r
18 import static org.mockito.Mockito.*
\r
20 import com.github.tomakehurst.wiremock.junit.WireMockRule
\r
22 class CreateGenericAlaCarteServiceInstanceTest {
\r
25 public WireMockRule wireMockRule = new WireMockRule(8090);
\r
27 String Prefix="CRENI_"
\r
28 def utils = new MsoUtils()
\r
29 JsonUtils jsonUtil = new JsonUtils()
\r
30 VidUtils vidUtils = new VidUtils()
\r
32 String createDBRequestError =
\r
33 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
\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><network-id></network-id><network-name></network-names></vnfOutputs>
\r
43 </ns:updateInfraRequest>
\r
45 </soapenv:Envelope>"""
\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
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
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
67 <request-id>88f65519-9a38-4c4b-8445-9eb4a5a5af56</request-id>
\r
68 <action>CREATE</action>
\r
69 <source>VID</source>
\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
75 String jsonIncomingRequest =
\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
83 "value": "786230f6-5120-4400-aa6b-92a0eb214685",
\r
87 "value": "786230f6-5120-4400-aa6b-92a0eb214685",
\r
99 "value": "createInstance",
\r
102 "serviceInstanceId": {
\r
123 "value": "demoVLB",
\r
148 MockitoAnnotations.initMocks(this)
\r
152 public void initializeVariables(Execution mockExecution) {
\r
154 verify(mockExecution).setVariable(Prefix + "Success", false)
\r
156 verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")
\r
157 verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")
\r
158 verify(mockExecution).setVariable(Prefix + "isSilentSuccess", false)
\r
164 public void preProcessRequest() {
\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
173 // preProcessRequest(Execution execution)
\r
174 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()
\r
175 createGenericALaCarteServiceInstance.preProcessRequest(mockExecution)
\r
177 verify(mockExecution).getVariable("isDebugLogEnabled")
\r
178 verify(mockExecution).setVariable("prefix", Prefix)
\r
180 initializeVariables(mockExecution)
\r
181 //verify(mockExecution).setVariable(Prefix + "Success", false)
\r
182 }catch(Exception e){
\r
189 public void sendSyncResponse() {
\r
191 println "************ sendSyncResponse ************* "
\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
199 // preProcessRequest(Execution execution)
\r
200 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
201 CreateNetworkInstance.sendSyncResponse(mockExecution)
\r
203 verify(mockExecution).setVariable("prefix", Prefix)
\r
204 verify(mockExecution).setVariable("CreateNetworkInstanceResponseCode", "202")
\r
205 }catch(Exception e){
\r
212 public void sendSyncError() {
\r
214 println "************ sendSyncError ************* "
\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
222 CreateNetworkInstance CreateNetworkInstance = new CreateNetworkInstance()
\r
223 CreateNetworkInstance.sendSyncError(mockExecution)
\r
225 verify(mockExecution).setVariable("prefix", Prefix)
\r
226 verify(mockExecution).setVariable("CreateNetworkInstanceResponseCode", "500")
\r
227 }catch(Exception e){
\r
232 private ExecutionEntity setupMock() {
\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
243 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
244 // Initialize prerequisite variables
\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
252 return mockExecution
\r