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