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
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.junit.Before
26 import org.onap.aai.domain.yang.v19.ServiceInstance
27 import org.onap.aai.domain.yang.v19.SliceProfile
28 import org.onap.aai.domain.yang.v19.SliceProfiles
29 import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
30 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
31 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
32 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
33 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
34 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
36 import static org.junit.Assert.assertNotNull
37 import static org.junit.Assert.assertTrue
38 import static org.mockito.Mockito.*
40 class DoModifyCoreNSSITest extends MsoGroovyTest {
43 void init() throws IOException {
44 super.init("DoModifyCoreNSSITest")
49 void testGetNSSIAssociatedProfiles() {
51 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
53 ServiceInstance nssi = new ServiceInstance()
54 nssi.setServiceInstanceId("5G-999")
56 SliceProfiles sliceProfiles = new SliceProfiles()
58 List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
59 slProfiles.add(new SliceProfile())
60 slProfiles.add(new SliceProfile())
62 nssi.setSliceProfiles(sliceProfiles)
63 currentNSSI.put("nssi", nssi)
65 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
66 obj.getNSSIAssociatedProfiles(mockExecution)
68 List<SliceProfile> associatedProfiles = (List<SliceProfile>)currentNSSI.get("associatedProfiles")
69 assertTrue("Either associatedProfiles doesn't exist or size is incorrect", (associatedProfiles != null && associatedProfiles.size() == 2))
74 void testCalculateSNSSAISliceProfileInstanceHasToBeDeleted() {
76 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
78 when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("false")
80 String theSNSSAI = "theS-NSSAI"
82 currentNSSI.put("S-NSSAI", theSNSSAI)
84 List<SliceProfile> associatedProfiles = new ArrayList<>()
85 SliceProfile sliceProfile1 = new SliceProfile()
86 sliceProfile1.setSNssai("snssai1")
88 SliceProfile sliceProfile2 = new SliceProfile()
89 sliceProfile2.setSNssai(theSNSSAI)
91 SliceProfile sliceProfile3 = new SliceProfile()
92 sliceProfile3.setSNssai("snssai2")
94 associatedProfiles.add(sliceProfile1)
95 associatedProfiles.add(sliceProfile2)
96 associatedProfiles.add(sliceProfile3)
98 int sizeBefore = associatedProfiles.size()
100 currentNSSI.put("associatedProfiles", associatedProfiles)
102 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
103 obj.calculateSNSSAI(mockExecution)
105 List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
106 SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")
108 assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
109 assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
110 assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
115 void testCalculateSNSSAISliceProfileInstanceHasToBeCreated() {
116 def currentNSSI = [:]
117 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
119 when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("true")
121 String theSNSSAI = "theS-NSSAI"
123 currentNSSI.put("S-NSSAI", theSNSSAI)
125 List<SliceProfile> associatedProfiles = new ArrayList<>()
126 SliceProfile sliceProfile1 = new SliceProfile()
127 sliceProfile1.setSNssai("snssai1")
129 SliceProfile sliceProfile2 = new SliceProfile()
130 sliceProfile2.setSNssai("snssai2")
132 associatedProfiles.add(sliceProfile1)
133 associatedProfiles.add(sliceProfile2)
135 int sizeBefore = associatedProfiles.size()
137 currentNSSI.put("associatedProfiles", associatedProfiles)
139 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
140 obj.calculateSNSSAI(mockExecution)
142 List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
144 assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore + 1)))
150 void testCreateSliceProfileInstance() {
151 def currentNSSI = [:]
153 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
155 String sliceProfileId = "sliceProfileId"
157 currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"],\"expDataRateUL\":\"12\"}")
158 currentNSSI.put("sliceProfileId", sliceProfileId)
160 DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
161 when(spy.getAAIClient()).thenReturn(client)
163 String globalSubscriberId = "globalSubscriberId"
164 String subscriptionServiceType = "subscription-service-type"
165 String nssiId = "nssiId"
167 when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId)
168 when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType)
170 currentNSSI.put("nssiId", nssiId)
172 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileId))
174 SliceProfile sliceProfile = new SliceProfile()
175 sliceProfile.setProfileId(sliceProfileId)
177 doNothing().when(client).create(uri, sliceProfile)
179 spy.createSliceProfileInstance(mockExecution)
181 assertNotNull("Slice Profile doesn't exist", currentNSSI.get("createdSliceProfile"))
182 assertTrue("Unexpected Slice Profile Id", ((SliceProfile)currentNSSI.get("createdSliceProfile")).getProfileId().equals(sliceProfile.getProfileId()))
187 void testAssociateSliceProfileInstanceWithNSSI() {
188 def currentNSSI = [:]
190 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
192 DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
193 when(spy.getAAIClient()).thenReturn(client)
195 String sliceProfileId = "sliceProfileId"
197 when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId)
199 String nssiId = "5G-999"
200 currentNSSI.put("nssiId", nssiId)
202 String globalSubscriberId = "globalSubscriberId"
203 String subscriptionServiceType = "subscriptionServiceType"
205 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
206 AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(nssiId).sliceProfile(sliceProfileId))
208 when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId)
209 when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType)
211 currentNSSI.put("sliceProfileId", sliceProfileId)
213 SliceProfile sliceProfile = new SliceProfile()
214 currentNSSI.put("createdSliceProfile", sliceProfile)
216 ServiceInstance nssi = new ServiceInstance()
217 nssi.setServiceInstanceId(nssiId)
218 nssi.setSliceProfiles(new SliceProfiles())
219 currentNSSI.put("nssi", nssi)
221 int sizeBelore = nssi.getSliceProfiles().getSliceProfile().size()
223 doNothing().when(client).update(nssiUri, nssi)
224 doNothing().when(client).connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO)
226 spy.associateSliceProfileInstanceWithNSSI(mockExecution)
228 assertTrue("Wrong number of associated slice profiles", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBelore + 1))