Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DoScaleE2EServiceInstanceTest.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2018 CMCC 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 package org.onap.so.bpmn.infrastructure.scripts
21
22 import com.github.tomakehurst.wiremock.junit.WireMockRule
23 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
24 import org.junit.Before
25 import org.junit.BeforeClass
26 import org.junit.Rule
27 import org.junit.Test
28 import org.mockito.MockitoAnnotations
29 import org.onap.so.bpmn.mock.FileUtil
30 import org.onap.so.bpmn.vcpe.scripts.GroovyTestBase
31
32 import static org.mockito.Mockito.verify
33 import static org.mockito.Mockito.when
34
35 class DoScaleE2EServiceInstanceTest extends GroovyTestBase {
36
37     private static String request
38
39     @Rule
40     public WireMockRule wireMockRule = new WireMockRule(GroovyTestBase.PORT)
41
42     String Prefix = "CVRCS_"
43
44     @BeforeClass
45     public static void setUpBeforeClass() {
46         request = FileUtil.readResourceFile("__files/InfrastructureFlows/DoScaleE2EServiceInstance.json")
47     }
48
49     @Before
50     public void init()
51     {
52         MockitoAnnotations.initMocks(this)
53     }
54     public DoScaleE2EServiceInstanceTest(){
55         super("DoScaleE2EServiceInstance")
56     }
57
58     @Test
59     public void preProcessRequestTest(){
60
61         ExecutionEntity mex = setupMock()
62         def map = setupMap(mex)
63         initPreProcess(mex)
64
65         DoScaleE2EServiceInstance instance = new DoScaleE2EServiceInstance()
66         instance.preProcessRequest(mex)
67         verify(mex).setVariable("resourceTemplateUUIDs", "ns111:ns333:")
68     }
69
70     @Test
71     public void preInitResourcesOperStatusTest(){
72         ExecutionEntity mex = setupMock()
73         def map = setupMap(mex)
74         initPreProcess(mex)
75         DoScaleE2EServiceInstance instance = new DoScaleE2EServiceInstance()
76         instance.preInitResourcesOperStatus(mex)
77
78         verify(mex).setVariable("serviceInstanceId","e151059a-d924-4629-845f-264db19e50b4")
79         verify(mex).setVariable("operationId", "59960003992")
80         verify(mex).setVariable("operationType", "SCALE")
81         verify(mex).setVariable("URN_mso_openecomp_adapters_db_endpoint","http://mso.mso.testlab.openecomp.org:8080/dbadapters/RequestsDbAdapter")
82
83         String payload =
84                 """<soapenv:Envelope xmlns:ns="http://org.onap.so/requestsdb"
85                   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
86    <soapenv:Header/>
87    <soapenv:Body>
88       <ns:initResourceOperationStatus>
89          <serviceId>e151059a-d924-4629-845f-264db19e50b4</serviceId>
90          <operationId>59960003992</operationId>
91          <operationType>SCALE</operationType>
92          <resourceTemplateUUIDs>ns111:ns333:</resourceTemplateUUIDs>
93       </ns:initResourceOperationStatus>
94    </soapenv:Body>
95 </soapenv:Envelope>"""
96         verify(mex).setVariable("CVFMI_initResOperStatusRequest", payload)
97     }
98
99     private void initPreProcess(ExecutionEntity mex) {
100         when(mex.getVariable(GroovyTestBase.DBGFLAG)).thenReturn("true")
101         when(mex.getVariable("bpmnRequest")).thenReturn(request)
102         when(mex.getVariable("msoRequestId")).thenReturn("mri")
103         when(mex.getVariable("serviceType")).thenReturn("VoLTE")
104         when(mex.getVariable("serviceInstanceId")).thenReturn("e151059a-d924-4629-845f-264db19e50b4")
105         when(mex.getVariable("serviceInstanceName")).thenReturn("ra")
106         when(mex.getVariable("operationId")).thenReturn("59960003992")
107         when(mex.getVariable("globalSubscriberId")).thenReturn("4993921112123")
108         when(mex.getVariable("resourceTemplateUUIDs")).thenReturn("ns111:ns333:")
109     }
110 }