Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / ScaleCustomE2EServiceInstanceTest.groovy
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                             <operationType>SCALE</operationType>
93                             <userId></userId>
94                             <result>processing</result>
95                             <operationContent>Prepare service scaling</operationContent>
96                             <progress>0</progress>
97                             <reason></reason>
98                         </ns:updateServiceOperationStatus>
99                     </soapenv:Body>
100                 </soapenv:Envelope>"""
101
102     @Before
103     public void init()
104     {
105         MockitoAnnotations.initMocks(this)
106     }
107
108     @Test
109     public void preProcessRequestTest() {
110         println "************ preProcessRequest_Payload ************* "
111         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
112
113         // Initialize prerequisite variables
114         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
115         when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
116
117         when(mockExecution.getVariable("mso-request-id")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
118         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
119
120         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
121         scaleCustomE2EServiceInstance.preProcessRequest(mockExecution)
122
123         verify(mockExecution).setVariable("globalSubscriberId", globalSubscriberId)
124         verify(mockExecution).setVariable("prefix", Prefix)
125         verify(mockExecution).setVariable("requestDescription", requestDescription)
126     }
127
128     @Test
129     public void sendSyncResponseTest() {
130         println "************ sendSyncResponse ************* "
131         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
132
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")
136
137         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
138         scaleCustomE2EServiceInstance.sendSyncResponse(mockExecution)
139
140         verify(mockExecution).setVariable("sentSyncResponse", true)
141     }
142
143     @Test
144     public void prepareCompletionRequestTest() {
145         println "************ prepareCompletionRequest ************* "
146         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
147
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")
151
152         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
153         scaleCustomE2EServiceInstance.prepareCompletionRequest(mockExecution)
154
155         verify(mockExecution).setVariable("CompleteMsoProcessRequest", xmlMsoCompletionRequest)
156
157     }
158
159     @Test
160     public void prepareInitServiceOperationStatusTest() {
161         println "************ prepareInitServiceOperationStatus ************* "
162         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
163
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")
167
168         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
169         scaleCustomE2EServiceInstance.prepareInitServiceOperationStatus(mockExecution)
170
171         payload = utils.formatXml(payload)
172         verify(mockExecution).setVariable("CVFMI_updateServiceOperStatusRequest", payload)
173     }
174
175 }