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.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
35 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
37 import static org.junit.Assert.assertNotNull
38 import static org.junit.Assert.assertTrue
39 import static org.mockito.Mockito.*
41 class DoModifyCoreNSSITest extends MsoGroovyTest {
44 void init() throws IOException {
45 super.init("DoModifyCoreNSSITest")
50 void testGetNSSIAssociatedProfiles() {
52 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
54 ServiceInstance nssi = new ServiceInstance()
55 nssi.setServiceInstanceId("5G-999")
57 SliceProfiles sliceProfiles = new SliceProfiles()
59 List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
60 slProfiles.add(new SliceProfile())
61 slProfiles.add(new SliceProfile())
63 nssi.setSliceProfiles(sliceProfiles)
64 currentNSSI.put("nssi", nssi)
66 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
67 obj.getNSSIAssociatedProfiles(mockExecution)
69 List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
70 assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
75 void testCalculateSNSSAISliceProfileInstanceHasToBeDeleted() {
77 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
79 when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("false")
81 String theSNSSAI = "theS-NSSAI"
83 currentNSSI.put("S-NSSAI", theSNSSAI)
85 List<SliceProfile> associatedProfiles = new ArrayList<>()
86 SliceProfile sliceProfile1 = new SliceProfile()
87 sliceProfile1.setSNssai("snssai1")
89 SliceProfile sliceProfile2 = new SliceProfile()
90 sliceProfile2.setSNssai(theSNSSAI)
92 SliceProfile sliceProfile3 = new SliceProfile()
93 sliceProfile3.setSNssai("snssai2")
95 associatedProfiles.add(sliceProfile1)
96 associatedProfiles.add(sliceProfile2)
97 associatedProfiles.add(sliceProfile3)
99 int sizeBefore = associatedProfiles.size()
101 currentNSSI.put("associatedProfiles", associatedProfiles)
103 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
104 obj.calculateSNSSAI(mockExecution)
106 List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
107 SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")
109 assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
110 assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
111 assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
116 void testCalculateSNSSAISliceProfileInstanceHasToBeCreated() {
117 def currentNSSI = [:]
118 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
120 when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("true")
122 String theSNSSAI = "theS-NSSAI"
124 currentNSSI.put("S-NSSAI", theSNSSAI)
126 List<SliceProfile> associatedProfiles = new ArrayList<>()
127 SliceProfile sliceProfile1 = new SliceProfile()
128 sliceProfile1.setSNssai("snssai1")
130 SliceProfile sliceProfile2 = new SliceProfile()
131 sliceProfile2.setSNssai("snssai2")
133 associatedProfiles.add(sliceProfile1)
134 associatedProfiles.add(sliceProfile2)
136 int sizeBefore = associatedProfiles.size()
138 currentNSSI.put("associatedProfiles", associatedProfiles)
140 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
141 obj.calculateSNSSAI(mockExecution)
143 List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
145 assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore + 1)))
151 void testCreateSliceProfileInstance() {
152 def currentNSSI = [:]
154 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
156 String sliceProfileId = "sliceProfileId"
158 when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId)
160 Map<String, Object> sliceProfileMap = new HashMap<>()
161 sliceProfileMap.put("expDataRateUL", "12")
162 sliceProfileMap.put("expDataRateDL", 5)
163 sliceProfileMap.put("activityFactor", 2)
164 sliceProfileMap.put("latency", 10)
166 when(mockExecution.getVariable("sliceProfileCn")).thenReturn(sliceProfileMap)
169 Map<String, Object> serviceProfileMap = new HashMap<>()
170 when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfileMap)
173 DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
174 when(spy.getAAIClient()).thenReturn(client)
176 String globalSubscriberId = "globalSubscriberId"
177 String serviceType = "serviceType"
178 String nssiId = "nssiId"
180 currentNSSI.put("globalSubscriberId", globalSubscriberId)
181 currentNSSI.put("serviceType", serviceType)
182 currentNSSI.put("nssiId", nssiId)
183 currentNSSI.put("sliceProfileId", sliceProfileId)
185 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(nssiId).sliceProfile(sliceProfileId))
187 SliceProfile sliceProfile = new SliceProfile()
188 sliceProfile.setProfileId(sliceProfileId)
190 doNothing().when(client).create(uri, sliceProfile)
192 spy.createSliceProfileInstance(mockExecution)
194 assertNotNull("Slice Profile doesn't exist", currentNSSI.get("createdSliceProfile"))
195 assertTrue("Unexpected Slice Profile Id", ((SliceProfile)currentNSSI.get("createdSliceProfile")).getProfileId().equals(sliceProfile.getProfileId()))
200 void testAssociateSliceProfileInstanceWithNSSI() {
201 def currentNSSI = [:]
203 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
205 DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
206 when(spy.getAAIClient()).thenReturn(client)
208 String sliceProfileId = "sliceProfileId"
210 when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId)
212 String nssiId = "5G-999"
213 currentNSSI.put("nssiId", nssiId)
215 String globalSubscriberId = "globalSubscriberId"
216 String serviceType = "serviceType"
218 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
219 AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(serviceType).serviceInstance(nssiId).sliceProfile(sliceProfileId))
221 currentNSSI.put("globalSubscriberId", globalSubscriberId)
222 currentNSSI.put("serviceType", serviceType)
223 currentNSSI.put("sliceProfileId", sliceProfileId)
225 SliceProfile sliceProfile = new SliceProfile()
226 currentNSSI.put("createdSliceProfile", sliceProfile)
228 ServiceInstance nssi = new ServiceInstance()
229 nssi.setServiceInstanceId(nssiId)
230 nssi.setSliceProfiles(new SliceProfiles())
231 currentNSSI.put("nssi", nssi)
233 int sizeBelore = nssi.getSliceProfiles().getSliceProfile().size()
235 doNothing().when(client).update(nssiUri, nssi)
236 doNothing().when(client).connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO)
238 spy.associateSliceProfileInstanceWithNSSI(mockExecution)
240 assertTrue("Wrong number of associated slice profiles", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBelore + 1))