481fee6f0275dd3cb8f6ef90358a082ca518af65
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
4  *  ================================================================================
5  *   Copyright (C) 2020 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())).thenReturn(new ResponseEntity<Object>(responsemap, HttpStatus.OK));
57                 assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfSlice("snssai"));
58         }
59
60         @Test
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);
67                 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(responsemap, HttpStatus.OK)); 
68                 assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfSlice("snssai"));
69
70         }
71         @Test
72         public void fetchRICsOfSnssai() {
73                 Map<String, List<CellsModel>> response=new HashMap<>();
74                 List<CellsModel> cellslist=new ArrayList<>();
75                 List<CellsModel> cellslist1=new ArrayList<>();
76                 CellsModel cellsmodel1=new CellsModel();
77                 cellsmodel1.setCellLocalId("1111");
78                 CellsModel cellsmodel2=new CellsModel();
79                 cellsmodel2.setCellLocalId("2222");
80                 cellslist.add(cellsmodel1);
81                 cellslist.add(cellsmodel2);
82                 response.put("1", cellslist);
83                 CellsModel cellsmodel3=new CellsModel();
84                 cellsmodel3.setCellLocalId("3333");
85                 CellsModel cellsmodel4=new CellsModel();
86                 cellsmodel4.setCellLocalId("4444");
87                 cellslist1.add(cellsmodel3);
88                 cellslist1.add(cellsmodel4);
89                 response.put("2", cellslist1);
90                 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(response, HttpStatus.OK));
91                 List<String> outputlist=new ArrayList<>();
92                 outputlist.add("1111");
93                 outputlist.add("2222");
94                 Map<String,List<String>> output= configdbservice.fetchRICsOfSnssai("snssai");
95                 assertEquals(outputlist, output.get("1"));
96
97         }
98
99         @Test
100         public void fetchNetworkFunctionsOfSnssai() {
101
102                 List<String> responsemap=new ArrayList<>();
103                 List<NetworkFunctionModel> networkfunctionslist=new ArrayList<NetworkFunctionModel>();
104                 NetworkFunctionModel nf1=new NetworkFunctionModel();
105                 nf1.setgNBDUId("1111");
106                 NetworkFunctionModel nf2=new NetworkFunctionModel();
107                 nf2.setgNBDUId("2222");
108                 NetworkFunctionModel nf3=new NetworkFunctionModel();
109                 nf3.setgNBDUId("3333");
110                 networkfunctionslist.add(nf1);
111                 networkfunctionslist.add(nf2);
112                 networkfunctionslist.add(nf3);
113                 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(networkfunctionslist, HttpStatus.OK));
114                 responsemap=configdbservice.fetchNetworkFunctionsOfSnssai("snssai");
115                 assertEquals(3, responsemap.size());
116
117         }
118         public void fetchServiceProfile() {
119                 Map<String,String> responseMap=new HashMap<String, String>();
120                 responseMap.put("sNSSAI", "001-010");
121                 responseMap.put("ranNFNSSIId","1111");
122                 responseMap.put("sliceProfileId","2222");
123                 responseMap.put("globalSubscriberId","110-345");
124                 Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(responseMap, HttpStatus.OK));
125                 assertEquals(responseMap, configdbservice.fetchServiceDetails("snssai"));
126         }
127 }