1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 Wipro Limited.
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=========================================================
20 *******************************************************************************/
21 package org.onap.slice.analysis.ms.configdb;
23 import static org.junit.Assert.assertEquals;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.onap.slice.analysis.ms.models.configdb.CellsModel;
36 import org.onap.slice.analysis.ms.models.configdb.NetworkFunctionModel;
37 import org.onap.slice.analysis.ms.restclients.ConfigDbRestClient;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
41 @RunWith(org.mockito.junit.MockitoJUnitRunner.class)
42 public class ConfigDbInterfaceServiceTest {
45 ConfigDbInterfaceService configdbservice;
48 ConfigDbRestClient restclient;
51 public void fetchCurrentConfigurationOfSlice() {
53 Map<String, Integer> responsemap=new HashMap<>();
54 responsemap.put("dLThptPerSlice", 1);
55 responsemap.put("uLThptPerSlice", 2);
56 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(responsemap, HttpStatus.OK));
57 assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfSlice("snssai"));
61 public void fetchCurrentConfigurationOfRIC() {
62 Map<String,Integer> map=new HashMap<>();
63 Map<String, Map<String,Integer>> responsemap=new HashMap<>();
64 map.put("dLThptPerSlice", 45);
65 map.put("uLThptPerSlice", 50);
66 responsemap.put("1", map);
68 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(responsemap, HttpStatus.OK));
69 assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfRIC("snssai"));
73 public void fetchRICsOfSnssai() {
74 Map<String, List<CellsModel>> response=new HashMap<>();
75 List<CellsModel> cellslist=new ArrayList<>();
76 List<CellsModel> cellslist1=new ArrayList<>();
77 CellsModel cellsmodel1=new CellsModel();
78 cellsmodel1.setCellLocalId("1111");
79 CellsModel cellsmodel2=new CellsModel();
80 cellsmodel2.setCellLocalId("2222");
81 cellslist.add(cellsmodel1);
82 cellslist.add(cellsmodel2);
83 response.put("1", cellslist);
84 CellsModel cellsmodel3=new CellsModel();
85 cellsmodel3.setCellLocalId("3333");
86 CellsModel cellsmodel4=new CellsModel();
87 cellsmodel4.setCellLocalId("4444");
88 cellslist1.add(cellsmodel3);
89 cellslist1.add(cellsmodel4);
90 response.put("2", cellslist1);
91 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(response, HttpStatus.OK));
92 List<String> outputlist=new ArrayList<>();
93 outputlist.add("1111");
94 outputlist.add("2222");
95 Map<String,List<String>> output= configdbservice.fetchRICsOfSnssai("snssai");
96 assertEquals(outputlist, output.get("1"));
101 public void fetchNetworkFunctionsOfSnssai() {
103 List<String> responsemap=new ArrayList<>();
104 List<NetworkFunctionModel> networkfunctionslist=new ArrayList<NetworkFunctionModel>();
105 NetworkFunctionModel nf1=new NetworkFunctionModel();
106 nf1.setgNBDUId("1111");
107 NetworkFunctionModel nf2=new NetworkFunctionModel();
108 nf2.setgNBDUId("2222");
109 NetworkFunctionModel nf3=new NetworkFunctionModel();
110 nf3.setgNBDUId("3333");
111 networkfunctionslist.add(nf1);
112 networkfunctionslist.add(nf2);
113 networkfunctionslist.add(nf3);
114 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(networkfunctionslist, HttpStatus.OK));
115 responsemap=configdbservice.fetchNetworkFunctionsOfSnssai("snssai");
116 assertEquals(3, responsemap.size());
119 public void fetchServiceProfile() {
120 Map<String,String> responseMap=new HashMap<String, String>();
121 responseMap.put("sNSSAI", "001-010");
122 responseMap.put("ranNFNSSIId","1111");
123 responseMap.put("sliceProfileId","2222");
124 responseMap.put("globalSubscriberId","110-345");
125 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(responseMap, HttpStatus.OK));
126 assertEquals(responseMap, configdbservice.fetchServiceDetails("snssai"));