Containerization feature of SO
[so.git] / bpmn / so-bpmn-infrastructure-flows / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DeleteCustomE2EServiceInstanceTest.groovy
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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 com.github.tomakehurst.wiremock.junit.WireMockRule
24 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
25 import org.junit.Before
26 import org.junit.BeforeClass
27 import org.junit.Rule
28 import org.junit.Test
29 import org.mockito.MockitoAnnotations
30 import org.onap.so.bpmn.mock.FileUtil
31 import org.onap.so.bpmn.vcpe.scripts.GroovyTestBase
32
33 import static org.mockito.Mockito.verify
34 import static org.mockito.Mockito.when
35
36 class DeleteCustomE2EServiceInstanceTest extends GroovyTestBase {
37
38     private static String request
39
40     @Rule
41     public WireMockRule wireMockRule = new WireMockRule(GroovyTestBase.PORT)
42
43     String Prefix = "CVRCS_"
44     String RbType = "DCRENI_"
45
46     @BeforeClass
47     public static void setUpBeforeClass() {
48         request = FileUtil.readResourceFile("__files/InfrastructureFlows/DeleteCustomE2EService.json")
49     }
50
51     @Before
52     public void init()
53     {
54         MockitoAnnotations.initMocks(this)
55     }
56
57     public DeleteCustomE2EServiceInstanceTest(){
58         super("DeleteCustomE2EServiceInstance")
59     }
60     @Test
61     public void preProcessRequestTest () {
62         ExecutionEntity mex = setupMock()
63         def map = setupMap(mex)
64         initPreProcess(mex)
65         DeleteCustomE2EServiceInstance instance = new DeleteCustomE2EServiceInstance()
66         mex.setVariable("isDebugLogEnabled","true")
67         instance.preProcessRequest(mex);
68
69         verify(mex).getVariable(GroovyTestBase.DBGFLAG)
70
71         Map<String,String> userParams = new HashMap<>()
72         userParams.put("someUserParam","someValue")
73
74         verify(mex).setVariable("prefix", "DELSI_")
75         verify(mex).setVariable("msoRequestId", "mri")
76         verify(mex).setVariable("source", "CCD")
77         verify(mex).setVariable("operationType", "DELETE")
78         verify(mex).setVariable("globalSubscriberId", "38829939920000")
79         verify(mex).setVariable("serviceInputParams",userParams)
80     }
81
82     @Test
83     public void sendSyncResponseTest() {
84         ExecutionEntity mex = setupMock()
85         def map = setupMap(mex)
86         initPreProcess(mex)
87         DeleteCustomE2EServiceInstance instance = new DeleteCustomE2EServiceInstance()
88         instance.sendSyncResponse(mex)
89         verify(mex).setVariable("DeleteCustomE2EServiceInstanceWorkflowResponseSent", "true")
90     }
91
92     @Test
93     public void prepareCompletionRequestTest(){
94         ExecutionEntity mex = setupMock()
95         def map = setupMap(mex)
96         initPreProcess(mex)
97         DeleteCustomE2EServiceInstance instance = new DeleteCustomE2EServiceInstance()
98         instance.prepareCompletionRequest(mex)
99         String msoComplitionRequest = FileUtil.readResourceFile("__files/GenericFlows/MsoCompletionRequest.xml")
100         //verify(mex).setVariable("completionRequest", msoComplitionRequest)
101     }
102
103     @Test
104     public void sendSyncErrorTest(){
105         ExecutionEntity mex = setupMock()
106         def map = setupMap(mex)
107         initPreProcess(mex)
108         DeleteCustomE2EServiceInstance instance = new DeleteCustomE2EServiceInstance()
109         instance.sendSyncError(mex)
110
111     }
112
113     @Test
114     public void prepareFalloutRequest(){
115         ExecutionEntity mex = setupMock()
116         def map = setupMap(mex)
117         initPreProcess(mex)
118         DeleteCustomE2EServiceInstance instance = new DeleteCustomE2EServiceInstance()
119         instance.prepareFalloutRequest(mex)
120         String requestInfo =
121                 """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
122                                         <request-id>null</request-id>
123                                         <action>DELETE</action>
124                                         <source>null</source>
125                                    </request-info>"""
126         //verify(mex).setVariable("falloutRequest", requestInfo)
127     }
128
129     @Test
130     public void processJavaExceptionTest(){
131         ExecutionEntity mex = setupMock()
132         def map = setupMap(mex)
133         initPreProcess(mex)
134         DeleteCustomE2EServiceInstance instance = new DeleteCustomE2EServiceInstance()
135         instance.processJavaException()
136     }
137
138
139     private void initPreProcess(ExecutionEntity mex) {
140         when(mex.getVariable(GroovyTestBase.DBGFLAG)).thenReturn("true")
141         when(mex.getVariable("bpmnRequest")).thenReturn(request)
142         when(mex.getVariable("mso-request-id")).thenReturn("mri")
143         when(mex.getVariable("serviceType")).thenReturn("VoLTE")
144         when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
145         when(mex.getVariable("requestAction")).thenReturn("ra")
146         when(mex.getVariable("operationId")).thenReturn("59960003992")
147     }
148 }