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.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 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="CRESI_"
\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 "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
85 "cloudConfiguration" : {
\r
86 "lcpCloudRegionId": "RegionOne",
\r
90 "globalSubscriberId": "Demonstration",
\r
91 "subscriberName": "Demonstration"
\r
94 "instanceName": "sample-instance-2",
\r
95 "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",
\r
97 "requestorId":"1234",
\r
98 "suppressRollback": "false"
\r
100 "requestParameters": {
\r
101 "subscriptionServiceType": "vLB"
\r
109 MockitoAnnotations.initMocks(this)
\r
113 public void initializeVariables(DelegateExecution mockExecution) {
\r
115 //verify(mockExecution).setVariable(Prefix + "Success", false)
\r
117 //verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")
\r
118 //verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")
\r
119 //verify(mockExecution).setVariable(Prefix + "isSilentSuccess", false)
\r
125 public void preProcessRequest() {
\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
134 // preProcessRequest(DelegateExecution execution)
\r
135 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()
\r
136 createGenericALaCarteServiceInstance.preProcessRequest(mockExecution)
\r
138 //verify(mockExecution).getVariable("isDebugLogEnabled")
\r
139 //verify(mockExecution).setVariable("prefix", Prefix)
\r
141 initializeVariables(mockExecution)
\r
142 //verify(mockExecution).setVariable(Prefix + "Success", false)
\r
143 }catch(Exception e){
\r
150 public void sendSyncResponse() {
\r
152 println "************ sendSyncResponse ************* "
\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
160 // preProcessRequest(DelegateExecution execution)
\r
161 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()
\r
162 createGenericALaCarteServiceInstance.sendSyncResponse(mockExecution)
\r
164 //verify(mockExecution).setVariable("prefix", Prefix)
\r
165 //verify(mockExecution).setVariable("createServiceRestRequest", "202")
\r
166 }catch(Exception e){
\r
173 public void sendSyncError() {
\r
175 println "************ sendSyncError ************* "
\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
183 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()
\r
184 createGenericALaCarteServiceInstance.sendSyncError(mockExecution)
\r
186 //verify(mockExecution).setVariable("prefix", Prefix)
\r
187 //verify(mockExecution).setVariable("createServiceRestRequest", "500")
\r
188 }catch(Exception e){
\r
193 private ExecutionEntity setupMock() {
\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
204 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
\r
205 // Initialize prerequisite variables
\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
213 return mockExecution
\r