1 package org.openecomp.mso.bpmn.infrastructure.scripts
3 import static org.mockito.Mockito.*
5 import org.apache.commons.lang3.*
6 import org.camunda.bpm.engine.ProcessEngineServices
7 import org.camunda.bpm.engine.RepositoryService
8 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
9 import org.camunda.bpm.engine.repository.ProcessDefinition
10 import org.camunda.bpm.engine.runtime.Execution
11 import org.junit.Before
14 import org.junit.runner.RunWith
15 import org.mockito.MockitoAnnotations
16 import org.mockito.runners.MockitoJUnitRunner
17 import org.openecomp.mso.bpmn.common.scripts.MsoUtils
18 import org.openecomp.mso.bpmn.core.WorkflowException
19 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
22 import com.github.tomakehurst.wiremock.junit.WireMockRule
24 @RunWith(MockitoJUnitRunner.class)
25 class SacleCustomE2EServiceInstanceTest{
27 public WireMockRule wireMockRule = new WireMockRule(8090);
29 String Prefix="CRESI_"
30 ExceptionUtil exceptionUtil = new ExceptionUtil()
31 String globalSubscriberId="test_custormer"
32 String requestDescription = "request description for test"
33 def utils = new MsoUtils()
35 String jsonIncomingRequest = """{"service":{
36 "serviceType":"example-service-type",
37 "globalSubscriberId":"test_custormer",
40 "resourceInstanceId":"ns111",
41 "scaleType":"SCALE_NS",
43 "scaleNsByStepsData":{
45 "aspectId":"TIC_EDGE_HW",
46 "scalingDirection":"UP"
51 "resourceInstanceId":"ns333",
52 "scaleType":"SCALE_NS",
54 "scaleNsByStepsData":{
56 "aspectId":"TIC_EDGE_HW",
57 "scalingDirection":"UP"
61 "serviceInstanceName":"XXXX"
63 "operationId":"0a5b1651-c56e-4263-8c26-c8f8a6ef72d8"
66 String xmlMsoCompletionRequest = """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.openecomp/mso/workflow/schema/v1"
67 xmlns:ns="http://org.openecomp/mso/request/types/v1"
68 xmlns:w1aaan0="http://org.openecomp/mso/infra/vnf-request/v1">
69 <w1aaan0:request-info>
70 <w1aaan0:request-id>56c881ad-6c9d-4b79-aacc-401e5640b47f</w1aaan0:request-id>
71 <w1aaan0:action>SCALE</w1aaan0:action>
72 <w1aaan0:source>null</w1aaan0:source>
73 </w1aaan0:request-info>
74 <status-message>Service Instance was scaled successfully.</status-message>
75 <serviceInstanceId>56c881ad-6c9d-4b79-aacc-401e5640b47f</serviceInstanceId>
76 <mso-bpel-name>ScaleGenericALaCarteServiceInstance</mso-bpel-name>
77 </aetgt:MsoCompletionRequest>"""
79 String requestInfo = """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">
80 <request-id>56c881ad-6c9d-4b79-aacc-401e5640b47f</request-id>
81 <action>SCALE</action>
85 String payload ="""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
86 xmlns:ns="http://org.openecomp.mso/requestsdb">
89 <ns:updateServiceOperationStatus xmlns:ns="http://org.openecomp.mso/requestsdb">
90 <serviceId>56c881ad-6c9d-4b79-aacc-401e5640b47f</serviceId>
91 <operationId>0a5b1651-c56e-4263-8c26-c8f8a6ef72d8</operationId>
92 <operationType>SCALE</operationType>
94 <result>processing</result>
95 <operationContent>Prepare service scaling</operationContent>
96 <progress>0</progress>
98 </ns:updateServiceOperationStatus>
100 </soapenv:Envelope>"""
105 MockitoAnnotations.initMocks(this)
109 public void preProcessRequestTest() {
110 println "************ preProcessRequest_Payload ************* "
111 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
113 // Initialize prerequisite variables
114 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
115 when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
117 when(mockExecution.getVariable("mso-request-id")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
118 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
120 ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
121 scaleCustomE2EServiceInstance.preProcessRequest(mockExecution)
123 verify(mockExecution).setVariable("globalSubscriberId", globalSubscriberId)
124 verify(mockExecution).setVariable("prefix", Prefix)
125 verify(mockExecution).setVariable("requestDescription", requestDescription)
129 public void sendSyncResponseTest() {
130 println "************ sendSyncResponse ************* "
131 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
133 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
134 when(mockExecution.getVariable("operationId")).thenReturn("3338b250-e995-4782-8936-081b66ba4dbf")
135 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
137 ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
138 scaleCustomE2EServiceInstance.sendSyncResponse(mockExecution)
140 verify(mockExecution).setVariable("sentSyncResponse", true)
144 public void prepareCompletionRequestTest() {
145 println "************ prepareCompletionRequest ************* "
146 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
148 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
149 when(mockExecution.getVariable("msoRequestId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
150 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
152 ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
153 scaleCustomE2EServiceInstance.prepareCompletionRequest(mockExecution)
155 verify(mockExecution).setVariable("CompleteMsoProcessRequest", xmlMsoCompletionRequest)
160 public void prepareInitServiceOperationStatusTest() {
161 println "************ prepareInitServiceOperationStatus ************* "
162 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
164 when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
165 //when(mockExecution.getVariable("serviceInstanceName")).thenReturn("XXXX")
166 when(mockExecution.getVariable("operationId")).thenReturn("0a5b1651-c56e-4263-8c26-c8f8a6ef72d8")
168 ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
169 scaleCustomE2EServiceInstance.prepareInitServiceOperationStatus(mockExecution)
171 payload = utils.formatXml(payload)
172 verify(mockExecution).setVariable("CVFMI_updateServiceOperStatusRequest", payload)