Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / ScaleCustomE2EServiceInstanceTest.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23 import static org.mockito.Mockito.*
24
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.ProcessEngineServices
27 import org.camunda.bpm.engine.RepositoryService
28 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
29 import org.camunda.bpm.engine.repository.ProcessDefinition
30 import org.camunda.bpm.engine.runtime.Execution
31 import org.junit.Before
32 import org.junit.Rule
33 import org.junit.Test
34 import org.junit.runner.RunWith
35 import org.mockito.MockitoAnnotations
36 import org.mockito.runners.MockitoJUnitRunner
37 import org.onap.so.bpmn.common.scripts.MsoUtils
38 import org.onap.so.bpmn.core.WorkflowException
39 import org.onap.so.bpmn.common.scripts.ExceptionUtil
40
41
42 import com.github.tomakehurst.wiremock.junit.WireMockRule
43
44 @RunWith(MockitoJUnitRunner.class)
45 class SacleCustomE2EServiceInstanceTest{
46     @Rule
47     public WireMockRule wireMockRule = new WireMockRule(8090);
48
49     String Prefix="CRESI_"
50     ExceptionUtil exceptionUtil = new ExceptionUtil()
51     String globalSubscriberId="test_custormer"
52     String requestDescription = "request description for test"
53     def utils = new MsoUtils()
54
55     String jsonIncomingRequest = """{"service":{
56                                         "serviceType":"example-service-type",
57                                         "globalSubscriberId":"test_custormer",
58                                         "resources":[
59                                             {
60                                                 "resourceInstanceId":"ns111",
61                                                 "scaleType":"SCALE_NS",
62                                                 "scaleNsData":{
63                                                     "scaleNsByStepsData":{
64                                                         "numberOfSteps":"4",
65                                                         "aspectId":"TIC_EDGE_HW",
66                                                         "scalingDirection":"UP"
67                                                         }
68                                                 }
69                                             },
70                                             {
71                                                 "resourceInstanceId":"ns333",
72                                                 "scaleType":"SCALE_NS",
73                                                 "scaleNsData":{
74                                                     "scaleNsByStepsData":{
75                                                         "numberOfSteps":"4",
76                                                         "aspectId":"TIC_EDGE_HW",
77                                                         "scalingDirection":"UP"
78                                                     }
79                                                 }
80                                             }],
81                                         "serviceInstanceName":"XXXX"
82                                      },
83                                      "operationId":"0a5b1651-c56e-4263-8c26-c8f8a6ef72d8"
84                                    }"""
85
86     String xmlMsoCompletionRequest = """<aetgt:MsoCompletionRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1"
87                             xmlns:ns="http://org.onap/so/request/types/v1"
88                             xmlns:w1aaan0="http://org.onap/so/infra/vnf-request/v1">
89    <w1aaan0:request-info>
90       <w1aaan0:request-id>56c881ad-6c9d-4b79-aacc-401e5640b47f</w1aaan0:request-id>
91       <w1aaan0:action>SCALE</w1aaan0:action>
92       <w1aaan0:source>null</w1aaan0:source>
93    </w1aaan0:request-info>
94    <status-message>Service Instance was scaled successfully.</status-message>
95    <serviceInstanceId>56c881ad-6c9d-4b79-aacc-401e5640b47f</serviceInstanceId>
96    <mso-bpel-name>ScaleGenericALaCarteServiceInstance</mso-bpel-name>
97 </aetgt:MsoCompletionRequest>"""
98
99     String requestInfo = """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
100                                         <request-id>56c881ad-6c9d-4b79-aacc-401e5640b47f</request-id>
101                                         <action>SCALE</action>
102                                         <source>null</source>
103                                    </request-info>"""
104
105     String payload ="""<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
106                         xmlns:ns="http://org.onap.so/requestsdb">
107                         <soapenv:Header/>
108                         <soapenv:Body>
109                             <ns:updateServiceOperationStatus xmlns:ns="http://org.onap.so/requestsdb">
110                             <serviceId>56c881ad-6c9d-4b79-aacc-401e5640b47f</serviceId>
111                             <operationId>0a5b1651-c56e-4263-8c26-c8f8a6ef72d8</operationId>
112                             <operationType>SCALE</operationType>
113                             <userId></userId>
114                             <result>processing</result>
115                             <operationContent>Prepare service scaling</operationContent>
116                             <progress>0</progress>
117                             <reason></reason>
118                         </ns:updateServiceOperationStatus>
119                     </soapenv:Body>
120                 </soapenv:Envelope>"""
121
122     @Before
123     public void init()
124     {
125         MockitoAnnotations.initMocks(this)
126     }
127
128     @Test
129     public void preProcessRequestTest() {
130         println "************ preProcessRequest_Payload ************* "
131         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
132
133         // Initialize prerequisite variables
134         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
135         when(mockExecution.getVariable("bpmnRequest")).thenReturn(jsonIncomingRequest)
136
137         when(mockExecution.getVariable("mso-request-id")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
138         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
139
140         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
141         scaleCustomE2EServiceInstance.preProcessRequest(mockExecution)
142
143         verify(mockExecution).setVariable("globalSubscriberId", globalSubscriberId)
144         verify(mockExecution).setVariable("prefix", Prefix)
145         verify(mockExecution).setVariable("requestDescription", requestDescription)
146     }
147
148     @Test
149     public void sendSyncResponseTest() {
150         println "************ sendSyncResponse ************* "
151         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
152
153         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
154         when(mockExecution.getVariable("operationId")).thenReturn("3338b250-e995-4782-8936-081b66ba4dbf")
155         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
156
157         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
158         scaleCustomE2EServiceInstance.sendSyncResponse(mockExecution)
159
160         verify(mockExecution).setVariable("sentSyncResponse", true)
161     }
162
163     @Test
164     public void prepareCompletionRequestTest() {
165         println "************ prepareCompletionRequest ************* "
166         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
167
168         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
169         when(mockExecution.getVariable("msoRequestId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
170         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
171
172         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
173         scaleCustomE2EServiceInstance.prepareCompletionRequest(mockExecution)
174
175         verify(mockExecution).setVariable("CompleteMsoProcessRequest", xmlMsoCompletionRequest)
176
177     }
178
179     @Test
180     public void prepareInitServiceOperationStatusTest() {
181         println "************ prepareInitServiceOperationStatus ************* "
182         ExecutionEntity mockExecution = mock(ExecutionEntity.class)
183
184         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("56c881ad-6c9d-4b79-aacc-401e5640b47f")
185         //when(mockExecution.getVariable("serviceInstanceName")).thenReturn("XXXX")
186         when(mockExecution.getVariable("operationId")).thenReturn("0a5b1651-c56e-4263-8c26-c8f8a6ef72d8")
187
188         ScaleCustomE2EServiceInstance scaleCustomE2EServiceInstance = new ScaleCustomE2EServiceInstance()
189         scaleCustomE2EServiceInstance.prepareInitServiceOperationStatus(mockExecution)
190
191         payload = utils.formatXml(payload)
192         verify(mockExecution).setVariable("CVFMI_updateServiceOperStatusRequest", payload)
193     }
194
195 }