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