aboutsummaryrefslogtreecommitdiffstats
path: root/ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/services/TestRANSliceConfigServices.java
blob: 70d3eedec7ed19c3b8fecc6d090de65b96198a54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*
 * ============LICENSE_START=======================================================
 * Ran Simulator Controller
 * ================================================================================
 * Copyright (C) 2020-2021 Wipro Limited.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.ransim.rest.api.services;

import static org.junit.Assert.assertEquals;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.ransim.rest.api.models.NSSAIConfig;
import org.onap.ransim.rest.api.services.RANSliceConfigService;
import org.onap.ransim.rest.web.mapper.GNBCUCPModel;
import org.onap.ransim.rest.web.mapper.GNBCUUPModel;
import org.onap.ransim.rest.web.mapper.GNBDUModel;
import org.onap.ransim.rest.web.mapper.NRCellCUModel;
import org.onap.ransim.rest.web.mapper.NRCellDUModel;
import org.onap.ransim.rest.web.mapper.NearRTRICModel;
import org.onap.ransim.rest.web.mapper.RANSliceInfoModel;
import org.springframework.context.annotation.PropertySource;

@RunWith(MockitoJUnitRunner.class)
@PropertySource("classpath:ransim.properties")
public class TestRANSliceConfigServices {

    @Mock
    RANSliceConfigService rANSliceConfigService;

    ObjectMapper objectMapper = new ObjectMapper();

    @Test
    public void testSaveGNBCUCP() {
        String input =
                "{\"gNBCUName\":\"cucpserver1\",\"gNBId\":98763,\"gNBIdLength\":5,\"pLMNId\":\"310-410\",\"nFType\":\"CUCP\",\"nearRTRICId\":11,\"cellCUList\":[{\"cellLocalId\":103594000,\"pLMNInfoList\":[{\"pLMNId\":\"310-410\",\"sNSSAI\":{\"sNSSAI\":\"001-093\",\"status\":\"ACTIVE\",\"configData\":{\"maxNumberOfConns\":3000}}}]}]}";
        GNBCUCPModel gNBCUCPModel = new GNBCUCPModel();
        try {
            gNBCUCPModel = objectMapper.readValue(input, GNBCUCPModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Mockito.doReturn(gNBCUCPModel).when(rANSliceConfigService).saveGNBCUCP(gNBCUCPModel);
        assertEquals(gNBCUCPModel, rANSliceConfigService.saveGNBCUCP(gNBCUCPModel));
    }

    @Test
    public void testFetchGNBCUCPData() {
        String cuCPName = "cucpserver1";
        GNBCUCPModel gNBCUCPModel = new GNBCUCPModel();
        Mockito.doReturn(gNBCUCPModel).when(rANSliceConfigService).fetchGNBCUCPData(cuCPName);
        assertEquals(gNBCUCPModel, rANSliceConfigService.fetchGNBCUCPData(cuCPName));
    }

    @Test
    public void testSaveGNBDU() {
        String input =
                "{\"gNBDUId\":1,\"gNBId\":98763,\"gNBIdLength\":5,\"pLMNId\":\"310-410\",\"gNBDUName\":\"gnduserver1\",\"nFType\":\"DU\",\"nearRTRICId\":11,\"cellDUList\":[{\"cellLocalId\":103593999,\"operationalState\":\"ENABLED\",\"administrativeState\":\"UNLOCKED\",\"cellState\":\"ACTIVE\",\"nRPCI\":12,\"nRTAC\":310,\"resourceType\":\"PRB\",\"pLMNInfoList\":[{\"pLMNId\":\"310-410\",\"sNSSAI\":{\"sNSSAI\":\"001-003\",\"status\":\"ACTIVE\",\"configData\":{\"dLThptPerSlice\":50,\"uLThptPerSlice\":40}}}]}]}";
        GNBDUModel gNBDUModel = new GNBDUModel();
        try {
            gNBDUModel = objectMapper.readValue(input, GNBDUModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Mockito.doReturn(gNBDUModel).when(rANSliceConfigService).saveGNBDU(gNBDUModel);
        assertEquals(gNBDUModel, rANSliceConfigService.saveGNBDU(gNBDUModel));
    }

    @Test
    public void testFetchGNBDUData() {
        int gNBDUId = 1;
        GNBDUModel gNBDUModel = new GNBDUModel();
        Mockito.doReturn(gNBDUModel).when(rANSliceConfigService).fetchGNBDUData(gNBDUId);
        assertEquals(gNBDUModel, rANSliceConfigService.fetchGNBDUData(gNBDUId));
    }

    @Test
    public void testSaveGNBCUUP() {
        String input =
                "{\"gNBCUUPId\":1111,\"gNBId\":98763,\"gNBIdLength\":2,\"resourceType\":\"DRB\",\"nearRTRICId\":11,\"pLMNInfoList\":[{\"pLMNId\":\"310-410\",\"sNSSAI\":{\"sNSSAI\":\"001-003\",\"status\":\"ACTIVE\",\"configData\":{\"maxNumberOfConns\":3000}}}]}";
        GNBCUUPModel gNBCUUPModel = new GNBCUUPModel();
        try {
            gNBCUUPModel = objectMapper.readValue(input, GNBCUUPModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Mockito.doReturn(gNBCUUPModel).when(rANSliceConfigService).saveGNBCUUP(gNBCUUPModel);
        assertEquals(gNBCUUPModel, rANSliceConfigService.saveGNBCUUP(gNBCUUPModel));
    }

    @Test
    public void testFetchGNBCUUPData() {
        Integer gNBCUUPId = 1111;
        String response =
                "{\"gNBCUUPId\":1111,\"gNBId\":98763,\"gNBIdLength\":2,\"resourceType\":\"DRB\",\"nearRTRICId\":11,\"pLMNInfoList\":[{\"pLMNId\":\"310-410\",\"sNSSAI\":{\"sNSSAI\":\"001-003\",\"status\":\"ACTIVE\",\"configData\":{\"maxNumberOfConns\":3000}}}]}";
        GNBCUUPModel gNBCUUPModel = new GNBCUUPModel();
        try {
            gNBCUUPModel = objectMapper.readValue(response, GNBCUUPModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Mockito.doReturn(gNBCUUPModel).when(rANSliceConfigService).fetchGNBCUUPData(gNBCUUPId);
        assertEquals(gNBCUUPModel, rANSliceConfigService.fetchGNBCUUPData(gNBCUUPId));

    }

    @Test
    public void testSaveNearRTRIC() {
        NearRTRICModel nearRTRIC = new NearRTRICModel();
        String input =
                "{\"nearRTRICId\":11,\"gNBId\":98763,\"trackingArea\":101,\"resourceType\":\"NearRTRIC\",\"ranNFNSSIList\":[\"11\",\"22\"],\"pLMNInfoList\":[{\"pLMNId\":\"310-410\",\"sNSSAI\":{\"sNSSAI\":\"001-003\",\"status\":\"ACTIVE\",\"configData\":{\"dLThptPerSlice\":55,\"uLThptPerSlice\":40}}}]}";
        try {
            nearRTRIC = objectMapper.readValue(input, NearRTRICModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Mockito.doReturn(nearRTRIC).when(rANSliceConfigService).saveNearRTRIC(nearRTRIC);
        assertEquals(nearRTRIC, rANSliceConfigService.saveNearRTRIC(nearRTRIC));
    }

    @Test
    public void testFetchNearRTRICData() {
        int nearRTRICId = 11;
        String response =
                "{\"nearRTRICId\":11,\"gNBId\":98763,\"trackingArea\":101,\"resourceType\":\"NearRTRIC\",\"ranNFNSSIList\":[\"11\",\"22\"],\"pLMNInfoList\":[{\"pLMNId\":\"310-410\",\"sNSSAI\":{\"sNSSAI\":\"001-003\",\"status\":\"ACTIVE\",\"configData\":{\"dLThptPerSlice\":55,\"uLThptPerSlice\":40}}}]}";
        NearRTRICModel nearRTRIC = new NearRTRICModel();
        try {
            nearRTRIC = objectMapper.readValue(response, NearRTRICModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Mockito.doReturn(nearRTRIC).when(rANSliceConfigService).fetchNearRTRICData(nearRTRICId);
        assertEquals(nearRTRIC, rANSliceConfigService.fetchNearRTRICData(nearRTRICId));
    }

    @Test
    public void testFindRICsInTA() {
        int trackingArea = 101;
        List<NearRTRICModel> ricsList = new ArrayList<>();
        String ricModel =
                "{\"nearRTRICId\":11,\"gNBId\":98763,\"trackingArea\":101,\"resourceType\":\"NearRTRIC\",\"ranNFNSSIList\":[\"11\",\"22\"],\"pLMNInfoList\":[{\"pLMNId\":\"310-410\",\"sNSSAI\":{\"sNSSAI\":\"001-003\",\"status\":\"ACTIVE\",\"configData\":{\"dLThptPerSlice\":55,\"uLThptPerSlice\":40}}}]}";
        NearRTRICModel nearRTRIC = new NearRTRICModel();
        try {
            nearRTRIC = objectMapper.readValue(ricModel, NearRTRICModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ricsList.add(nearRTRIC);
        Mockito.doReturn(ricsList).when(rANSliceConfigService).findRICsInTA(Mockito.anyInt());
        assertEquals(ricsList, rANSliceConfigService.findRICsInTA(trackingArea));
    }

    @Test
    public void testfindNearRTRICofCells() {
        List<Integer> cellIds = new ArrayList<Integer>();
        cellIds.add(23456);
        cellIds.add(45785);
        List<NearRTRICModel> ricsList = new ArrayList<>();
        String ricModel =
                "{\"nearRTRICId\":11,\"gNBId\":98763,\"trackingArea\":101,\"resourceType\":\"NearRTRIC\",\"ranNFNSSIList\":[\"11\",\"22\"],\"pLMNInfoList\":[{\"pLMNId\":\"310-410\",\"sNSSAI\":{\"sNSSAI\":\"001-003\",\"status\":\"ACTIVE\",\"configData\":{\"dLThptPerSlice\":55,\"uLThptPerSlice\":40}}}]}";
        NearRTRICModel nearRTRIC = new NearRTRICModel();
        try {
            nearRTRIC = objectMapper.readValue(ricModel, NearRTRICModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ricsList.add(nearRTRIC);
        Mockito.doReturn(ricsList).when(rANSliceConfigService).findNearRTRICofCells(Mockito.anyList());
        assertEquals(ricsList, rANSliceConfigService.findNearRTRICofCells(cellIds));
    }

    @Test
    public void testUpdateRANInventory() {
        String input =
                "{\"ranNFNSSIId\":\"11\",\"ranNSSIList\":[\"ran3\"],\"nSSAIList\":[\"001-003\",\"001-001\"],\"sliceProfilesList\":[{\"sliceProfileId\":12,\"dLThptPerSlice\":1,\"uLThptPerSlice\":2,\"maxNumberofConns\":3,\"sNSSAI\":\"001-003\"}],\"trackingAreaList\":\"Chennai\",\"subnetStatus\":\"ACTIVE\",\"nsstId\":\"NSSTID1\",\"sliceType\":\"eMBB\",\"isShareable\":\"true\"}";
        RANSliceInfoModel inventorynfo = new RANSliceInfoModel();
        try {
            inventorynfo = objectMapper.readValue(input, RANSliceInfoModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Mockito.doReturn(inventorynfo).when(rANSliceConfigService).updateRANInventory(Mockito.anyObject());
        assertEquals(inventorynfo, rANSliceConfigService.updateRANInventory(inventorynfo));
    }

    @Test
    public void testFetchRANSlice() {
        String ranNFNSSIId = "11";
        String input =
                "{\"ranNFNSSIId\":\"11\",\"ranNSSIList\":[\"ran3\"],\"nSSAIList\":[\"001-003\",\"001-001\"],\"sliceProfilesList\":[{\"sliceProfileId\":12,\"dLThptPerSlice\":1,\"uLThptPerSlice\":2,\"maxNumberofConns\":3,\"sNSSAI\":\"001-003\"}],\"trackingAreaList\":\"Chennai\",\"subnetStatus\":\"ACTIVE\",\"nsstId\":\"NSSTID1\",\"sliceType\":\"eMBB\",\"isShareable\":\"true\"}";
        RANSliceInfoModel inventorynfo = new RANSliceInfoModel();
        try {
            inventorynfo = objectMapper.readValue(input, RANSliceInfoModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Mockito.doReturn(inventorynfo).when(rANSliceConfigService).fetchRANSlice(ranNFNSSIId);
        assertEquals(inventorynfo, rANSliceConfigService.fetchRANSlice(ranNFNSSIId));
    }

    @Test
    public void testFetchCellsofTA() {
        int trackingArea = 202;
        List<String> cellIds = new ArrayList<String>();
        cellIds.add("23456");
        cellIds.add("45785");
        Mockito.doReturn(cellIds).when(rANSliceConfigService).fetchCellsofTA(Mockito.anyInt());
        assertEquals(cellIds, rANSliceConfigService.fetchCellsofTA(trackingArea));
    }

    @Test
    public void testFetchCUCellsofRIC() {
        Integer nearRTRICId = 1;
        List<NRCellCUModel> cellCUList = new ArrayList<>();
        Mockito.doReturn(cellCUList).when(rANSliceConfigService).fetchCUCellsofRIC(Mockito.anyInt());
        assertEquals(cellCUList, rANSliceConfigService.fetchCUCellsofRIC(nearRTRICId));;
    }

    @Test
    public void testFetchDUCellsofRIC() {
        String sNSSAI = "001-00001";
        Map<Integer, List<NRCellDUModel>> cellsMap = new HashMap<Integer, List<NRCellDUModel>>();
        Mockito.doReturn(cellsMap).when(rANSliceConfigService).fetchDUCellsofRIC(Mockito.anyString());
        assertEquals(cellsMap, rANSliceConfigService.fetchDUCellsofRIC(sNSSAI));;
    }

    @Test
    public void testFindNearRTRICByNSSI() {
        String ranNFNSSIID = "11";
        List<NearRTRICModel> ricsList = new ArrayList<>();
        String ricModel =
                "{\"nearRTRICId\":11,\"gNBId\":98763,\"trackingArea\":101,\"resourceType\":\"NearRTRIC\",\"ranNFNSSIList\":[\"11\",\"22\"],\"pLMNInfoList\":[{\"pLMNId\":\"310-410\",\"sNSSAI\":{\"sNSSAI\":\"001-003\",\"status\":\"ACTIVE\",\"configData\":{\"dLThptPerSlice\":55,\"uLThptPerSlice\":40}}}]}";
        NearRTRICModel nearRTRIC = new NearRTRICModel();
        try {
            nearRTRIC = objectMapper.readValue(ricModel, NearRTRICModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ricsList.add(nearRTRIC);
        Mockito.doReturn(ricsList).when(rANSliceConfigService).findNearRTRICByNSSI(Mockito.anyString());
        assertEquals(ricsList, rANSliceConfigService.findNearRTRICByNSSI(ranNFNSSIID));
    }

    @Test
    public void testFindRICsByNSSAI() {
        String sNSSAI = "001-00001";
        List<NearRTRICModel> ricsList = new ArrayList<>();
        String ricModel =
                "{\"nearRTRICId\":11,\"gNBId\":98763,\"trackingArea\":101,\"resourceType\":\"NearRTRIC\",\"ranNFNSSIList\":[\"11\",\"22\"],\"pLMNInfoList\":[{\"pLMNId\":\"310-410\",\"sNSSAI\":{\"sNSSAI\":\"001-003\",\"status\":\"ACTIVE\",\"configData\":{\"dLThptPerSlice\":55,\"uLThptPerSlice\":40}}}]}";
        NearRTRICModel nearRTRIC = new NearRTRICModel();
        try {
            nearRTRIC = objectMapper.readValue(ricModel, NearRTRICModel.class);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ricsList.add(nearRTRIC);
        Mockito.doReturn(ricsList).when(rANSliceConfigService).findRICsByNSSAI(Mockito.anyString());
        assertEquals(ricsList, rANSliceConfigService.findRICsByNSSAI(sNSSAI));
    }

    @Test
    public void testFindSliceProfileconfig() {
        String sNSSAI = "001-00001";
        Map<String, Integer> configDetails = new HashMap<String, Integer>();
        configDetails.put("dLThptPerSlice", 40);
        configDetails.put("uLThptPerSlice", 50);
        Mockito.doReturn(configDetails).when(rANSliceConfigService).findSliceProfileconfig(Mockito.anyString());
        assertEquals(configDetails, rANSliceConfigService.findSliceProfileconfig(sNSSAI));
    }

    @Test
    public void testFindSliceeconfig() {
        String sNSSAI = "001-00001";
        Map<Integer, NSSAIConfig> configMap = new HashMap<Integer, NSSAIConfig>();
        Mockito.doReturn(configMap).when(rANSliceConfigService).findSliceConfig(Mockito.anyString());
        assertEquals(configMap, rANSliceConfigService.findSliceConfig(sNSSAI));
    }

    @Test
    public void testFindDUsofSNssai() {
        String sNSSAI = "001-00001";
        List<GNBDUModel> duModels = new ArrayList<GNBDUModel>();
        Mockito.doReturn(duModels).when(rANSliceConfigService).findDUsofSNssai(Mockito.anyString());
        assertEquals(duModels, rANSliceConfigService.findDUsofSNssai(sNSSAI));
    }

    @Test
    public void testFindCUsofSNssai() {
        String sNSSAI = "001-00001";
        List<GNBCUCPModel> cuModels = new ArrayList<GNBCUCPModel>();
        Mockito.doReturn(cuModels).when(rANSliceConfigService).findCUsofSNssai(Mockito.anyString());
        assertEquals(cuModels, rANSliceConfigService.findCUsofSNssai(sNSSAI));
    }

    @Test
    public void testGetSubscriberDetails() {
        String sNSSAI = "001-00001";
        Map<String, String> details = new HashMap<String, String>();
        Mockito.doReturn(details).when(rANSliceConfigService).getSubscriberDetails(Mockito.anyString());
        assertEquals(details, rANSliceConfigService.getSubscriberDetails(sNSSAI));
    }

    @Test
    public void testFindAllCUCPFunctions() {
        List<GNBCUCPModel> cucpModels = new ArrayList<GNBCUCPModel>();
        Mockito.doReturn(cucpModels).when(rANSliceConfigService).findAllCUCPFunctions();
        assertEquals(cucpModels, rANSliceConfigService.findAllCUCPFunctions());
    }

    @Test
    public void testFindAllDUFunctions() {
        List<GNBDUModel> duModels = new ArrayList<GNBDUModel>();
        Mockito.doReturn(duModels).when(rANSliceConfigService).findAllDUFunctions();
        assertEquals(duModels, rANSliceConfigService.findAllDUFunctions());
    }

}