Removed deprecated Matcher imports
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCustomDeleteE2EServiceInstanceTest.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.delegate.BpmnError
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.junit.Before
27 import org.junit.BeforeClass
28 import org.junit.Ignore
29 import org.junit.Rule
30 import org.junit.Test
31 import org.mockito.MockitoAnnotations
32 import org.onap.so.bpmn.infrastructure.scripts.DoCustomDeleteE2EServiceInstance
33 import org.onap.so.bpmn.mock.FileUtil
34 import org.onap.so.bpmn.vcpe.scripts.GroovyTestBase
35
36 import static org.assertj.core.api.Assertions.assertThatThrownBy
37 import static org.mockito.ArgumentMatchers.anyString
38 import static org.mockito.Mockito.verify
39 import static org.mockito.Mockito.when
40 import static org.mockito.Mockito.eq
41
42 class DoCustomDeleteE2EServiceInstanceTest extends GroovyTestBase {
43
44     private static String request
45
46     @Rule
47     public WireMockRule wireMockRule = new WireMockRule(GroovyTestBase.PORT)
48
49     String Prefix = "CVRCS_"
50     String RbType = "DCRENI_"
51
52     @BeforeClass
53     public static void setUpBeforeClass() {
54         request = FileUtil.readResourceFile("__files/InfrastructureFlows/DeleteCustomE2EService.json")
55     }
56
57     @Before
58     public void init()
59     {
60         MockitoAnnotations.initMocks(this)
61     }
62     public DoCustomDeleteE2EServiceInstanceTest(){
63         super("DoCustomDeleteE2EServiceInstance")
64     }
65
66     @Test
67     public void preProcessRequestTest(){
68
69         ExecutionEntity mex = setupMock()
70         def map = setupMap(mex)
71         initPreProcess(mex)
72
73         DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
74         instance.preProcessRequest(mex)
75         verify(mex).setVariable("sdncCallbackUrl", "/mso/sdncadapter/")
76         verify(mex).setVariable("siParamsXml", "")
77     }
78
79     @Test
80     public void postProcessAAIGETSuccessTest(){
81         ExecutionEntity mex = setupMock()
82         def map = setupMap(mex)
83         initPreProcess(mex)
84         when(mex.getVariable("GENGS_SuccessIndicator")).thenReturn(true)
85
86         String aaiGetResponse = FileUtil.readResourceFile("__files/GenericFlows/aaiGetResponse.xml")
87         when(mex.getVariable("GENGS_service")).thenReturn(aaiGetResponse)
88         DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
89         instance.postProcessAAIGET(mex)
90
91         verify(mex).setVariable(eq("serviceRelationShip"), anyString())
92     }
93
94     @Test
95     public void postProcessAAIGETFailureTest(){
96         ExecutionEntity mex = setupMock()
97         def map = setupMap(mex)
98         initPreProcess(mex)
99         when(mex.getVariable("GENGS_FoundIndicator")).thenReturn(false)
100         when(mex.getVariable("GENGS_SuccessIndicator")).thenReturn(false)
101
102         DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
103         assertThatThrownBy { instance.postProcessAAIGET(mex) } isInstanceOf BpmnError.class
104     }
105
106     @Test
107     public void preInitResourcesOperStatusTest(){
108         ExecutionEntity mex = setupMock()
109         def map = setupMap(mex)
110         initPreProcess(mex)
111         when(mex.getVariable("serviceRelationShip")).thenReturn("[{\"resourceInstanceId\":\"3333\",\"resourceType\":\"overlay\"},{\"resourceInstanceId\":\"4444\",\"resourceType\":\"underlay\"},{\"resourceInstanceId\":\"1111\",\"resourceType\":\"vIMS\"},{\"resourceInstanceId\":\"222\",\"resourceType\":\"vEPC\"}]")
112         DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
113         instance.preInitResourcesOperStatus(mex)
114
115         verify(mex).setVariable(eq("CVFMI_initResOperStatusRequest"), anyString())
116     }
117
118     @Test
119     public void preResourceDeleteTest() {
120         ExecutionEntity mex = setupMock()
121         def map = setupMap(mex)
122         initPreProcess(mex)
123         when(mex.getVariable("serviceRelationShip")).thenReturn("[{\"resourceInstanceId\":\"3333\",\"resourceType\":\"overlay\"},{\"resourceInstanceId\":\"4444\",\"resourceType\":\"underlay\"},{\"resourceInstanceId\":\"1111\",\"resourceType\":\"vIMS\"},{\"resourceInstanceId\":\"222\",\"resourceType\":\"vEPC\"}]")
124         DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
125         instance.preResourceDelete(mex,"overlay")
126         verify(mex).setVariable("resourceType", "overlay")
127     }
128
129     @Test
130     public void postProcessSDNCDeleteTest(){
131         ExecutionEntity mex = setupMock()
132         def map = setupMap(mex)
133         initPreProcess(mex)
134         when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn("true")
135         when(mex.getVariable("DDELSI_sdncResponseSuccess")).thenReturn("true")
136         when(mex.getVariable("prefix")).thenReturn("DDELSI_")
137         DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
138         String response = FileUtil.readResourceFile("__files/GenericFlows/SDNCDeleteResponse.xml")
139         String method = "deleteE2E";
140         instance.postProcessSDNCDelete(mex, response, method)
141                 // following method doesn't do anything currently -> nothing to check
142     }
143
144     @Test
145     public void postProcessAAIDELTest() {
146         ExecutionEntity mex = setupMock()
147         def map = setupMap(mex)
148         initPreProcess(mex)
149         when(mex.getVariable("GENDS_SuccessIndicator")).thenReturn("true")
150         DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
151         instance.postProcessAAIDEL(mex)
152     }
153
154     private void initPreProcess(ExecutionEntity mex) {
155         when(mex.getVariable(GroovyTestBase.DBGFLAG)).thenReturn("true")
156         when(mex.getVariable("bpmnRequest")).thenReturn(request)
157         when(mex.getVariable("mso-request-id")).thenReturn("mri")
158         when(mex.getVariable("serviceType")).thenReturn("VoLTE")
159         when(mex.getVariable("serviceInstanceId")).thenReturn("e151059a-d924-4629-845f-264db19e50b4")
160         when(mex.getVariable("requestAction")).thenReturn("ra")
161         when(mex.getVariable("operationId")).thenReturn("59960003992")
162         when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("/mso/sdncadapter/")
163         when(mex.getVariable("GENGS_FoundIndicator")).thenReturn("true")
164         when(mex.getVariable("GENGS_siResourceLink")).thenReturn("/service-subscription/e2eserviceInstance/delete/service-instances/")
165         when(mex.getVariable("globalSubscriberId")).thenReturn("4993921112123")
166         when(mex.getVariable("GENGS_service")).thenReturn("test3434")
167         when(mex.getVariable("mso.adapters.openecomp.db.endpoint")).thenReturn("http://localhost:8080/mso")
168     }
169 }