e7ffe0542418e2df6a890495ef71f43ee271ae01
[so.git] /
1 package org.openecomp.mso.bpmn.infrastructure.scripts
2
3 import static org.mockito.Mockito.*
4
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
12 import org.junit.Rule
13 import org.junit.Test
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
20
21
22 import com.github.tomakehurst.wiremock.junit.WireMockRule
23
24 @RunWith(MockitoJUnitRunner.class)
25 class SacleCustomE2EServiceInstanceTest{
26     @Rule
27     public WireMockRule wireMockRule = new WireMockRule(8090);
28
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()
34
35     String jsonIncomingRequest = """{"service":{
36                                         "serviceType":"example-service-type",
37                                         "globalSubscriberId":"test_custormer",
38                                         "resources":[
39                                             {
40                                                 "resourceInstanceId":"ns111",
41                                                 "scaleType":"SCALE_NS",
42                                                 "scaleNsData":{
43                                                     "scaleNsByStepsData":{
44                                                         "numberOfSteps":"4",
45                                                         "aspectId":"TIC_EDGE_HW",
46                                                         "scalingDirection":"UP"
47                                                         }
48                                                 }
49                                             },
50                                             {
51                                                 "resourceInstanceId":"ns333",
52                                                 "scaleType":"SCALE_NS",
53                                                 "scaleNsData":{
54                                                     "scaleNsByStepsData":{
55                                                         "numberOfSteps":"4",
56                                                         "aspectId":"TIC_EDGE_HW",
57                                                         "scalingDirection":"UP"
58                                                     }
59                                                 }
60                                             }],
61                                         "serviceInstanceName":"XXXX"
62                                      },
63                                      "operationId":"0a5b1651-c56e-4263-8c26-c8f8a6ef72d8"
64                                    }"""
65
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>"""
78
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>
82                                         <source>null</source>
83                                    </request-info>"""
84
85     String payload ="""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
86                         xmlns:ns="http://org.openecomp.mso/requestsdb">
87                         <soapenv:Header/>
88                         <soapenv:Body>
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                             <serviceName>XXXX</serviceName>
93                             <operationType>SCALE</operationType>
94                             <userId></userId>
95                             <result>processing</result>
96                             <operationContent>Prepare service scaling</operationContent>
97                             <progress>0</progress>
98                             <reason></reason>
99                         </ns:updateServiceOperationStatus>
100                     </soapenv:Body>
101                 </soapenv:Envelope>"""
102
103     @Before
104     public void init()
105     {
106         MockitoAnnotations.initMocks(this)
107     }
108
109     @Test
110     public void preProcessRequestTest() {
111         println "************ preProcessRequest_Payload ************* "
112         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
113
114         // Initialize prerequisite variables
115         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
116         when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
117
118         when(mockExecution.getVariable("mso-request-id")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
119         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
120
121         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
122         scaleCustomE2EServiceInstance.preProcessRequest(mockExecution)
123
124         verify(mockExecution).setVariable("globalSubscriberId", globalSubscriberId)
125         verify(mockExecution).setVariable("prefix", Prefix)
126         verify(mockExecution).setVariable("requestDescription", requestDescription)
127     }
128
129     @Test
130     public void sendSyncResponseTest() {
131         println "************ sendSyncResponse ************* "
132         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
133
134         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
135         when(mockExecution.getVariable("operationId")).thenReturn("3338b250-e995-4782-8936-081b66ba4dbf")
136         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
137
138         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
139         scaleCustomE2EServiceInstance.sendSyncResponse(mockExecution)
140
141         verify(mockExecution).setVariable("sentSyncResponse", true)
142     }
143
144     @Test
145     public void prepareCompletionRequestTest() {
146         println "************ prepareCompletionRequest ************* "
147         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
148
149         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
150         when(mockExecution.getVariable("msoRequestId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
151         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
152
153         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
154         scaleCustomE2EServiceInstance.prepareCompletionRequest(mockExecution)
155
156         verify(mockExecution).setVariable("CompleteMsoProcessRequest", xmlMsoCompletionRequest)
157
158     }
159
160     @Test
161     public void prepareInitServiceOperationStatusTest() {
162         println "************ prepareInitServiceOperationStatus ************* "
163         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
164
165         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
166         when(mockExecution.getVariable("serviceInstanceName")).thenReturn("XXXX")
167         when(mockExecution.getVariable("operationId")).thenReturn("0a5b1651-c56e-4263-8c26-c8f8a6ef72d8")
168
169         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
170         scaleCustomE2EServiceInstance.prepareInitServiceOperationStatus(mockExecution)
171
172         payload = utils.formatXml(payload)
173         verify(mockExecution).setVariable("CVFMI_updateServiceOperStatusRequest", payload)
174     }
175
176 }