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