diff options
author | 2022-02-03 04:50:38 +0000 | |
---|---|---|
committer | 2022-03-03 13:39:38 +0000 | |
commit | f67adad42f2c857ff76b52df39f0beb5c2cabee4 (patch) | |
tree | d9c4394a5f52187d9db0a09a0759e78350df8e16 /components/slice-analysis-ms/src/test/java/org/onap | |
parent | 5f69c24ad78121a2840b5299583791e557f8b535 (diff) |
[DCAEGEN2] Calculate slice utilization data
Issue-ID: DCAEGEN2-2942
Signed-off-by: Niranjana <niranjana.y60@wipro.com>
Change-Id: Id16d2a36cf964b15495531a54094cad96471bdcb
Diffstat (limited to 'components/slice-analysis-ms/src/test/java/org/onap')
8 files changed, 766 insertions, 285 deletions
diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/aai/AaiInterfaceServiceTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/aai/AaiInterfaceServiceTest.java new file mode 100644 index 00000000..31264e8c --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/aai/AaiInterfaceServiceTest.java @@ -0,0 +1,284 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2021-2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.aai; + +import static org.junit.Assert.assertEquals; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.restclients.AaiRestClient; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(SpringRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) +@PrepareForTest({AaiService.class, Configuration.class}) +@SpringBootTest(classes = AaiInterfaceServiceTest.class) +public class AaiInterfaceServiceTest { + + Configuration configuration = Configuration.getInstance(); + + @InjectMocks + AaiService aaiService; + + @Mock + AaiRestClient restClient; + + @Test + public void fetchCurrentConfigurationOfSlice() { + configuration.setAaiUrl("http://aai:30233/aai/v21/business/customers/customer/"); + PowerMockito.mockStatic(AaiService.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + Map<String, Integer> responsemap = new HashMap<>(); + responsemap.put("dLThptPerSlice", 60); + responsemap.put("uLThptPerSlice", 54); + try { + String serviceInstance = + new String(Files.readAllBytes(Paths.get("src/test/resources/aaiDetailsList.json"))); + Mockito.when(restClient.sendGetRequest(Mockito.anyString(), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstance, HttpStatus.OK)); + + } catch (Exception e) { + e.printStackTrace(); + + } + assertEquals(responsemap, aaiService.fetchCurrentConfigurationOfSlice("001-010000")); + } + + @Test + public void fetchServiceProfile() { + Map<String, String> responseMap = new HashMap<String, String>(); + responseMap.put("sNSSAI", "001-00110"); + responseMap.put("ranNFNSSIId", "4b889f2b-8ee4-4ec7-881f-5b1af8a74039"); + responseMap.put("sliceProfileId", "ab9af40f13f7219099333"); + responseMap.put("globalSubscriberId", "5GCustomer"); + responseMap.put("subscriptionServiceType", "5G"); + + try { + String serviceInstance = + new String(Files.readAllBytes(Paths.get("src/test/resources/aaiDetailsList.json"))); + Mockito.when(restClient.sendGetRequest(Mockito.anyString(), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstance, HttpStatus.OK)); + + } catch (Exception e) { + e.printStackTrace(); + + } + + assertEquals(responseMap, aaiService.fetchServiceDetails("001-00110")); + } + + @Test + public void fetchSubscriberAndSubscriptionServiceTypeTest() throws Exception { + + configuration.setAaiUrl("http://aai:30233/aai/v21"); + Map<String, String> expectedResponse = new HashMap<String, String>(); + expectedResponse.put("globalSubscriberId", "5GCustomer"); + expectedResponse.put("subscriptionServiceType", "5G"); + PowerMockito.mockStatic(AaiService.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + + try { + + String serviceInstance = + new String(Files.readAllBytes(Paths.get("src/test/resources/aaiDetailsList.json"))); + Mockito.when(restClient.sendGetRequest(Mockito.anyString(), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstance, HttpStatus.OK)); + + } catch (Exception e) { + e.printStackTrace(); + } + + Map<String, String> actualResponse = aaiService.fetchSubscriberAndSubscriptionServiceType(); + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void fetchSliceProfilesOfAllotedResourceDataTest() throws Exception { + configuration.setAaiUrl("http://aai:30233/aai/v21"); + List<String> allotedResourceList = new ArrayList<>(); + allotedResourceList.add("530d188d-9087-49af-a44a-90c40e0c2d47"); + List<String> expectedResponse = new ArrayList<>(); + expectedResponse.add("b2ae730f-1d5f-495a-8112-dac017a7348c"); + expectedResponse.add("cad8fa36-2d55-4c12-a92e-1bd551517a0c"); + expectedResponse.add("8d0d698e-77f4-4453-8c09-ae2cbe6a9a04"); + PowerMockito.mockStatic(AaiService.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + + try { + + String serviceInstance = + new String(Files.readAllBytes(Paths.get("src/test/resources/alloted-resource.json"))); + Mockito.when(restClient.sendGetRequest(Mockito.anyString(), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstance, HttpStatus.OK)); + + } catch (Exception e) { + e.printStackTrace(); + + } + List<String> actualResponse = aaiService.fetchSliceProfilesOfAllotedResourceData(allotedResourceList); + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void fetchSnssaiOfSliceProfileTest() throws Exception { + configuration.setAaiUrl("http://aai:30233/aai/v21"); + List<String> sliceProfileList = new ArrayList<>(); + sliceProfileList.add("b2ae730f-1d5f-495a-8112-dac017a7348c"); + sliceProfileList.add("cad8fa36-2d55-4c12-a92e-1bd551517a0c"); + sliceProfileList.add("8d0d698e-77f4-4453-8c09-ae2cbe6a9a04"); + List<String> expectedResponse = new ArrayList<>(); + expectedResponse.add("01-06E442"); + expectedResponse.add("01-B989BD"); + + PowerMockito.mockStatic(AaiService.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + String serviceInstanceUrlAn = "b2ae730f-1d5f-495a-8112-dac017a7348c"; + String serviceInstanceUrlCn = "cad8fa36-2d55-4c12-a92e-1bd551517a0c"; + String serviceInstanceUrlTn = "8d0d698e-77f4-4453-8c09-ae2cbe6a9a04"; + + try { + + String serviceInstanceAn = + new String(Files.readAllBytes(Paths.get("src/test/resources/sliceprofile_an_sa1.json"))); + Mockito.when(restClient.sendGetRequest(Mockito.contains(serviceInstanceUrlAn), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstanceAn, HttpStatus.OK)); + + String serviceInstanceCn = + new String(Files.readAllBytes(Paths.get("src/test/resources/sliceprofile_cn_sa1.json"))); + Mockito.when(restClient.sendGetRequest(Mockito.contains(serviceInstanceUrlCn), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstanceCn, HttpStatus.OK)); + + String serviceInstanceTn = + new String(Files.readAllBytes(Paths.get("src/test/resources/sliceprofile_tn_sa1.json"))); + Mockito.when(restClient.sendGetRequest(Mockito.contains(serviceInstanceUrlTn), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstanceTn, HttpStatus.OK)); + + } catch (Exception e) { + e.printStackTrace(); + + } + List<String> actualResponse = aaiService.fetchSnssaiOfSliceProfile(sliceProfileList); + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void getSnssaiListForNsiTest() throws Exception { + configuration.setAaiUrl("http://aai:30233/aai/v21"); + List<String> expectedResponse = new ArrayList<>(); + expectedResponse.add("01-06E442"); + expectedResponse.add("01-B989BD"); + PowerMockito.mockStatic(AaiService.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + + try { + + String allotedResource = + new String(Files.readAllBytes(Paths.get("src/test/resources/alloted-resource.json"))); + Mockito.when( + restClient.sendGetRequest(Mockito.contains("0835fd19-6726-4081-befb-cc8932c47767"), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(allotedResource, HttpStatus.OK)); + + String serviceInstance = new String(Files.readAllBytes(Paths.get("src/test/resources/nsi.json"))); + Mockito.when( + restClient.sendGetRequest(Mockito.contains("09cad94e-fbb8-4c70-9c4d-74ec75e97683"), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstance, HttpStatus.OK)); + + String serviceInstanceAn = + new String(Files.readAllBytes(Paths.get("src/test/resources/sliceprofile_an_sa1.json"))); + Mockito.when( + restClient.sendGetRequest(Mockito.contains("b2ae730f-1d5f-495a-8112-dac017a7348c"), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstanceAn, HttpStatus.OK)); + + String serviceInstanceCn = + new String(Files.readAllBytes(Paths.get("src/test/resources/sliceprofile_cn_sa1.json"))); + Mockito.when( + restClient.sendGetRequest(Mockito.contains("cad8fa36-2d55-4c12-a92e-1bd551517a0c"), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstanceCn, HttpStatus.OK)); + + String serviceInstanceTn = + new String(Files.readAllBytes(Paths.get("src/test/resources/sliceprofile_tn_sa1.json"))); + Mockito.when( + restClient.sendGetRequest(Mockito.contains("8d0d698e-77f4-4453-8c09-ae2cbe6a9a04"), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstanceTn, HttpStatus.OK)); + + } catch (Exception e) { + e.printStackTrace(); + + } + List<String> actualResponse = aaiService.getSnssaiList("09cad94e-fbb8-4c70-9c4d-74ec75e97683"); + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void getSnssaiListForNssiTest() throws Exception { + configuration.setAaiUrl("http://aai:30233/aai/v21"); + List<String> expectedResponse = new ArrayList<>(); + expectedResponse.add("01-06E442"); + PowerMockito.mockStatic(AaiService.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + try { + + String nssi = new String(Files.readAllBytes(Paths.get("src/test/resources/nssi.json"))); + Mockito.when( + restClient.sendGetRequest(Mockito.contains("50f418a6-804f-4453-bf70-21f0efaf6fcd"), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(nssi, HttpStatus.OK)); + + String serviceInstanceAn = + new String(Files.readAllBytes(Paths.get("src/test/resources/sliceprofile_an_sa1.json"))); + Mockito.when( + restClient.sendGetRequest(Mockito.contains("b2ae730f-1d5f-495a-8112-dac017a7348c"), Mockito.any())) + .thenReturn(new ResponseEntity<Object>(serviceInstanceAn, HttpStatus.OK)); + + } catch (Exception e) { + e.printStackTrace(); + + } + List<String> actualResponse = aaiService.getSnssaiList("50f418a6-804f-4453-bf70-21f0efaf6fcd"); + assertEquals(expectedResponse, actualResponse); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/AaiInterfaceServiceTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/AaiInterfaceServiceTest.java deleted file mode 100644 index 78607788..00000000 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/AaiInterfaceServiceTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * slice-analysis-ms - * ================================================================================ - * Copyright (C) 2021 Wipro Limited. - * ============================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - *******************************************************************************/ -package org.onap.slice.analysis.ms.configdb; - -import static org.junit.Assert.assertEquals; - -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.onap.slice.analysis.ms.models.Configuration; -import org.onap.slice.analysis.ms.models.configdb.CellsModel; -import org.onap.slice.analysis.ms.models.configdb.NetworkFunctionModel; -import org.onap.slice.analysis.ms.restclients.AaiRestClient; -import org.onap.slice.analysis.ms.restclients.ConfigDbRestClient; -import org.onap.slice.analysis.ms.utils.BeanUtil; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) -@PrepareForTest({ AaiService.class,Configuration.class }) -@SpringBootTest(classes = AaiInterfaceServiceTest.class) -public class AaiInterfaceServiceTest { - - Configuration configuration = Configuration.getInstance(); - - @InjectMocks - AaiService aaiService; - - @Mock - AaiRestClient restClient; - - @Test - public void fetchCurrentConfigurationOfSlice() { - configuration.setAaiUrl("http://aai:30233/aai/v21/business/customers/customer/"); - PowerMockito.mockStatic(AaiService.class); - PowerMockito.mockStatic(Configuration.class); - PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); - Map<String, Integer> responsemap = new HashMap<>(); - responsemap.put("dLThptPerSlice", 60); - responsemap.put("uLThptPerSlice", 54); - try { - String serviceInstance = new String( - Files.readAllBytes(Paths.get("src/test/resources/aaiDetailsList.json"))); - Mockito.when(restClient.sendGetRequest(Mockito.anyString(), Mockito.any())) - .thenReturn(new ResponseEntity<Object>(serviceInstance, HttpStatus.OK)); - - - } catch (Exception e) { - e.printStackTrace(); - - } - assertEquals(responsemap, aaiService.fetchCurrentConfigurationOfSlice("001-010000")); - } - - @Test - public void fetchServiceProfile() { - Map<String, String> responseMap = new HashMap<String, String>(); - responseMap.put("sNSSAI", "001-00110"); - responseMap.put("ranNFNSSIId", "4b889f2b-8ee4-4ec7-881f-5b1af8a74039"); - responseMap.put("sliceProfileId", "ab9af40f13f7219099333"); - responseMap.put("globalSubscriberId", "5GCustomer"); - responseMap.put("subscriptionServiceType", "5G"); - - try { - String serviceInstance = new String( - Files.readAllBytes(Paths.get("src/test/resources/aaiDetailsList.json"))); - Mockito.when(restClient.sendGetRequest(Mockito.anyString(), Mockito.any())) - .thenReturn(new ResponseEntity<Object>(serviceInstance, HttpStatus.OK)); - - } catch (Exception e) { - e.printStackTrace(); - - } - - assertEquals(responseMap, aaiService.fetchServiceDetails("001-00110")); - } -} - diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/CpsInterfaceServiceTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/CpsInterfaceServiceTest.java deleted file mode 100644 index 008736d3..00000000 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/CpsInterfaceServiceTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * slice-analysis-ms - * ================================================================================ - * Copyright (C) 2021 Wipro Limited. - * ============================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - *******************************************************************************/ -package org.onap.slice.analysis.ms.configdb; - -import static org.junit.Assert.assertEquals; - -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.onap.slice.analysis.ms.models.Configuration; -import org.onap.slice.analysis.ms.restclients.CpsRestClient; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.modules.junit4.PowerMockRunnerDelegate; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(PowerMockRunner.class) -@PowerMockRunnerDelegate(SpringRunner.class) -@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) -@PrepareForTest({ CpsService.class,Configuration.class }) -@SpringBootTest(classes = CpsInterfaceServiceTest.class) -public class CpsInterfaceServiceTest { - @InjectMocks - CpsService cpsService; - - @Mock - CpsRestClient restClient; - - @Test - public void fetchCurrentConfigurationOfRICTest() { - Map<String, Object> map = new HashMap<>(); - map.put("dLThptPerSlice", 10); - map.put("uLThptPerSlice", 10); - map.put("maxNumberOfConns", 10); - Map<String, Map<String, Object>> responseMap = new HashMap<>(); - responseMap.put("11", map); - try { - String serviceInstance = new String( - Files.readAllBytes(Paths.get("src/test/resources/sliceConfig.json"))); - Mockito.when(restClient.sendPostRequest(Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<>(serviceInstance, HttpStatus.OK)); - } catch (Exception e) { - e.printStackTrace(); - } - assertEquals(responseMap, cpsService.fetchCurrentConfigurationOfRIC("111-1111")); - } - - @Test - public void fetchNetworkFunctionsOfSnssaiTest() { - List<String> responseList=new ArrayList<>(); - responseList.add("22"); - responseList.add("23"); - try { - String serviceInstance = new String( - Files.readAllBytes(Paths.get("src/test/resources/DUList.json"))); - Mockito.when(restClient.sendPostRequest(Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<>(serviceInstance, HttpStatus.OK)); - } catch (Exception e) { - e.printStackTrace(); - } - assertEquals(responseList, cpsService.fetchNetworkFunctionsOfSnssai("111-1111")); - } - - @Test - public void fetchRICsOfSnssaiTest() { - Map<String,List<String>> responseMap=new HashMap<>(); - List<String> cellslist=new ArrayList<>(); - cellslist.add("1599"); - cellslist.add("1598"); - responseMap.put("11",cellslist); - try { - String serviceInstance = new String( - Files.readAllBytes(Paths.get("src/test/resources/DUCellsList.json"))); - Mockito.when(restClient.sendPostRequest(Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<>(serviceInstance, HttpStatus.OK)); - } catch (Exception e) { - e.printStackTrace(); - } - assertEquals(responseMap, cpsService.fetchRICsOfSnssai("111-1111")); - } -} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/controller/SliceConfiguratonTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/controller/SliceConfiguratonTest.java new file mode 100644 index 00000000..b35ecdea --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/controller/SliceConfiguratonTest.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.controller; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.slice.analysis.ms.models.SliceConfigRequest; +import org.onap.slice.analysis.ms.models.SliceConfigResponse; +import org.onap.slice.analysis.ms.service.SliceUtilization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +@RunWith(SpringRunner.class) +@WebMvcTest(SliceConfiguraton.class) +public class SliceConfiguratonTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private SliceUtilization sliceUtilization; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + private static final String UTF8 = StandardCharsets.UTF_8.name(); + + @Test + public void getSnssaiListTest() throws Exception { + SliceConfigRequest sliceConfigRequest = new SliceConfigRequest(); + List<String> sliceIdentifiersList = new ArrayList<>(); + sliceIdentifiersList.add("14559ead-f4fe-4c1c-a94c-8015fad3ea35"); + sliceIdentifiersList.add("14559ead-f4fe-4c1c-a94c-8015fad3ea36"); + sliceConfigRequest.setSliceIdentifiers(sliceIdentifiersList); + List<String> configParamsList = new ArrayList<>(); + configParamsList.add("dLThptPerSlice"); + configParamsList.add("uLThptPerSlice"); + sliceConfigRequest.setConfigParams(configParamsList); + + String executePath = "/api/v1/slices-config"; + String sliceConfigResquestString = + new String(Files.readAllBytes(Paths.get("src/test/resources/sliceConfigRequest.json"))); + ObjectMapper objectMapper = new ObjectMapper(); + SliceConfigResponse sliceConfigResponse = objectMapper + .readValue(new File("src/test/resources/sliceConfigResponse.json"), SliceConfigResponse.class); + Mockito.when(sliceUtilization.getSliceUtilizationData(ArgumentMatchers.any())).thenReturn(sliceConfigResponse); + + mockMvc.perform(get(executePath).contentType(MediaType.APPLICATION_JSON).characterEncoding(UTF8) + .content(objectMapper.writeValueAsString(sliceConfigRequest)).accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().string(objectMapper.writeValueAsString(sliceConfigResponse))); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/cps/CpsInterfaceServiceTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/cps/CpsInterfaceServiceTest.java new file mode 100644 index 00000000..0ae7d4f3 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/cps/CpsInterfaceServiceTest.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2021-2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.cps; + +import static org.junit.Assert.assertEquals; + +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.restclients.CpsRestClient; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(SpringRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) +@PrepareForTest({CpsService.class, Configuration.class}) +@SpringBootTest(classes = CpsInterfaceServiceTest.class) +public class CpsInterfaceServiceTest { + @InjectMocks + CpsService cpsService; + + @Mock + CpsRestClient restClient; + + @Test + public void fetchCurrentConfigurationOfRICTest() { + Map<String, Object> map = new HashMap<>(); + map.put("dLThptPerSlice", 10); + map.put("uLThptPerSlice", 10); + map.put("maxNumberOfConns", 10); + Map<String, Map<String, Object>> responseMap = new HashMap<>(); + responseMap.put("11", map); + try { + String serviceInstance = new String(Files.readAllBytes(Paths.get("src/test/resources/sliceConfig.json"))); + Mockito.when(restClient.sendPostRequest(Mockito.anyString(), Mockito.anyString(), Mockito.any())) + .thenReturn(new ResponseEntity<>(serviceInstance, HttpStatus.OK)); + } catch (Exception e) { + e.printStackTrace(); + } + assertEquals(responseMap, cpsService.fetchCurrentConfigurationOfRIC("111-1111")); + } + + @Test + public void fetchNetworkFunctionsOfSnssaiTest() { + List<String> responseList = new ArrayList<>(); + responseList.add("22"); + responseList.add("23"); + try { + String serviceInstance = new String(Files.readAllBytes(Paths.get("src/test/resources/DUList.json"))); + Mockito.when(restClient.sendPostRequest(Mockito.anyString(), Mockito.anyString(), Mockito.any())) + .thenReturn(new ResponseEntity<>(serviceInstance, HttpStatus.OK)); + } catch (Exception e) { + e.printStackTrace(); + } + assertEquals(responseList, cpsService.fetchNetworkFunctionsOfSnssai("111-1111")); + } + + @Test + public void fetchRICsOfSnssaiTest() { + Map<String, List<String>> responseMap = new HashMap<>(); + List<String> cellslist = new ArrayList<>(); + cellslist.add("1599"); + cellslist.add("1598"); + responseMap.put("11", cellslist); + try { + String serviceInstance = new String(Files.readAllBytes(Paths.get("src/test/resources/DUCellsList.json"))); + Mockito.when(restClient.sendPostRequest(Mockito.anyString(), Mockito.anyString(), Mockito.any())) + .thenReturn(new ResponseEntity<>(serviceInstance, HttpStatus.OK)); + } catch (Exception e) { + e.printStackTrace(); + } + assertEquals(responseMap, cpsService.fetchRICsOfSnssai("111-1111")); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ModelsTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ModelsTest.java index 3150fb5c..682bef43 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ModelsTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ModelsTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * slice-analysis-ms * ================================================================================ - * Copyright (C) 2020-2021 Wipro Limited. + * Copyright (C) 2020-2022 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,9 @@ * ============LICENSE_END========================================================= * *******************************************************************************/ + package org.onap.slice.analysis.ms.models; -import org.junit.Test; + import com.openpojo.reflection.PojoClass; import com.openpojo.reflection.impl.PojoClassFactory; import com.openpojo.validation.Validator; @@ -29,28 +30,37 @@ import com.openpojo.validation.rule.impl.GetterMustExistRule; import com.openpojo.validation.rule.impl.SetterMustExistRule; import com.openpojo.validation.test.impl.GetterTester; import com.openpojo.validation.test.impl.SetterTester; + import nl.jqno.equalsverifier.EqualsVerifier; + +import org.junit.Test; + public class ModelsTest { @Test public void configDataEqualHashcodeTest() { - EqualsVerifier.simple().forClass(ConfigData.class).verify(); + EqualsVerifier.simple().forClass(ConfigData.class).verify(); } + @Test public void cellCUListEqualHashcodeTest() { - EqualsVerifier.simple().forClass(CellCUList.class).verify(); + EqualsVerifier.simple().forClass(CellCUList.class).verify(); } + @Test public void cuModelEqualHashcodeTest() { - EqualsVerifier.simple().forClass(CUModel.class).verify(); + EqualsVerifier.simple().forClass(CUModel.class).verify(); } + @Test public void subCounterEqualHashcodeTest() { EqualsVerifier.simple().forClass(SubCounter.class).verify(); } + @Test public void measurementObjectEqualHashcodeTest() { - EqualsVerifier.simple().forClass(MeasurementObject.class).verify(); + EqualsVerifier.simple().forClass(MeasurementObject.class).verify(); } + @Test public void testGetterSetterSubCounter() { PojoClass pojoclass = PojoClassFactory.getPojoClass(SubCounter.class); @@ -64,34 +74,55 @@ public class ModelsTest { .build(); validator.validate(pojoclass); } + @Test public void testGetterSetterMeasurementObject() { PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasurementObject.class); validateMd(pojoclass); } + @Test public void testGetterSetterCellCUList() { PojoClass pojoclass = PojoClassFactory.getPojoClass(CellCUList.class); validateMd(pojoclass); } + @Test public void testGetterSetterCUModel() { PojoClass pojoclass = PojoClassFactory.getPojoClass(CUModel.class); validateMd(pojoclass); } + @Test public void testGetterSetterConfigData() { PojoClass pojoclass = PojoClassFactory.getPojoClass(ConfigData.class); validateMd(pojoclass); } + + @Test + public void testGetterSetterSliceConfigDetailsModel() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(SliceConfigDetails.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterSliceConfigRequestModel() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(SliceConfigRequest.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterSliceConfigResponseModel() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(SliceConfigResponse.class); + validateMd(pojoclass); + } + public void validateMd(PojoClass pojoclass) { - Validator validator = ValidatorBuilder + Validator validator = ValidatorBuilder .create() .with(new SetterMustExistRule()) .with(new GetterMustExistRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .build(); + .with(new SetterTester()).with(new GetterTester()).build(); validator.validate(pojoclass); } } diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/MLMessageProcessorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/MLMessageProcessorTest.java index 6e0d1243..387b5fd0 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/MLMessageProcessorTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/MLMessageProcessorTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * slice-analysis-ms * ================================================================================ - * Copyright (C) 2020 Wipro Limited. + * Copyright (C) 2020-2022 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,16 @@ package org.onap.slice.analysis.ms.service; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.anyMap; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -29,73 +39,71 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.onap.slice.analysis.ms.aai.AaiService; import org.onap.slice.analysis.ms.configdb.IConfigDbService; -import org.onap.slice.analysis.ms.configdb.AaiService; -import org.onap.slice.analysis.ms.configdb.CpsService; +import org.onap.slice.analysis.ms.cps.CpsService; import org.onap.slice.analysis.ms.models.MLOutputModel; import org.onap.slice.analysis.ms.models.policy.AdditionalProperties; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - @RunWith(SpringRunner.class) @SpringBootTest(classes = MLMessageProcessorTest.class) public class MLMessageProcessorTest { - ObjectMapper obj = new ObjectMapper(); - - @InjectMocks - private MLMessageProcessor mlMessageProcessor; - - @Mock - private IConfigDbService configDbService; + ObjectMapper obj = new ObjectMapper(); + + @InjectMocks + private MLMessageProcessor mlMessageProcessor; + + @Mock + private IConfigDbService configDbService; + + @Mock + AaiService aaiService; + + @Mock + CpsService cpsService; - @Mock - AaiService aaiService; + @Mock + private PolicyService policyService; - @Mock - CpsService cpsService; + @SuppressWarnings({"unchecked"}) + @Test + public void processMLMsgTest() { + MLOutputModel mloutput = null; + MLOutputModel mloutputExp = null; - @Mock - private PolicyService policyService; - - @SuppressWarnings({"unchecked" }) - @Test - public void processMLMsgTest() { - MLOutputModel mloutput = null; - MLOutputModel mloutputExp = null; + Map<String, List<String>> ricToCellMapping = new HashMap<>(); + List<String> myList = new ArrayList<String>(); + myList.add("111"); + myList.add("112"); + ricToCellMapping.put("12", myList); + myList = new ArrayList<String>(); + myList.add("113"); + myList.add("114"); + ricToCellMapping.put("13", myList); - Map<String, List<String>> ricToCellMapping = new HashMap<>(); - List<String> myList = new ArrayList<String>(); - myList.add("111"); - myList.add("112"); - ricToCellMapping.put("12", myList); - myList = new ArrayList<String>(); - myList.add("113"); - myList.add("114"); - ricToCellMapping.put("13", myList); + try { + mloutput = + obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel1.json"))), + new TypeReference<MLOutputModel>() {}); + mloutputExp = + obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel.json"))), + new TypeReference<MLOutputModel>() {}); + } catch (IOException e) { + e.printStackTrace(); + } + when(configDbService.fetchRICsOfSnssai("0001-0111")).thenReturn(ricToCellMapping); + AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>(); + addProps.setResourceConfig(mloutputExp); + doNothing().when(policyService).sendOnsetMessageToPolicy(anyString(), any(AdditionalProperties.class), + anyMap()); + mlMessageProcessor.processMLMsg(mloutput); + assertEquals(mloutputExp, mloutput); + } - try { - mloutput = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel1.json"))), new TypeReference<MLOutputModel>(){}); - mloutputExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel.json"))), new TypeReference<MLOutputModel>(){}); - } - catch (IOException e) { - e.printStackTrace(); - } - when(configDbService.fetchRICsOfSnssai("0001-0111")).thenReturn(ricToCellMapping); - AdditionalProperties<MLOutputModel> addProps = new AdditionalProperties<>(); - addProps.setResourceConfig(mloutputExp); - doNothing().when(policyService).sendOnsetMessageToPolicy(anyString(), any(AdditionalProperties.class), anyMap()); - mlMessageProcessor.processMLMsg(mloutput); - assertEquals(mloutputExp, mloutput); - } - } diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SliceUtilizationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SliceUtilizationTest.java new file mode 100644 index 00000000..90202366 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SliceUtilizationTest.java @@ -0,0 +1,174 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2022 Wipro Limited. + * ============================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + *******************************************************************************/ + +package org.onap.slice.analysis.ms.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.slice.analysis.ms.aai.AaiService; +import org.onap.slice.analysis.ms.models.AggregatedConfig; +import org.onap.slice.analysis.ms.models.Configuration; +import org.onap.slice.analysis.ms.models.SliceConfigRequest; +import org.onap.slice.analysis.ms.models.SliceConfigResponse; +import org.onap.slice.analysis.ms.restclients.DesRestClient; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({SliceUtilization.class, Configuration.class}) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) +@SpringBootTest(classes = SliceUtilizationTest.class) +public class SliceUtilizationTest { + + ObjectMapper objectMapper = new ObjectMapper(); + + Configuration configuration = Configuration.getInstance(); + + @InjectMocks + SliceUtilization sliceUtilization; + + @Mock + AaiService aaiService; + + @Mock + DesRestClient desRestClient; + + @Rule + public ExpectedException exception = ExpectedException.none(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void getPmDataTest() throws Exception { + configuration.setDesUrl("http://des:1681/datalake/v1/exposure/pm_data"); + configuration.setPmDataDurationInWeeks(4); + PowerMockito.mockStatic(SliceUtilization.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + String pmData = null; + try { + pmData = new String(Files.readAllBytes(Paths.get("src/test/resources/pm_data.json"))); + } catch (Exception e) { + e.printStackTrace(); + + } + Mockito.when(desRestClient.sendPostRequest(Mockito.any(), Mockito.any(), Mockito.any())) + .thenReturn(new ResponseEntity<>(pmData, HttpStatus.OK)); + JSONObject actualResponse = sliceUtilization.getPMData("001-1100"); + assertTrue(actualResponse.has("result")); + + } + + @Test + public void calculateSliceUtilizationTest() throws Exception { + + PowerMockito.mockStatic(SliceUtilization.class); + List<JSONObject> pmDataList = new ArrayList<>(); + String pmData; + try { + pmData = new String(Files.readAllBytes(Paths.get("src/test/resources/pm_data.json"))); + JSONObject pmDataObj = new JSONObject(pmData); + pmDataList.add(pmDataObj); + pmDataList.add(pmDataObj); + pmDataList.add(pmDataObj); + } catch (Exception e) { + e.printStackTrace(); + + } + AggregatedConfig actualResponse = sliceUtilization.calculateSliceUtilization(pmDataList); + assertEquals(190857028, (int) actualResponse.getDLThptPerSlice()); + assertEquals(119285978, (int) actualResponse.getULThptPerSlice()); + } + + @Test + public void getSliceUtilizationDataTest() throws Exception { + + PowerMockito.mockStatic(SliceUtilization.class); + SliceConfigRequest sliceConfigRequest = new SliceConfigRequest(); + List<String> sliceIdentifiersList = new ArrayList<>(); + sliceIdentifiersList.add("14559ead-f4fe-4c1c-a94c-8015fad3ea35"); + sliceIdentifiersList.add("14559ead-f4fe-4c1c-a94c-8015fad3ea36"); + sliceConfigRequest.setSliceIdentifiers(sliceIdentifiersList); + List<String> configParamsList = new ArrayList<>(); + configParamsList.add("dLThptPerSlice"); + configParamsList.add("uLThptPerSlice"); + sliceConfigRequest.setConfigParams(configParamsList); + List<String> snssaiList = new ArrayList<>(); + snssaiList.add("01-06E442"); + snssaiList.add("01-B989BD"); + configuration.setDesUrl("http://des:1681/datalake/v1/exposure/pm_data"); + configuration.setPmDataDurationInWeeks(4); + + PowerMockito.mockStatic(SliceUtilization.class); + PowerMockito.mockStatic(Configuration.class); + PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); + + try { + + Mockito.when(aaiService.getSnssaiList(Mockito.any())).thenReturn(snssaiList); + + String pmData = new String(Files.readAllBytes(Paths.get("src/test/resources/pm_data.json"))); + Mockito.when(desRestClient.sendPostRequest(Mockito.any(), Mockito.any(), Mockito.any())) + .thenReturn(new ResponseEntity<>(pmData, HttpStatus.OK)); + } catch (Exception e) { + e.printStackTrace(); + + } + SliceConfigResponse actualResponse = sliceUtilization.getSliceUtilizationData(sliceConfigRequest); + String actualResponseString = objectMapper.writeValueAsString(actualResponse); + SliceConfigResponse sliceConfigResponse = objectMapper + .readValue(new File("src/test/resources/sliceConfigResponse.json"), SliceConfigResponse.class); + assertEquals(objectMapper.writeValueAsString(sliceConfigResponse), actualResponseString); + } +} |