2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
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
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
37 import static org.junit.Assert.*;
38 import static org.mockito.Mockito.*
40 import com.github.tomakehurst.wiremock.junit.WireMockRule
42 class CreateGenericAlaCarteServiceInstanceTest {
45 public WireMockRule wireMockRule = new WireMockRule(8090);
47 String Prefix="CRESI_"
48 def utils = new MsoUtils()
49 JsonUtils jsonUtil = new JsonUtils()
50 VidUtils vidUtils = new VidUtils()
52 String createDBRequestError =
53 """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
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><network-id></network-id><network-name></network-names></vnfOutputs>
63 </ns:updateInfraRequest>
65 </soapenv:Envelope>"""
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>
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>"""
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">
87 <request-id>88f65519-9a38-4c4b-8445-9eb4a5a5af56</request-id>
88 <action>CREATE</action>
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>"""
95 String jsonIncomingRequest =
99 "modelType": "service",
100 "modelInvariantId": "1de901ed-17af-4b03-bc1f-41659cfa27cb",
101 "modelVersionId": "ace39141-09ec-4068-b06d-ac6b23bdc6e0",
102 "modelName": "demoVLB",
103 "modelVersion": "1.0"
105 "cloudConfiguration" : {
106 "lcpCloudRegionId": "RegionOne",
110 "globalSubscriberId": "Demonstration",
111 "subscriberName": "Demonstration"
114 "instanceName": "sample-instance-2",
115 "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb",
117 "requestorId":"1234",
118 "suppressRollback": "false"
120 "requestParameters": {
121 "subscriptionServiceType": "vLB"
129 MockitoAnnotations.initMocks(this)
133 public void initializeVariables(DelegateExecution mockExecution) {
135 //verify(mockExecution).setVariable(Prefix + "Success", false)
137 //verify(mockExecution).setVariable(Prefix + "CompleteMsoProcessRequest", "")
138 //verify(mockExecution).setVariable(Prefix + "FalloutHandlerRequest", "")
139 //verify(mockExecution).setVariable(Prefix + "isSilentSuccess", false)
145 public void preProcessRequest() {
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)
154 // preProcessRequest(DelegateExecution execution)
155 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()
156 createGenericALaCarteServiceInstance.preProcessRequest(mockExecution)
158 //verify(mockExecution).getVariable("isDebugLogEnabled")
159 //verify(mockExecution).setVariable("prefix", Prefix)
161 initializeVariables(mockExecution)
162 //verify(mockExecution).setVariable(Prefix + "Success", false)
170 public void sendSyncResponse() {
172 println "************ sendSyncResponse ************* "
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")
180 // preProcessRequest(DelegateExecution execution)
181 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()
182 createGenericALaCarteServiceInstance.sendSyncResponse(mockExecution)
184 //verify(mockExecution).setVariable("prefix", Prefix)
185 //verify(mockExecution).setVariable("createServiceRestRequest", "202")
193 public void sendSyncError() {
195 println "************ sendSyncError ************* "
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")
203 CreateGenericALaCarteServiceInstance createGenericALaCarteServiceInstance = new CreateGenericALaCarteServiceInstance()
204 createGenericALaCarteServiceInstance.sendSyncError(mockExecution)
206 //verify(mockExecution).setVariable("prefix", Prefix)
207 //verify(mockExecution).setVariable("createServiceRestRequest", "500")
213 private ExecutionEntity setupMock() {
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)
224 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
225 // Initialize prerequisite variables
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)