008736d3fce464cd734a312408fb7aa8ce4c83e7
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
4  *  ================================================================================
5  *   Copyright (C) 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.nio.file.Files;
26 import java.nio.file.Paths;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.Mockito;
37 import org.onap.slice.analysis.ms.models.Configuration;
38 import org.onap.slice.analysis.ms.restclients.CpsRestClient;
39 import org.powermock.core.classloader.annotations.PowerMockIgnore;
40 import org.powermock.core.classloader.annotations.PrepareForTest;
41 import org.powermock.modules.junit4.PowerMockRunner;
42 import org.powermock.modules.junit4.PowerMockRunnerDelegate;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.http.HttpStatus;
45 import org.springframework.http.ResponseEntity;
46 import org.springframework.test.context.junit4.SpringRunner;
47
48 @RunWith(PowerMockRunner.class)
49 @PowerMockRunnerDelegate(SpringRunner.class)
50 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
51 @PrepareForTest({ CpsService.class,Configuration.class })
52 @SpringBootTest(classes = CpsInterfaceServiceTest.class)
53 public class CpsInterfaceServiceTest {
54         @InjectMocks
55         CpsService cpsService;
56
57         @Mock
58         CpsRestClient restClient;
59
60         @Test
61         public void fetchCurrentConfigurationOfRICTest() {
62                 Map<String, Object> map = new HashMap<>();
63                 map.put("dLThptPerSlice", 10);
64                 map.put("uLThptPerSlice", 10);
65                 map.put("maxNumberOfConns", 10);
66                 Map<String, Map<String, Object>> responseMap = new HashMap<>();
67                 responseMap.put("11", map);
68                 try {
69                         String serviceInstance = new String(
70                                         Files.readAllBytes(Paths.get("src/test/resources/sliceConfig.json")));
71                         Mockito.when(restClient.sendPostRequest(Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<>(serviceInstance, HttpStatus.OK));
72                 } catch (Exception e) {
73                         e.printStackTrace();
74                 }
75                 assertEquals(responseMap, cpsService.fetchCurrentConfigurationOfRIC("111-1111"));
76         }
77
78         @Test
79         public void fetchNetworkFunctionsOfSnssaiTest() {
80                 List<String> responseList=new ArrayList<>();
81                 responseList.add("22");
82                 responseList.add("23");
83                 try {
84                         String serviceInstance = new String(
85                                         Files.readAllBytes(Paths.get("src/test/resources/DUList.json")));
86                         Mockito.when(restClient.sendPostRequest(Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<>(serviceInstance, HttpStatus.OK));
87                 } catch (Exception e) {
88                         e.printStackTrace();
89                 }
90                 assertEquals(responseList, cpsService.fetchNetworkFunctionsOfSnssai("111-1111"));
91         }
92
93         @Test
94         public void fetchRICsOfSnssaiTest() {
95                 Map<String,List<String>> responseMap=new HashMap<>();
96                 List<String> cellslist=new ArrayList<>();
97                 cellslist.add("1599");
98                 cellslist.add("1598");
99                 responseMap.put("11",cellslist);
100                 try {
101                         String serviceInstance = new String(
102                                         Files.readAllBytes(Paths.get("src/test/resources/DUCellsList.json")));
103                         Mockito.when(restClient.sendPostRequest(Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<>(serviceInstance, HttpStatus.OK));
104                 } catch (Exception e) {
105                         e.printStackTrace();
106                 }
107                 assertEquals(responseMap, cpsService.fetchRICsOfSnssai("111-1111"));
108         }
109 }