786077880b3399f9a6e8f7e00d018790df6fde71
[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.powermock.api.mockito.PowerMockito;
38 import org.powermock.core.classloader.annotations.PowerMockIgnore;
39 import org.powermock.core.classloader.annotations.PrepareForTest;
40 import org.powermock.modules.junit4.PowerMockRunner;
41 import org.powermock.modules.junit4.PowerMockRunnerDelegate;
42 import org.onap.slice.analysis.ms.models.Configuration;
43 import org.onap.slice.analysis.ms.models.configdb.CellsModel;
44 import org.onap.slice.analysis.ms.models.configdb.NetworkFunctionModel;
45 import org.onap.slice.analysis.ms.restclients.AaiRestClient;
46 import org.onap.slice.analysis.ms.restclients.ConfigDbRestClient;
47 import org.onap.slice.analysis.ms.utils.BeanUtil;
48 import org.springframework.boot.test.context.SpringBootTest;
49 import org.springframework.http.HttpStatus;
50 import org.springframework.http.ResponseEntity;
51 import org.springframework.test.context.junit4.SpringRunner;
52
53 @RunWith(PowerMockRunner.class)
54 @PowerMockRunnerDelegate(SpringRunner.class)
55 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
56 @PrepareForTest({ AaiService.class,Configuration.class })
57 @SpringBootTest(classes = AaiInterfaceServiceTest.class)
58 public class AaiInterfaceServiceTest {
59         
60         Configuration configuration = Configuration.getInstance();
61         
62         @InjectMocks
63         AaiService aaiService;
64
65         @Mock
66         AaiRestClient restClient;
67
68         @Test
69         public void fetchCurrentConfigurationOfSlice() {
70                 configuration.setAaiUrl("http://aai:30233/aai/v21/business/customers/customer/");
71                 PowerMockito.mockStatic(AaiService.class);
72                 PowerMockito.mockStatic(Configuration.class);
73                 PowerMockito.when(Configuration.getInstance()).thenReturn(configuration);
74                 Map<String, Integer> responsemap = new HashMap<>();
75                 responsemap.put("dLThptPerSlice", 60);
76                 responsemap.put("uLThptPerSlice", 54);
77                 try {
78                         String serviceInstance = new String(
79                                         Files.readAllBytes(Paths.get("src/test/resources/aaiDetailsList.json")));
80                         Mockito.when(restClient.sendGetRequest(Mockito.anyString(), Mockito.any()))
81                                         .thenReturn(new ResponseEntity<Object>(serviceInstance, HttpStatus.OK));
82
83
84                 } catch (Exception e) {
85                         e.printStackTrace();
86
87                 }
88                 assertEquals(responsemap, aaiService.fetchCurrentConfigurationOfSlice("001-010000"));
89         }
90
91         @Test
92         public void fetchServiceProfile() {
93                 Map<String, String> responseMap = new HashMap<String, String>();
94                 responseMap.put("sNSSAI", "001-00110");
95                 responseMap.put("ranNFNSSIId", "4b889f2b-8ee4-4ec7-881f-5b1af8a74039");
96                 responseMap.put("sliceProfileId", "ab9af40f13f7219099333");
97                 responseMap.put("globalSubscriberId", "5GCustomer");
98                 responseMap.put("subscriptionServiceType", "5G");
99
100                 try {
101                         String serviceInstance = new String(
102                                         Files.readAllBytes(Paths.get("src/test/resources/aaiDetailsList.json")));
103                         Mockito.when(restClient.sendGetRequest(Mockito.anyString(), Mockito.any()))
104                                         .thenReturn(new ResponseEntity<Object>(serviceInstance, HttpStatus.OK));
105
106                 } catch (Exception e) {
107                         e.printStackTrace();
108
109                 }
110
111                 assertEquals(responseMap, aaiService.fetchServiceDetails("001-00110"));
112         }
113 }
114