1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
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
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.nio.file.Files;
26 import java.nio.file.Paths;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
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;
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 {
55 CpsService cpsService;
58 CpsRestClient restClient;
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);
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) {
75 assertEquals(responseMap, cpsService.fetchCurrentConfigurationOfRIC("111-1111"));
79 public void fetchNetworkFunctionsOfSnssaiTest() {
80 List<String> responseList=new ArrayList<>();
81 responseList.add("22");
82 responseList.add("23");
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) {
90 assertEquals(responseList, cpsService.fetchNetworkFunctionsOfSnssai("111-1111"));
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);
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) {
107 assertEquals(responseMap, cpsService.fetchRICsOfSnssai("111-1111"));