2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Telecom Italia
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
24 import org.junit.Before
26 import org.onap.aai.domain.yang.ServiceInstance
27 import org.onap.aai.domain.yang.SliceProfile
28 import org.onap.aai.domain.yang.SliceProfiles
29 import org.onap.aaiclient.client.aai.AAIObjectType
30 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
31 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
32 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
34 import static org.junit.Assert.assertNotNull
35 import static org.junit.Assert.assertTrue
36 import static org.mockito.Mockito.*
38 class DoDeallocateCoreNSSITest extends MsoGroovyTest {
41 void init() throws IOException {
42 super.init("DoDeallocateNSSITest")
47 void testExecuteTerminateNSSIQuery() {
50 currentNSSI.put("nssiId","5G-999")
52 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
54 when(mockExecution.getVariable("mso.oof.endpoint")).thenReturn("http://oof.onap:8088")
55 when(mockExecution.getVariable("mso.oof.auth")).thenReturn("mso.oof.auth")
56 when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
57 when(mockExecution.getVariable("mso-request-id")).thenReturn("mso-request-id")
59 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
60 when(spy.getAAIClient()).thenReturn(client)
62 when(spy.encryptBasicAuth("mso.oof.auth", "mso.msoKey")).thenReturn("auth-value")
64 String authHeaderResponse = "auth-header"
66 /* String authHeaderResponse = "{\n" +
67 " \"errorCode\": \"401\",\n" +
68 " \"errorMessage\": \"Bad request\"\n" +
71 when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
73 String urlString = "http://oof.onap:8088"
75 String httpRequest = "{\n" +
76 " \"type\": \"NSSI\",\n" +
77 " \"NxIId\": \"5G-999\",\n" +
78 " \"requestInfo\": {\n" +
79 " \"transactionId\": \"mso-request-id\",\n" +
80 " \"requestId\": \"mso-request-id\",\n" +
81 " \"sourceId\": \"so\",\n" +
85 boolean terminateResponse = true
87 String oofResponse = "{\n" +
88 " \"requestId\": \"mso-request-id\",\n" +
89 " \"transactionId\": \"mso-request-id\",\n" +
90 " \"statusMessage\": \"\",\n" +
91 " \"requestStatus\": \"accepted\",\n" +
92 " \"terminateResponse\": \"${terminateResponse}\",\n" +
93 " \"reason\": \"\"\n" +
96 String oofCallResponse = oofResponse
98 /* String oofCallResponse = "{\n" +
99 " \"errorCode\": \"401\",\n" +
100 " \"errorMessage\": \"Exception during the call\"\n" +
103 when(spy.callOOF(urlString, "auth-header", httpRequest)).thenReturn(oofCallResponse)
105 spy.executeTerminateNSSIQuery(mockExecution)
107 verify(mockExecution).setVariable("isTerminateNSSI", terminateResponse)
113 void testDeleteServiceOrder() {
114 def currentNSSI = [:]
115 currentNSSI.put("nssiId","5G-999")
117 ServiceInstance networkServiceInstance = new ServiceInstance()
118 networkServiceInstance.setServiceInstanceId("NS-777")
119 networkServiceInstance.setServiceRole("Network Service")
121 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
123 currentNSSI.put("networkServiceInstance", networkServiceInstance)
125 when(mockExecution.getVariable("nbi.endpoint.url")).thenReturn("http://nbi.onap:8088")
126 when(mockExecution.getVariable("mso.msoKey")).thenReturn("mso.msoKey")
127 when(mockExecution.getVariable("mso.infra.endpoint.auth")).thenReturn("mso.infra.endpoint.auth")
129 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
130 when(spy.getAAIClient()).thenReturn(client)
132 when(spy.encryptBasicAuth("mso.infra.endpoint.auth", "mso.msoKey")).thenReturn("auth-value")
134 String authHeaderResponse = "auth-header"
136 /* String authHeaderResponse = "{\n" +
137 " \"errorCode\": \"401\",\n" +
138 " \"errorMessage\": \"Bad request\"\n" +
141 when(spy.getAuthHeader(mockExecution, "auth-value", "mso.msoKey")).thenReturn(authHeaderResponse)
143 String urlString = String.format("http://nbi.onap:8088/api/v4/serviceOrder/%s", networkServiceInstance.getServiceInstanceId())
145 String callDeleteServiceOrderResponse = "deleted"
147 when(spy.callDeleteServiceOrder(mockExecution, urlString, "auth-header")).thenReturn(callDeleteServiceOrderResponse)
149 spy.deleteServiceOrder(mockExecution)
154 void testGetNSSIAssociatedProfiles() {
155 def currentNSSI = [:]
156 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
158 ServiceInstance nssi = new ServiceInstance()
159 nssi.setServiceInstanceId("5G-999")
161 SliceProfiles sliceProfiles = new SliceProfiles()
163 List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
164 slProfiles.add(new SliceProfile())
165 slProfiles.add(new SliceProfile())
167 nssi.setSliceProfiles(sliceProfiles)
168 currentNSSI.put("nssi", nssi)
170 DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI()
171 obj.getNSSIAssociatedProfiles(mockExecution)
173 List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
174 assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
179 void testCalculateSNSSAI() {
180 def currentNSSI = [:]
181 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
183 String theSNSSAI = "theS-NSSAI"
185 currentNSSI.put("S-NSSAI", theSNSSAI)
187 List<SliceProfile> associatedProfiles = new ArrayList<>()
188 SliceProfile sliceProfile1 = new SliceProfile()
189 sliceProfile1.setSNssai("snssai1")
191 SliceProfile sliceProfile2 = new SliceProfile()
192 sliceProfile2.setSNssai(theSNSSAI)
194 SliceProfile sliceProfile3 = new SliceProfile()
195 sliceProfile3.setSNssai("snssai3")
197 associatedProfiles.add(sliceProfile1)
198 associatedProfiles.add(sliceProfile2)
199 associatedProfiles.add(sliceProfile3)
201 int sizeBefore = associatedProfiles.size()
203 currentNSSI.put("associatedProfiles", associatedProfiles)
205 DoDeallocateCoreNSSI obj = new DoDeallocateCoreNSSI()
206 obj.calculateSNSSAI(mockExecution)
208 List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
209 SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")
211 assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
212 assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
213 assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
218 void testRemoveNSSIAssociationWithNSI() {
219 def currentNSSI = [:]
221 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
223 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
225 when(spy.getAAIClient()).thenReturn(client)
227 String nssiId = "5G-999"
228 String nsiId = "5G-99"
229 currentNSSI.put("nssiId", nssiId)
230 currentNSSI.put("nsiId", nsiId)
232 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
233 AAIResourceUri nsiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nsiId)
235 doNothing().when(client).disconnect(nssiUri, nsiUri)
237 spy.removeNSSIAssociationWithNSI(mockExecution)
243 void testDeleteNSSIServiceInstance() {
244 def currentNSSI = [:]
246 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
248 String nssiId = "5G-999"
250 currentNSSI.put("nssiId", nssiId)
252 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
254 DoDeallocateCoreNSSI spy = spy(DoDeallocateCoreNSSI.class)
256 when(spy.getAAIClient()).thenReturn(client)
258 doNothing().when(client).delete(nssiUri)
260 spy.deleteNSSIServiceInstance(mockExecution)