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