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.AAIEdgeLabel
31 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
32 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
33 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
35 import static org.junit.Assert.assertNotNull
36 import static org.junit.Assert.assertTrue
37 import static org.mockito.Mockito.*
39 class DoModifyCoreNSSITest extends MsoGroovyTest {
42 void init() throws IOException {
43 super.init("DoModifyCoreNSSITest")
48 void testGetNSSIAssociatedProfiles() {
50 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
52 ServiceInstance nssi = new ServiceInstance()
53 nssi.setServiceInstanceId("5G-999")
55 SliceProfiles sliceProfiles = new SliceProfiles()
57 List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
58 slProfiles.add(new SliceProfile())
59 slProfiles.add(new SliceProfile())
61 nssi.setSliceProfiles(sliceProfiles)
62 currentNSSI.put("nssi", nssi)
64 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
65 obj.getNSSIAssociatedProfiles(mockExecution)
67 List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
68 assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
73 void testCalculateSNSSAISliceProfileInstanceHasToBeDeleted() {
75 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
77 when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("false")
79 String theSNSSAI = "theS-NSSAI"
81 currentNSSI.put("S-NSSAI", theSNSSAI)
83 List<SliceProfile> associatedProfiles = new ArrayList<>()
84 SliceProfile sliceProfile1 = new SliceProfile()
85 sliceProfile1.setSNssai("snssai1")
87 SliceProfile sliceProfile2 = new SliceProfile()
88 sliceProfile2.setSNssai(theSNSSAI)
90 SliceProfile sliceProfile3 = new SliceProfile()
91 sliceProfile3.setSNssai("snssai2")
93 associatedProfiles.add(sliceProfile1)
94 associatedProfiles.add(sliceProfile2)
95 associatedProfiles.add(sliceProfile3)
97 int sizeBefore = associatedProfiles.size()
99 currentNSSI.put("associatedProfiles", associatedProfiles)
101 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
102 obj.calculateSNSSAI(mockExecution)
104 List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
105 SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")
107 assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
108 assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
109 assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
114 void testCalculateSNSSAISliceProfileInstanceHasToBeCreated() {
115 def currentNSSI = [:]
116 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
118 when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("true")
120 String theSNSSAI = "theS-NSSAI"
122 currentNSSI.put("S-NSSAI", theSNSSAI)
124 List<SliceProfile> associatedProfiles = new ArrayList<>()
125 SliceProfile sliceProfile1 = new SliceProfile()
126 sliceProfile1.setSNssai("snssai1")
128 SliceProfile sliceProfile2 = new SliceProfile()
129 sliceProfile2.setSNssai("snssai2")
131 associatedProfiles.add(sliceProfile1)
132 associatedProfiles.add(sliceProfile2)
134 int sizeBefore = associatedProfiles.size()
136 currentNSSI.put("associatedProfiles", associatedProfiles)
138 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
139 obj.calculateSNSSAI(mockExecution)
141 List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
143 assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore + 1)))
149 void testCreateSliceProfileInstance() {
150 def currentNSSI = [:]
152 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
154 String sliceProfileId = "sliceProfileId"
156 when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId)
158 Map<String, Object> sliceProfileMap = new HashMap<>()
159 sliceProfileMap.put("expDataRateUL", "12")
160 sliceProfileMap.put("expDataRateDL", 5)
161 sliceProfileMap.put("activityFactor", 2)
162 sliceProfileMap.put("latency", 10)
164 when(mockExecution.getVariable("sliceProfileCn")).thenReturn(sliceProfileMap)
167 Map<String, Object> serviceProfileMap = new HashMap<>()
168 when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfileMap)
171 DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
172 when(spy.getAAIClient()).thenReturn(client)
174 String globalSubscriberId = "globalSubscriberId"
175 String serviceType = "serviceType"
176 String nssiId = "nssiId"
178 currentNSSI.put("globalSubscriberId", globalSubscriberId)
179 currentNSSI.put("serviceType", serviceType)
180 currentNSSI.put("nssiId", nssiId)
181 currentNSSI.put("sliceProfileId", sliceProfileId)
183 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileId)
185 SliceProfile sliceProfile = new SliceProfile()
186 sliceProfile.setProfileId(sliceProfileId)
188 doNothing().when(client).create(uri, sliceProfile)
190 spy.createSliceProfileInstance(mockExecution)
192 assertNotNull("Slice Profile doesn't exist", currentNSSI.get("createdSliceProfile"))
193 assertTrue("Unexpected Slice Profile Id", ((SliceProfile)currentNSSI.get("createdSliceProfile")).getProfileId().equals(sliceProfile.getProfileId()))
198 void testAssociateSliceProfileInstanceWithNSSI() {
199 def currentNSSI = [:]
201 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
203 DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
204 when(spy.getAAIClient()).thenReturn(client)
206 String sliceProfileId = "sliceProfileId"
208 when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId)
210 String nssiId = "5G-999"
211 currentNSSI.put("nssiId", nssiId)
213 String globalSubscriberId = "globalSubscriberId"
214 String serviceType = "serviceType"
216 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
217 AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileId)
219 currentNSSI.put("globalSubscriberId", globalSubscriberId)
220 currentNSSI.put("serviceType", serviceType)
221 currentNSSI.put("sliceProfileId", sliceProfileId)
223 SliceProfile sliceProfile = new SliceProfile()
224 currentNSSI.put("createdSliceProfile", sliceProfile)
226 ServiceInstance nssi = new ServiceInstance()
227 nssi.setServiceInstanceId(nssiId)
228 nssi.setSliceProfiles(new SliceProfiles())
229 currentNSSI.put("nssi", nssi)
231 int sizeBelore = nssi.getSliceProfiles().getSliceProfile().size()
233 doNothing().when(client).update(nssiUri, nssi)
234 doNothing().when(client).connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO)
236 spy.associateSliceProfileInstanceWithNSSI(mockExecution)
238 assertTrue("Wrong number of associated slice profiles", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBelore + 1))