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