885a9171e05f1364544682903dddaa41ce8b75f3
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
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
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.slice.analysis.ms.configdb;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
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;
40
41 @RunWith(org.mockito.junit.MockitoJUnitRunner.class)
42 public class ConfigDbInterfaceServiceTest {
43
44         @InjectMocks
45         ConfigDbInterfaceService configdbservice;
46
47         @Mock
48         ConfigDbRestClient restclient;
49
50         @Test
51         public void fetchCurrentConfigurationOfSlice() {
52
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()))
57                             .thenReturn(new ResponseEntity<Object>(responsemap, HttpStatus.OK));
58                 assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfSlice("snssai"));
59         }
60
61         @Test
62         public void fetchCurrentConfigurationOfRIC() {
63                 Map<String,Integer> map=new HashMap<>();
64                 Map<String, Map<String,Integer>> responsemap=new HashMap<>();
65                 Map<String, List<Map<String,Integer>>> result =new HashMap<String, List<Map<String,Integer>>>();
66                 map.put("dLThptPerSlice", 45);
67                 map.put("uLThptPerSlice", 60);
68                 map.put("nearRTRICId",1);
69                 responsemap.put("1", map);
70                 List<Map<String,Integer>> list = new ArrayList<Map<String,Integer>>();
71                 list.add(map);
72                 result.put("data",list);
73                 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any()))
74                             .thenReturn(new ResponseEntity<Object>(result, HttpStatus.OK));
75                 assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfRIC("snssai"));
76
77         }
78
79         @Test
80         public void fetchRICsOfSnssai() {
81                 Map<String, List<CellsModel>> response=new HashMap<>();
82                 List<CellsModel> cellslist=new ArrayList<>();
83                 List<CellsModel> cellslist1=new ArrayList<>();
84                 CellsModel cellsmodel1=new CellsModel();
85                 cellsmodel1.setCellLocalId("1111");
86                 CellsModel cellsmodel2=new CellsModel();
87                 cellsmodel2.setCellLocalId("2222");
88                 cellslist.add(cellsmodel1);
89                 cellslist.add(cellsmodel2);
90                 response.put("1", cellslist);
91                 CellsModel cellsmodel3=new CellsModel();
92                 cellsmodel3.setCellLocalId("3333");
93                 CellsModel cellsmodel4=new CellsModel();
94                 cellsmodel4.setCellLocalId("4444");
95                 cellslist1.add(cellsmodel3);
96                 cellslist1.add(cellsmodel4);
97                 response.put("2", cellslist1);
98                 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any()))
99                             .thenReturn(new ResponseEntity<Object>(response, HttpStatus.OK));
100                 List<String> outputlist=new ArrayList<>();
101                 outputlist.add("1111");
102                 outputlist.add("2222");
103                 Map<String,List<String>> output= configdbservice.fetchRICsOfSnssai("snssai");
104                 assertEquals(outputlist, output.get("1"));
105
106         }
107
108         @Test
109         public void fetchNetworkFunctionsOfSnssai() {
110
111                 List<String> responsemap=new ArrayList<>();
112                 List<NetworkFunctionModel> networkfunctionslist=new ArrayList<NetworkFunctionModel>();
113                 NetworkFunctionModel nf1=new NetworkFunctionModel();
114                 nf1.setgNBDUId("1111");
115                 NetworkFunctionModel nf2=new NetworkFunctionModel();
116                 nf2.setgNBDUId("2222");
117                 NetworkFunctionModel nf3=new NetworkFunctionModel();
118                 nf3.setgNBDUId("3333");
119                 networkfunctionslist.add(nf1);
120                 networkfunctionslist.add(nf2);
121                 networkfunctionslist.add(nf3);
122                 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any()))
123                             .thenReturn(new ResponseEntity<Object>(networkfunctionslist, HttpStatus.OK));
124                 responsemap=configdbservice.fetchNetworkFunctionsOfSnssai("snssai");
125                 assertEquals(3, responsemap.size());
126
127         }
128
129         public void fetchServiceProfile() {
130                 Map<String,String> responseMap=new HashMap<String, String>();
131                 responseMap.put("sNSSAI", "001-010");
132                 responseMap.put("ranNFNSSIId","1111");
133                 responseMap.put("sliceProfileId","2222");
134                 responseMap.put("globalSubscriberId","110-345");
135                 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any()))
136                             .thenReturn(new ResponseEntity<Object>(responseMap, HttpStatus.OK));
137                 assertEquals(responseMap, configdbservice.fetchServiceDetails("snssai"));
138         }
139 }
140