a3c2b46fe6f47c4f1b433f3aac60249d980bd549
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.scripts
22
23
24 import org.junit.Before
25 import org.junit.Test
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
34
35 import static org.junit.Assert.assertNotNull
36 import static org.junit.Assert.assertTrue
37 import static org.mockito.Mockito.*
38
39 class DoModifyCoreNSSITest extends MsoGroovyTest  {
40
41     @Before
42     void init() throws IOException {
43         super.init("DoModifyCoreNSSITest")
44     }
45
46
47     @Test
48     void testGetNSSIAssociatedProfiles() {
49         def currentNSSI = [:]
50         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
51
52         ServiceInstance nssi = new ServiceInstance()
53         nssi.setServiceInstanceId("5G-999")
54
55         SliceProfiles sliceProfiles = new SliceProfiles()
56
57         List<SliceProfile> slProfiles = sliceProfiles.getSliceProfile()
58         slProfiles.add(new SliceProfile())
59         slProfiles.add(new SliceProfile())
60
61         nssi.setSliceProfiles(sliceProfiles)
62         currentNSSI.put("nssi", nssi)
63
64         DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
65         obj.getNSSIAssociatedProfiles(mockExecution)
66
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))
69     }
70
71
72     @Test
73     void testCalculateSNSSAISliceProfileInstanceHasToBeDeleted() {
74         def currentNSSI = [:]
75         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
76
77         when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("false")
78
79         String theSNSSAI = "theS-NSSAI"
80
81         currentNSSI.put("S-NSSAI", theSNSSAI)
82
83         List<SliceProfile> associatedProfiles = new ArrayList<>()
84         SliceProfile sliceProfile1 = new SliceProfile()
85         sliceProfile1.setSNssai("snssai1")
86
87         SliceProfile sliceProfile2 = new SliceProfile()
88         sliceProfile2.setSNssai(theSNSSAI)
89
90         SliceProfile sliceProfile3 = new SliceProfile()
91         sliceProfile3.setSNssai("snssai2")
92
93         associatedProfiles.add(sliceProfile1)
94         associatedProfiles.add(sliceProfile2)
95         associatedProfiles.add(sliceProfile3)
96
97         int sizeBefore = associatedProfiles.size()
98
99         currentNSSI.put("associatedProfiles", associatedProfiles)
100
101         DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
102         obj.calculateSNSSAI(mockExecution)
103
104         List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
105         SliceProfile sliceProfileContainsSNSSAI = (SliceProfile)currentNSSI.get("sliceProfileS-NSSAI")
106
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))
110     }
111
112
113     @Test
114     void testCalculateSNSSAISliceProfileInstanceHasToBeCreated() {
115         def currentNSSI = [:]
116         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
117
118         when(mockExecution.getVariable("isCreateSliceProfileInstance")).thenReturn("true")
119
120         String theSNSSAI = "theS-NSSAI"
121
122         currentNSSI.put("S-NSSAI", theSNSSAI)
123
124         List<SliceProfile> associatedProfiles = new ArrayList<>()
125         SliceProfile sliceProfile1 = new SliceProfile()
126         sliceProfile1.setSNssai("snssai1")
127
128         SliceProfile sliceProfile2 = new SliceProfile()
129         sliceProfile2.setSNssai("snssai2")
130
131         associatedProfiles.add(sliceProfile1)
132         associatedProfiles.add(sliceProfile2)
133
134         int sizeBefore = associatedProfiles.size()
135
136         currentNSSI.put("associatedProfiles", associatedProfiles)
137
138         DoModifyCoreNSSI obj = new DoModifyCoreNSSI()
139         obj.calculateSNSSAI(mockExecution)
140
141         List<SliceProfile> snssais = (List<SliceProfile>)currentNSSI.get("S-NSSAIs")
142
143         assertTrue("Either snssais doesn't exist or size is incorrect", (snssais != null && snssais.size() == (sizeBefore + 1)))
144
145     }
146
147
148     @Test
149     void testCreateSliceProfileInstance() {
150         def currentNSSI = [:]
151
152         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
153
154         String sliceProfileId = "sliceProfileId"
155
156         when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId)
157
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)
163
164         when(mockExecution.getVariable("sliceProfileCn")).thenReturn(sliceProfileMap)
165
166
167         Map<String, Object> serviceProfileMap = new HashMap<>()
168         when(mockExecution.getVariable("serviceProfile")).thenReturn(serviceProfileMap)
169
170
171         DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
172         when(spy.getAAIClient()).thenReturn(client)
173
174         String globalSubscriberId = "globalSubscriberId"
175         String serviceType = "serviceType"
176         String nssiId = "nssiId"
177
178         currentNSSI.put("globalSubscriberId", globalSubscriberId)
179         currentNSSI.put("serviceType", serviceType)
180         currentNSSI.put("nssiId", nssiId)
181         currentNSSI.put("sliceProfileId", sliceProfileId)
182
183         AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileId)
184
185         SliceProfile sliceProfile = new SliceProfile()
186         sliceProfile.setProfileId(sliceProfileId)
187
188         doNothing().when(client).create(uri, sliceProfile)
189
190         spy.createSliceProfileInstance(mockExecution)
191
192         assertNotNull("Slice Profile doesn't exist", currentNSSI.get("createdSliceProfile"))
193         assertTrue("Unexpected Slice Profile Id", ((SliceProfile)currentNSSI.get("createdSliceProfile")).getProfileId().equals(sliceProfile.getProfileId()))
194     }
195
196
197     @Test
198     void testAssociateSliceProfileInstanceWithNSSI() {
199         def currentNSSI = [:]
200
201         when(mockExecution.getVariable("currentNSSI")).thenReturn(currentNSSI)
202
203         DoModifyCoreNSSI spy = spy(DoModifyCoreNSSI.class)
204         when(spy.getAAIClient()).thenReturn(client)
205
206         String sliceProfileId = "sliceProfileId"
207
208         when(mockExecution.getVariable("sliceProfileID")).thenReturn(sliceProfileId)
209
210         String nssiId = "5G-999"
211         currentNSSI.put("nssiId", nssiId)
212
213         String globalSubscriberId = "globalSubscriberId"
214         String serviceType = "serviceType"
215
216         AAIResourceUri nssiUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, nssiId)
217         AAIResourceUri sliceProfileUri = AAIUriFactory.createResourceUri(AAIObjectType.SLICE_PROFILE, globalSubscriberId, serviceType, nssiId, sliceProfileId)
218
219         currentNSSI.put("globalSubscriberId", globalSubscriberId)
220         currentNSSI.put("serviceType", serviceType)
221         currentNSSI.put("sliceProfileId", sliceProfileId)
222
223         SliceProfile sliceProfile = new SliceProfile()
224         currentNSSI.put("createdSliceProfile", sliceProfile)
225
226         ServiceInstance nssi = new ServiceInstance()
227         nssi.setServiceInstanceId(nssiId)
228         nssi.setSliceProfiles(new SliceProfiles())
229         currentNSSI.put("nssi", nssi)
230
231         int sizeBelore = nssi.getSliceProfiles().getSliceProfile().size()
232
233         doNothing().when(client).update(nssiUri, nssi)
234         doNothing().when(client).connect(sliceProfileUri, nssiUri, AAIEdgeLabel.BELONGS_TO)
235
236         spy.associateSliceProfileInstanceWithNSSI(mockExecution)
237
238         assertTrue("Wrong number of associated slice profiles", ((ServiceInstance)currentNSSI.get("nssi")).getSliceProfiles().getSliceProfile().size() == (sizeBelore + 1))
239     }
240
241
242 }