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.mockito.Mockito
27 import org.onap.aai.domain.yang.v19.AllottedResource
28 import org.onap.aai.domain.yang.v19.ServiceInstance
29 import org.onap.aai.domain.yang.v19.SliceProfile
30 import org.onap.aai.domain.yang.v19.SliceProfiles
31 import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel
32 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri
33 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder
35 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types
36 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
38 import static org.junit.Assert.assertNotNull
39 import static org.junit.Assert.assertTrue
40 import static org.mockito.Mockito.*
42 class DoModifyCoreNSSITest extends MsoGroovyTest {
45 void init() throws IOException {
46 super.init("DoModifyCoreNSSITest")
51 void testCalculateSNSSAISliceProfileInstanceHasToBeDeleted() {
53 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
55 when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("false")
57 String theSNSSAI = "theS-NSSAI"
59 currentNSSI.put("S-NSSAI", theSNSSAI)
61 List<SliceProfile> associatedProfiles = new ArrayList<>()
62 SliceProfile sliceProfile1 = new SliceProfile()
63 sliceProfile1.setSNssai("snssai1")
65 SliceProfile sliceProfile2 = new SliceProfile()
66 sliceProfile2.setSNssai(theSNSSAI)
68 SliceProfile sliceProfile3 = new SliceProfile()
69 sliceProfile3.setSNssai("snssai2")
71 associatedProfiles.add(sliceProfile1)
72 associatedProfiles.add(sliceProfile2)
73 associatedProfiles.add(sliceProfile3)
75 int sizeBefore = associatedProfiles.size()
77 currentNSSI.put("associatedProfiles", associatedProfiles)
79 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
80 obj.calculateSNSSAI(mockExecution)
82 List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
83 SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")
85 assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore - 1)))
86 assertNotNull("Slice Profile which contains given S-NSSAI not found", sliceProfileContainsSNSSAI)
87 assertTrue("Wrong Slice Profile", sliceProfileContainsSNSSAI.getSNssai().equals(theSNSSAI))
92 void testCalculateSNSSAISliceProfileInstanceHasToBeCreated() {
94 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
96 when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("true")
98 String theSNSSAI = "theS-NSSAI"
100 currentNSSI.put("S-NSSAI", theSNSSAI)
102 List<SliceProfile> associatedProfiles = new ArrayList<>()
103 SliceProfile sliceProfile1 = new SliceProfile()
104 sliceProfile1.setSNssai("snssai1")
106 SliceProfile sliceProfile2 = new SliceProfile()
107 sliceProfile2.setSNssai("snssai2")
109 associatedProfiles.add(sliceProfile1)
110 associatedProfiles.add(sliceProfile2)
112 int sizeBefore = associatedProfiles.size()
114 currentNSSI.put("associatedProfiles", associatedProfiles)
116 DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
117 obj.calculateSNSSAI(mockExecution)
119 List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
121 assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore + 1)))
127 void testCreateSliceProfileInstance() {
128 def currentNSSI = [:]
130 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
132 String sliceProfileId = "sliceProfileId"
134 currentNSSI.put("sliceProfile", "{\"sliceProfileId\":\"slice-profile-id\",\"snssaiList\":[\"S-NSSAI\"],\"expDataRateUL\":\"12\",\"expDataRateDL\":\"5\"," +
135 "\"activityFactor\":\"2\",\"resourceSharingLevel\":\"resource-sharing-level\",\"uEMobilityLevel\":\"ue-mobility-level\",\"coverageAreaTAList\":\"coverage-area-ta-list\"," +
136 "\"maxNumberofUEs\":\"10000\",\"latency\":\"7\"}")
137 currentNSSI.put("sliceProfileId", sliceProfileId)
139 List<String> snssais = new ArrayList<>()
140 snssais.add("s-nssai")
141 currentNSSI.put("S-NSSAIs", snssais)
143 DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
144 when(spy.getAAIClient()).thenReturn(client)
146 String globalSubscriberId = "globalSubscriberId"
147 String subscriptionServiceType = "subscription-service-type"
148 String nssiId = "nssiId"
150 when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId)
151 when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType)
153 currentNSSI.put("nssiId", nssiId)
155 ServiceInstance sliceProfileInstance = new ServiceInstance()
156 sliceProfileInstance.setServiceInstanceId(UUID.randomUUID().toString())
158 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).
159 serviceInstance(sliceProfileInstance.getServiceInstanceId()))
161 SliceProfile sliceProfile = new SliceProfile()
162 sliceProfile.setProfileId(sliceProfileId)
164 doNothing().when(client).create(uri, sliceProfileInstance)
166 spy.createSliceProfileInstance(mockExecution)
168 assertTrue("Slice Profile Instance Id doesn't exist", (currentNSSI.get("createdSliceProfileInstanceId")) != null)
174 void testAssociateSliceProfileInstanceWithNSSI() {
175 def currentNSSI = [:]
177 when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
179 DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
180 when(spy.getAAIClient()).thenReturn(client)
182 String sliceProfileId = "sliceProfileId"
184 when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId)
186 String nssiId = "5G-999"
187 currentNSSI.put("nssiId", nssiId)
189 String globalSubscriberId = "globalSubscriberId"
190 String subscriptionServiceType = "subscriptionServiceType"
192 String sliceProfileInstanceId = "slice-rpofile-instance-id"
193 currentNSSI.put("createdSliceProfileInstanceId", sliceProfileInstanceId)
195 AllottedResource allottedResource = new AllottedResource()
197 String allottedResourceId = UUID.randomUUID().toString()
199 allottedResource.setId(allottedResourceId)
201 AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId).serviceSubscription(subscriptionServiceType).serviceInstance(sliceProfileInstanceId).allottedResource(allottedResourceId))
202 doNothing().when(client).create(allottedResourceUri, allottedResource)
204 currentNSSI.put("allottedResourceUri", allottedResourceUri)
206 when(mockExecution.getVariable("globalSubscriberId")).thenReturn(globalSubscriberId)
207 when(mockExecution.getVariable("subscriptionServiceType")).thenReturn(subscriptionServiceType)
209 currentNSSI.put("sliceProfileId", sliceProfileId)
211 SliceProfile sliceProfile = new SliceProfile()
212 currentNSSI.put("createdSliceProfile", sliceProfile)
214 AAIResourceUri sliceProfileInstanceUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(sliceProfileInstanceId))
216 AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(nssiId))
218 ServiceInstance sliceProfileInstance = new ServiceInstance()
219 sliceProfileInstance.setServiceInstanceId(sliceProfileInstanceId)
220 Optional<ServiceInstance> sliceProfileInstanceOpt = Optional.of(sliceProfileInstance)
222 when(client.get(ServiceInstance.class, sliceProfileInstanceUri)).thenReturn(sliceProfileInstanceOpt)
223 doNothing().when(client).update(sliceProfileInstanceUri, sliceProfileInstance)
225 ServiceInstance nssi = new ServiceInstance()
226 nssi.setServiceInstanceId(nssiId)
227 nssi.setSliceProfiles(new SliceProfiles())
228 currentNSSI.put("nssi", nssi)
230 doNothing().when(client).connect(nssiUri, sliceProfileInstanceUri, AAIEdgeLabel.USES)
232 spy.associateSliceProfileInstanceWithNSSI(mockExecution)