aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-flows/src/test/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCustomDeleteE2EServiceInstanceTest.groovy
blob: bbbb82b5aa97dc52619b4cb3440cdd9ecbed8502 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.so.bpmn.infrastructure.scripts

import com.github.tomakehurst.wiremock.junit.WireMockRule
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.mockito.MockitoAnnotations
import org.onap.so.bpmn.infrastructure.scripts.DoCustomDeleteE2EServiceInstance
import org.onap.so.bpmn.mock.FileUtil
import org.onap.so.bpmn.vcpe.scripts.GroovyTestBase

import static org.assertj.core.api.Assertions.assertThatThrownBy
import static org.mockito.Matchers.anyString
import static org.mockito.Mockito.verify
import static org.mockito.Mockito.when
import static org.mockito.Mockito.eq

class DoCustomDeleteE2EServiceInstanceTest extends GroovyTestBase {

    private static String request

    @Rule
    public WireMockRule wireMockRule = new WireMockRule(GroovyTestBase.PORT)

    String Prefix = "CVRCS_"
    String RbType = "DCRENI_"

    @BeforeClass
    public static void setUpBeforeClass() {
        request = FileUtil.readResourceFile("__files/InfrastructureFlows/DeleteCustomE2EService.json")
    }

    @Before
    public void init()
    {
        MockitoAnnotations.initMocks(this)
    }
    public DoCustomDeleteE2EServiceInstanceTest(){
        super("DoCustomDeleteE2EServiceInstance")
    }

    @Test
    public void preProcessRequestTest(){

        ExecutionEntity mex = setupMock()
        def map = setupMap(mex)
        initPreProcess(mex)

        DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
        instance.preProcessRequest(mex)
        verify(mex).setVariable("sdncCallbackUrl", "/mso/sdncadapter/")
        verify(mex).setVariable("siParamsXml", "")
    }

    @Test
    public void postProcessAAIGETSuccessTest(){
        ExecutionEntity mex = setupMock()
        def map = setupMap(mex)
        initPreProcess(mex)
        when(mex.getVariable("GENGS_SuccessIndicator")).thenReturn(true)

        String aaiGetResponse = FileUtil.readResourceFile("__files/GenericFlows/aaiGetResponse.xml")
        when(mex.getVariable("GENGS_service")).thenReturn(aaiGetResponse)
        DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
        instance.postProcessAAIGET(mex)

        verify(mex).setVariable(eq("serviceRelationShip"), anyString())
    }

    @Test
    public void postProcessAAIGETFailureTest(){
        ExecutionEntity mex = setupMock()
        def map = setupMap(mex)
        initPreProcess(mex)
        when(mex.getVariable("GENGS_FoundIndicator")).thenReturn(false)
        when(mex.getVariable("GENGS_SuccessIndicator")).thenReturn(false)

        DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
        assertThatThrownBy { instance.postProcessAAIGET(mex) } isInstanceOf BpmnError.class
    }

    @Test
    public void preInitResourcesOperStatusTest(){
        ExecutionEntity mex = setupMock()
        def map = setupMap(mex)
        initPreProcess(mex)
        when(mex.getVariable("serviceRelationShip")).thenReturn("[{\"resourceInstanceId\":\"3333\",\"resourceType\":\"overlay\"},{\"resourceInstanceId\":\"4444\",\"resourceType\":\"underlay\"},{\"resourceInstanceId\":\"1111\",\"resourceType\":\"vIMS\"},{\"resourceInstanceId\":\"222\",\"resourceType\":\"vEPC\"}]")
        DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
        instance.preInitResourcesOperStatus(mex)

        verify(mex).setVariable(eq("CVFMI_initResOperStatusRequest"), anyString())
    }

    @Test
    public void preResourceDeleteTest() {
        ExecutionEntity mex = setupMock()
        def map = setupMap(mex)
        initPreProcess(mex)
        when(mex.getVariable("serviceRelationShip")).thenReturn("[{\"resourceInstanceId\":\"3333\",\"resourceType\":\"overlay\"},{\"resourceInstanceId\":\"4444\",\"resourceType\":\"underlay\"},{\"resourceInstanceId\":\"1111\",\"resourceType\":\"vIMS\"},{\"resourceInstanceId\":\"222\",\"resourceType\":\"vEPC\"}]")
        DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
        instance.preResourceDelete(mex,"overlay")
        verify(mex).setVariable("resourceType", "overlay")
    }

    @Test
    public void postProcessSDNCDeleteTest(){
        ExecutionEntity mex = setupMock()
        def map = setupMap(mex)
        initPreProcess(mex)
        when(mex.getVariable("SDNCA_SuccessIndicator")).thenReturn("true")
        when(mex.getVariable("DDELSI_sdncResponseSuccess")).thenReturn("true")
        when(mex.getVariable("prefix")).thenReturn("DDELSI_")
        DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
        String response = FileUtil.readResourceFile("__files/GenericFlows/SDNCDeleteResponse.xml")
        String method = "deleteE2E";
        instance.postProcessSDNCDelete(mex, response, method)
		// following method doesn't do anything currently -> nothing to check
    }

    @Test
    public void postProcessAAIDELTest() {
        ExecutionEntity mex = setupMock()
        def map = setupMap(mex)
        initPreProcess(mex)
        when(mex.getVariable("GENDS_SuccessIndicator")).thenReturn("true")
        DoCustomDeleteE2EServiceInstance instance = new DoCustomDeleteE2EServiceInstance()
        instance.postProcessAAIDEL(mex)
    }

    private void initPreProcess(ExecutionEntity mex) {
        when(mex.getVariable(GroovyTestBase.DBGFLAG)).thenReturn("true")
        when(mex.getVariable("bpmnRequest")).thenReturn(request)
        when(mex.getVariable("mso-request-id")).thenReturn("mri")
        when(mex.getVariable("serviceType")).thenReturn("VoLTE")
        when(mex.getVariable("serviceInstanceId")).thenReturn("e151059a-d924-4629-845f-264db19e50b4")
        when(mex.getVariable("requestAction")).thenReturn("ra")
        when(mex.getVariable("operationId")).thenReturn("59960003992")
        when(mex.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("/mso/sdncadapter/")
        when(mex.getVariable("GENGS_FoundIndicator")).thenReturn("true")
        when(mex.getVariable("GENGS_siResourceLink")).thenReturn("/service-subscription/e2eserviceInstance/delete/service-instances/")
        when(mex.getVariable("globalSubscriberId")).thenReturn("4993921112123")
        when(mex.getVariable("GENGS_service")).thenReturn("test3434")
        when(mex.getVariable("mso.adapters.openecomp.db.endpoint")).thenReturn("http://localhost:8080/mso")
    }
}