From 8882e23eedce9e9236e1d979b2056b62dd974d91 Mon Sep 17 00:00:00 2001 From: dhebeha Date: Tue, 8 Sep 2020 13:02:32 +0530 Subject: Add support to consume, process pm message from DB - Add support for analysing pm data - Add support to trigger closed loop - Add support for configDb Interface Implementation - Add support for Intelligent slicing Issue-ID: DCAEGEN2-2255 Signed-off-by: dhebeha Change-Id: I185dbb6da45ae6ee74f0a090e2d604914163588b --- .../slice/analysis/ms/beans/ConfigPolicyTest.java | 43 ----- .../slice/analysis/ms/beans/ConfigurationTest.java | 73 -------- .../ms/configdb/ConfigDbInterfaceServiceTest.java | 127 ++++++++++++++ .../slice/analysis/ms/dmaap/DmaapClientTest.java | 51 +++--- .../ms/dmaap/NotificationConsumerTest.java | 10 +- .../analysis/ms/dmaap/PolicyDmaapClientTest.java | 10 +- .../slice/analysis/ms/models/ConfigPolicyTest.java | 43 +++++ .../analysis/ms/models/ConfigurationTest.java | 73 ++++++++ .../onap/slice/analysis/ms/models/ModelsTest.java | 92 ++++++++++ .../ms/models/pmnotification/PmModelsTest.java | 106 +++++++++++ .../ms/models/policy/PolicyModelsTest.java | 69 ++++++++ .../analysis/ms/restclients/RestClientTest.java | 120 +++++++++++++ .../analysis/ms/service/AverageCalculatorTest.java | 117 +++++++++++++ .../ms/service/MLMessageProcessorTest.java | 93 ++++++++++ .../slice/analysis/ms/service/PmDataQueueTest.java | 152 ++++++++++++++++ .../analysis/ms/service/PmEventProcessorTest.java | 65 +++++++ .../analysis/ms/service/PolicyServiceTest.java | 84 +++++++++ .../ms/service/SnssaiSamplesProcessorTest.java | 193 +++++++++++++++++++++ 18 files changed, 1369 insertions(+), 152 deletions(-) delete mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java delete mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceServiceTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigPolicyTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ModelsTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/pmnotification/PmModelsTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/policy/PolicyModelsTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/MLMessageProcessorTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmDataQueueTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmEventProcessorTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java create mode 100644 components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java (limited to 'components/slice-analysis-ms/src/test/java') diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java deleted file mode 100644 index 66f97d96..00000000 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * slice-analysis-ms - * ================================================================================ - * Copyright (C) 2020 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.beans; - -import static org.junit.Assert.assertEquals; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; - - -public class ConfigPolicyTest { - - @Test - public void configPolicyTest() { - ConfigPolicy configPolicy = ConfigPolicy.getInstance(); - Map config = new HashMap(); - config.put("policyName", "pcims_policy"); - configPolicy.setConfig(config); - assertEquals(config, configPolicy.getConfig()); - } -} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java deleted file mode 100644 index a3487773..00000000 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START======================================================= - * slice-analysis-ms - * ================================================================================ - * Copyright (C) 2020 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.beans; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; - - -public class ConfigurationTest { - Configuration configuration = Configuration.getInstance(); - - @Test - public void configurationTest() { - - List list = new ArrayList(); - list.add("server"); - Map subscribes = new HashMap<>(); - - configuration.setStreamsSubscribes(subscribes); - configuration.setStreamsPublishes(subscribes); - configuration.setDmaapServers(list); - configuration.setCg("cg"); - configuration.setCid("cid"); - configuration.setAafPassword("password"); - configuration.setAafUsername("user"); - configuration.setPgHost("pg"); - configuration.setPgPort(5432); - configuration.setPgPassword("password"); - configuration.setPgUsername("user"); - configuration.setPollingInterval(30); - configuration.setPollingTimeout(100); - configuration.setConfigDbService("sdnrService"); - - assertEquals("cg", configuration.getCg()); - assertEquals("cid", configuration.getCid()); - assertEquals("user", configuration.getAafUsername()); - assertEquals("password", configuration.getAafPassword()); - assertEquals("user", configuration.getPgUsername()); - assertEquals("password", configuration.getPgPassword()); - assertEquals("pg", configuration.getPgHost()); - assertEquals(5432, configuration.getPgPort()); - assertEquals(30, configuration.getPollingInterval()); - assertEquals(100, configuration.getPollingTimeout()); - assertEquals("sdnrService", configuration.getConfigDbService()); - assertEquals(list, configuration.getDmaapServers()); - } -} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceServiceTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceServiceTest.java new file mode 100644 index 00000000..481fee6f --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceServiceTest.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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.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.configdb.CellsModel; +import org.onap.slice.analysis.ms.models.configdb.NetworkFunctionModel; +import org.onap.slice.analysis.ms.restclients.ConfigDbRestClient; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +@RunWith(org.mockito.junit.MockitoJUnitRunner.class) +public class ConfigDbInterfaceServiceTest { + + @InjectMocks + ConfigDbInterfaceService configdbservice; + + @Mock + ConfigDbRestClient restclient; + + @Test + public void fetchCurrentConfigurationOfSlice() { + + Map responsemap=new HashMap<>(); + responsemap.put("dLThptPerSlice", 1); + responsemap.put("uLThptPerSlice", 2); + Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity(responsemap, HttpStatus.OK)); + assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfSlice("snssai")); + } + + @Test + public void fetchCurrentConfigurationOfRIC() { + Map map=new HashMap<>(); + Map> responsemap=new HashMap<>(); + map.put("dLThptPerSlice", 45); + map.put("uLThptPerSlice", 50); + responsemap.put("1", map); + Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity(responsemap, HttpStatus.OK)); + assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfSlice("snssai")); + + } + @Test + public void fetchRICsOfSnssai() { + Map> response=new HashMap<>(); + List cellslist=new ArrayList<>(); + List cellslist1=new ArrayList<>(); + CellsModel cellsmodel1=new CellsModel(); + cellsmodel1.setCellLocalId("1111"); + CellsModel cellsmodel2=new CellsModel(); + cellsmodel2.setCellLocalId("2222"); + cellslist.add(cellsmodel1); + cellslist.add(cellsmodel2); + response.put("1", cellslist); + CellsModel cellsmodel3=new CellsModel(); + cellsmodel3.setCellLocalId("3333"); + CellsModel cellsmodel4=new CellsModel(); + cellsmodel4.setCellLocalId("4444"); + cellslist1.add(cellsmodel3); + cellslist1.add(cellsmodel4); + response.put("2", cellslist1); + Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity(response, HttpStatus.OK)); + List outputlist=new ArrayList<>(); + outputlist.add("1111"); + outputlist.add("2222"); + Map> output= configdbservice.fetchRICsOfSnssai("snssai"); + assertEquals(outputlist, output.get("1")); + + } + + @Test + public void fetchNetworkFunctionsOfSnssai() { + + List responsemap=new ArrayList<>(); + List networkfunctionslist=new ArrayList(); + NetworkFunctionModel nf1=new NetworkFunctionModel(); + nf1.setgNBDUId("1111"); + NetworkFunctionModel nf2=new NetworkFunctionModel(); + nf2.setgNBDUId("2222"); + NetworkFunctionModel nf3=new NetworkFunctionModel(); + nf3.setgNBDUId("3333"); + networkfunctionslist.add(nf1); + networkfunctionslist.add(nf2); + networkfunctionslist.add(nf3); + Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity(networkfunctionslist, HttpStatus.OK)); + responsemap=configdbservice.fetchNetworkFunctionsOfSnssai("snssai"); + assertEquals(3, responsemap.size()); + + } + public void fetchServiceProfile() { + Map responseMap=new HashMap(); + responseMap.put("sNSSAI", "001-010"); + responseMap.put("ranNFNSSIId","1111"); + responseMap.put("sliceProfileId","2222"); + responseMap.put("globalSubscriberId","110-345"); + Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity(responseMap, HttpStatus.OK)); + assertEquals(responseMap, configdbservice.fetchServiceDetails("snssai")); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java index f2420b02..b74056db 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java @@ -43,7 +43,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.models.Configuration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -54,10 +54,9 @@ public class DmaapClientTest { @Mock private CambriaTopicManager topicManager; - @InjectMocks DmaapClient client; - + @Before public void setup() { MockitoAnnotations.initMocks(this); @@ -77,53 +76,53 @@ public class DmaapClientTest { configuration.setPollingInterval(30); configuration.setPollingTimeout(100); configuration.setConfigDbService("sdnrService"); - + try { when(topicManager.getTopics()).thenReturn(topics); - + client=Mockito.mock(DmaapClient.class); client.initClient(); Mockito.verify(client).initClient(); - // Mockito.verifycreateAndConfigureTopics(); + // Mockito.verifycreateAndConfigureTopics(); } catch (IOException e) { e.printStackTrace(); } } - + @Test public void startClientTest() { try { Configuration configuration = Configuration.getInstance(); String configAllJson = readFromFile("src/test/resources/config_all.json"); - JsonObject configAll = new Gson().fromJson(configAllJson, JsonObject.class); + JsonObject configAll = new Gson().fromJson(configAllJson, JsonObject.class); - JsonObject config = configAll.getAsJsonObject("config"); - - configuration.updateConfigurationFromJsonObject(config); + JsonObject config = configAll.getAsJsonObject("config"); + System.out.println(configuration); + configuration.updateConfigurationFromJsonObject(config); DmaapClient client= new DmaapClient(); client.initClient(); //Mockito.verify(client).startClient(); - // Mockito.verifycreateAndConfigureTopics(); + // Mockito.verifycreateAndConfigureTopics(); } catch ( Exception e) { e.printStackTrace(); } } - private static String readFromFile(String file) { - String content = ""; - try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { - content = bufferedReader.readLine(); - String temp; - while ((temp = bufferedReader.readLine()) != null) { - content = content.concat(temp); - } - content = content.trim(); - } catch (Exception e) { - content = null; - } - return content; - } + private static String readFromFile(String file) { + String content = ""; + try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) { + content = bufferedReader.readLine(); + String temp; + while ((temp = bufferedReader.readLine()) != null) { + content = content.concat(temp); + } + content = content.trim(); + } catch (Exception e) { + content = null; + } + return content; + } } diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java index f4b64397..9aab22c2 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java @@ -21,6 +21,11 @@ package org.onap.slice.analysis.ms.dmaap; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -28,11 +33,6 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; import com.att.nsa.cambria.client.CambriaConsumer; diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java index a458d33c..3ff56ab1 100644 --- a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java @@ -22,10 +22,7 @@ package org.onap.slice.analysis.ms.dmaap; -import static org.junit.Assert.*; - -import com.att.nsa.cambria.client.CambriaBatchingPublisher; -import com.att.nsa.cambria.client.CambriaConsumer; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.HashMap; @@ -38,10 +35,13 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; -import org.onap.slice.analysis.ms.beans.Configuration; +import org.onap.slice.analysis.ms.models.Configuration; import org.onap.slice.analysis.ms.utils.DmaapUtils; import org.springframework.boot.test.context.SpringBootTest; +import com.att.nsa.cambria.client.CambriaBatchingPublisher; +import com.att.nsa.cambria.client.CambriaConsumer; + @RunWith(MockitoJUnitRunner.class) @SpringBootTest(classes = PolicyDmaapClient.class) public class PolicyDmaapClientTest { diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigPolicyTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigPolicyTest.java new file mode 100644 index 00000000..2b137e3a --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigPolicyTest.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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.models; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + + +public class ConfigPolicyTest { + + @Test + public void configPolicyTest() { + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + Map config = new HashMap(); + config.put("policyName", "pcims_policy"); + configPolicy.setConfig(config); + assertEquals(config, configPolicy.getConfig()); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java new file mode 100644 index 00000000..eb492800 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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.models; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; + + +public class ConfigurationTest { + Configuration configuration = Configuration.getInstance(); + + @Test + public void configurationTest() { + + List list = new ArrayList(); + list.add("server"); + Map subscribes = new HashMap<>(); + + configuration.setStreamsSubscribes(subscribes); + configuration.setStreamsPublishes(subscribes); + configuration.setDmaapServers(list); + configuration.setCg("cg"); + configuration.setCid("cid"); + configuration.setAafPassword("password"); + configuration.setAafUsername("user"); + configuration.setPgHost("pg"); + configuration.setPgPort(5432); + configuration.setPgPassword("password"); + configuration.setPgUsername("user"); + configuration.setPollingInterval(30); + configuration.setPollingTimeout(100); + configuration.setConfigDbService("sdnrService"); + + assertEquals("cg", configuration.getCg()); + assertEquals("cid", configuration.getCid()); + assertEquals("user", configuration.getAafUsername()); + assertEquals("password", configuration.getAafPassword()); + assertEquals("user", configuration.getPgUsername()); + assertEquals("password", configuration.getPgPassword()); + assertEquals("pg", configuration.getPgHost()); + assertEquals(5432, configuration.getPgPort()); + assertEquals(30, configuration.getPollingInterval()); + assertEquals(100, configuration.getPollingTimeout()); + assertEquals("sdnrService", configuration.getConfigDbService()); + assertEquals(list, configuration.getDmaapServers()); + } +} 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 new file mode 100644 index 00000000..582abdce --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ModelsTest.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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.models; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule; +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; + +public class ModelsTest { + + @Test + public void testGetterSetterSubCounter() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(SubCounter.class); + Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .with(new EqualsAndHashCodeMatchRule()) + .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 testGetterSetterMLOutputModel() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MLOutputModel.class); + validateMd(pojoclass); + } + + public void validateMd(PojoClass pojoclass) { + Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .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/models/pmnotification/PmModelsTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/pmnotification/PmModelsTest.java new file mode 100644 index 00000000..8954ae9b --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/pmnotification/PmModelsTest.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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.models.pmnotification; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +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; + +public class PmModelsTest { + @Test + public void testGetterSetterCommonEventHeader() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(CommonEventHeader.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterEvent() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(Event.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasDataCollection() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasDataCollection.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasInfoId() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasInfoId.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasInfoList() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasInfoList.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasResult() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasResult.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasTypes() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasTypes.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterMeasValuesList() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(MeasValuesList.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterPerf3gppFields() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(Perf3gppFields.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterPmNotification() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(PmNotification.class); + validateMd(pojoclass); + } + + public void validateMd(PojoClass pojoclass) { + Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .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/models/policy/PolicyModelsTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/policy/PolicyModelsTest.java new file mode 100644 index 00000000..958a1f83 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/policy/PolicyModelsTest.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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.models.policy; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +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; + +public class PolicyModelsTest { + @Test + public void testGetterSetterPayload() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(Payload.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterAAI() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(AAI.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterOnsetMessage() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(OnsetMessage.class); + validateMd(pojoclass); + } + + @Test + public void testGetterSetterAdditionalProperties() { + PojoClass pojoclass = PojoClassFactory.getPojoClass(AdditionalProperties.class); + validateMd(pojoclass); + } + + public void validateMd(PojoClass pojoclass) { + Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .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/restclients/RestClientTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java new file mode 100644 index 00000000..b19b4801 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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.restclients; + + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import java.util.HashMap; +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.utils.BeanUtil; +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.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; + + + +@RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({ BeanUtil.class }) +@SpringBootTest(classes = RestClient.class) +public class RestClientTest { + + + @Mock + RestTemplate restTemplate; + + + @InjectMocks + RestClient restclient; + + + @SuppressWarnings({ "static-access", "unchecked", "rawtypes" }) + @Test + public void sendGetRequestTest() { + + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(Mockito.any())).thenReturn(restTemplate); + ParameterizedTypeReference> responseType = null; + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity requestEntity = new HttpEntity<>( headers); + Map responsemap=new HashMap<>(); + responsemap.put("dLThptPerSlice", 1); + responsemap.put("uLThptPerSlice", 2); + String requestUrl=""; + PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.GET,requestEntity,responseType)).thenReturn(ResponseEntity.ok(responsemap)); + ResponseEntity> resp = restclient.sendGetRequest(headers, requestUrl, responseType); + assertEquals(resp.getBody(),responsemap); + } + + @SuppressWarnings({ "static-access", "unchecked", "rawtypes" }) + @Test + public void sendPostRequestTest() { + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(RestTemplate.class)).thenReturn(restTemplate); + ParameterizedTypeReference responseType = null; + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + String requestUrl = "Url"; String requestBody = null; + HttpEntity requestEntity = new HttpEntity<>(requestBody, headers); + PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.OK)); + ResponseEntity resp = restclient.sendPostRequest(headers, requestUrl, requestBody,responseType); + assertEquals(resp.getStatusCode(), HttpStatus.OK); + } + + @Test + public void sendPostRequestTest2() { + ParameterizedTypeReference responseType = null; + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.setContentType(MediaType.APPLICATION_JSON); + String requestUrl = "Url"; String requestBody = null; + HttpEntity requestEntity = new HttpEntity<>(requestBody, headers); + PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.NOT_FOUND)); + ResponseEntity resp = restclient.sendPostRequest(headers, requestUrl, requestBody,responseType); + assertEquals(resp.getStatusCode(), HttpStatus.NOT_FOUND); + } + + +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java new file mode 100644 index 00000000..e9c134f7 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 java.io.IOException; +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.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AverageCalculatorTest.class) +public class AverageCalculatorTest { + + @InjectMocks + AverageCalculator averageCalculator; + + @Before + public void setup() { + List pmNames = new ArrayList<>(); + pmNames.add("PrbUsedDl"); + pmNames.add("PrbUsedUl"); + ReflectionTestUtils.setField(averageCalculator, "pmNames", pmNames); + } + + @Test + public void findAverageOfSamplesTest() { + ObjectMapper obj = new ObjectMapper(); + List> input = null; + List output = null; + try { + input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/measurementObjectList.json"))), new TypeReference>>(){}); + output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/average.json"))), new TypeReference>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + + assertEquals(output, averageCalculator.findAverageOfSamples(input)); + } + + @Test + public void findAvgTest() { + List result = new ArrayList<>(); + Map pmData = new HashMap<>(); + pmData.put("PrbUsedDl", 50); + pmData.put("PrbUsedUl", 48); + result.add(new MeasurementObject("cell11", pmData)); + pmData.put("PrbUsedDl", 40); + pmData.put("PrbUsedUl", 38); + result.add(new MeasurementObject("cell12", pmData)); + + List exp = new ArrayList<>(); + pmData.put("PrbUsedDl", 25); + pmData.put("PrbUsedUl", 24); + exp.add(new MeasurementObject("cell11", pmData)); + pmData.put("PrbUsedDl", 20); + pmData.put("PrbUsedUl", 19); + exp.add(new MeasurementObject("cell12", pmData)); + + assertEquals(exp, averageCalculator.findAvg(result, 2)); + } + + @Test + public void findAvgSum() { + Map existingMap = new HashMap<>(); + existingMap.put("PrbUsedDl", 50); + existingMap.put("PrbUsedUl", 48); + + Map currentMap = new HashMap<>(); + currentMap.put("PrbUsedDl", 40); + currentMap.put("PrbUsedUl", 38); + + Map result = new HashMap<>(); + result.put("PrbUsedDl", 90); + result.put("PrbUsedUl", 86); + + assertEquals(new MeasurementObject("cell1", result), + averageCalculator.findSum(new MeasurementObject("cell1", existingMap), new MeasurementObject("cell1", currentMap))); + } +} + 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 new file mode 100644 index 00000000..d80160c9 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/MLMessageProcessorTest.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 java.io.IOException; +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 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.configdb.IConfigDbService; +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; + + @Mock + private PolicyService policyService; + + @SuppressWarnings({"unchecked" }) + @Test + public void processMLMsgTest() { + MLOutputModel mloutput = null; + MLOutputModel mloutputExp = null; + + Map> ricToCellMapping = new HashMap<>(); + List myList = new ArrayList(); + myList.add("111"); + myList.add("112"); + ricToCellMapping.put("12", myList); + myList = new ArrayList(); + 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(){}); + mloutputExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/MLOutputModel.json"))), new TypeReference(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + when(configDbService.fetchRICsOfSnssai("0001-0111")).thenReturn(ricToCellMapping); + AdditionalProperties 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/PmDataQueueTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmDataQueueTest.java new file mode 100644 index 00000000..b2c2243d --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmDataQueueTest.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.LinkedBlockingQueue; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.onap.slice.analysis.ms.models.SubCounter; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = PmDataQueueTest.class) +public class PmDataQueueTest { + ObjectMapper obj = new ObjectMapper(); + + @InjectMocks + PmDataQueue pmDataQueue; + + @Before + public void setup() { + Queue> measList = null; + try { + measList = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/measurementObjectList.json"))), new TypeReference>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + SubCounter sub1 = new SubCounter("nf1", "nssai1"); + Map>> subCounterMap = Collections.synchronizedMap(new LinkedHashMap>>()); + subCounterMap.put(sub1, measList); + ReflectionTestUtils.setField(pmDataQueue, "subCounterMap", subCounterMap); + + Queue snssaiList = new LinkedBlockingQueue<>(); + snssaiList.add("nssai1"); + snssaiList.add("nssai2"); + snssaiList.add("nssai3"); + ReflectionTestUtils.setField(pmDataQueue, "snssaiList", snssaiList); + + } + + @Test + public void putDataToQueueSameNssaiTest() { + SubCounter sub1 = new SubCounter("nf1", "nssai1"); + Map>> subCounterMapExp = Collections.synchronizedMap(new LinkedHashMap>>()); + List measObj = null; + Queue> measObjExp = null; + try { + measObj = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/average.json"))), new TypeReference>(){}); + measObjExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/appendData.json"))), new TypeReference>>(){}); + + } + catch (IOException e) { + e.printStackTrace(); + } + subCounterMapExp.put(sub1, measObjExp); + pmDataQueue.putDataToQueue(sub1, measObj); + assertEquals(subCounterMapExp, ReflectionTestUtils.getField(pmDataQueue, "subCounterMap")); + } + + @SuppressWarnings("unchecked") + @Test + public void putDataToQueueDiffNssaiTest() { + SubCounter sub = new SubCounter("nf1", "nssai1"); + SubCounter sub1 = new SubCounter("nf1", "nssai2"); + Map>> subCounterMapExp = Collections.synchronizedMap(new LinkedHashMap>>()); + List measObj = null; + Queue> measObjExp = null; + Queue> measObjExp1 = new LinkedBlockingQueue<>(); + try { + measObj = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/average.json"))), new TypeReference>(){}); + measObjExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/measurementObjectList.json"))), new TypeReference>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + measObjExp1.add(measObj); + subCounterMapExp.put(sub, measObjExp); + subCounterMapExp.put(sub1, measObjExp1); + pmDataQueue.putDataToQueue(sub1, measObj); + assertEquals(subCounterMapExp.get(sub), ((Map>>) ReflectionTestUtils.getField(pmDataQueue, "subCounterMap")).get(sub)); + assertEquals(subCounterMapExp.get(sub1).contains(measObj), ((Map>>) ReflectionTestUtils.getField(pmDataQueue, "subCounterMap")).get(sub1).contains(measObj)); + } + + @Test + public void getSamplesFromQueueTest() { + SubCounter sub = new SubCounter("nf1", "nssai1"); + List> measObj = null; + try { + measObj = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/getResponse.json"))), new TypeReference>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + assertEquals(measObj, pmDataQueue.getSamplesFromQueue(sub, 1)); + } + + @SuppressWarnings("unchecked") + @Test + public void putSnssaiToQueueTest() { + pmDataQueue.putSnssaiToQueue("nssai1"); + assertEquals(3, ((Queue)ReflectionTestUtils.getField(pmDataQueue, "snssaiList")).size()); + } + + @SuppressWarnings("unchecked") + @Test + public void putNewSnssaiToQueueTest() { + pmDataQueue.putSnssaiToQueue("nssai9"); + assertEquals(4, ((Queue)ReflectionTestUtils.getField(pmDataQueue, "snssaiList")).size()); + } + + @Test + public void getSnnsaiFromQueueTest() { + assertEquals("nssai1", pmDataQueue.getSnnsaiFromQueue()); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmEventProcessorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmEventProcessorTest.java new file mode 100644 index 00000000..ae4f5471 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmEventProcessorTest.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.onap.slice.analysis.ms.models.pmnotification.Event; +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 = PmEventProcessorTest.class) +public class PmEventProcessorTest { + + @InjectMocks + PmEventProcessor pmEventProcessor; + + @Test + public void processEventTest() { + ObjectMapper obj = new ObjectMapper(); + Event input = null; + Map> output = null; + try { + input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/event.json"))), Event.class); + output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/eventProcessorOutput.json"))), new TypeReference>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + + assertEquals(output, pmEventProcessor.processEvent(input)); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java new file mode 100644 index 00000000..1131a5e5 --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.slice.analysis.ms.models.policy.AdditionalProperties; +import org.onap.slice.analysis.ms.models.policy.OnsetMessage; +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; +import com.google.gson.Gson; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = PolicyServiceTest.class) +public class PolicyServiceTest { + ObjectMapper obj = new ObjectMapper(); + + @InjectMocks + PolicyService policyService; + + @Test + public void formPolicyOnsetMessageTest() { + String snssai = "001-100001"; + Map input = null; + OnsetMessage output = null; + String expected = ""; + String actual = ""; + Map> ricToThroughputMapping = new HashMap<>(); + Map ric1 = new HashMap<>(); + Map ric2 = new HashMap<>(); + ric1.put("dLThptPerSlice",50); + ric1.put("uLThptPerSlice",40); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMapping.put("1", ric1); + ricToThroughputMapping.put("2", ric2); + try { + input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/serviceDetails.json"))), new TypeReference>(){}); + output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/onsetMessage.json"))), OnsetMessage.class); + expected = obj.writeValueAsString(output); + } + catch (IOException e) { + e.printStackTrace(); + } + AdditionalProperties>> addProps = new AdditionalProperties<>(); + addProps.setResourceConfig(ricToThroughputMapping); + actual = new Gson().toJson(policyService.formPolicyOnsetMessage(snssai,addProps,input)); + + assertThatJson(actual) + .whenIgnoringPaths("requestID","payload.additionalProperties.nsiInfo.nsiId","closedLoopAlarmStart", "AAI", "target_type", "aai", "targetType") + .isEqualTo(expected); + } +} diff --git a/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java new file mode 100644 index 00000000..b8316dfe --- /dev/null +++ b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * slice-analysis-ms + * ================================================================================ + * Copyright (C) 2020 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 java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.onap.slice.analysis.ms.models.MeasurementObject; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SnssaiSamplesProcessorTest.class) +public class SnssaiSamplesProcessorTest { + ObjectMapper obj = new ObjectMapper(); + + @InjectMocks + SnssaiSamplesProcessor snssaiSamplesProcessor; + + @Before + public void setup() { + Map> ricToThroughputMapping = new HashMap<>(); + Map ric1 = new HashMap<>(); + Map ric2 = new HashMap<>(); + ric1.put("dLThptPerSlice",50); + ric1.put("uLThptPerSlice",40); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMapping.put("1", ric1); + ricToThroughputMapping.put("2", ric2); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToThroughputMapping", ricToThroughputMapping); + + Map> ricToPrbsMapping = null; + List sliceMeasList = null; + Map> ricToCellMapping = null; + Map prbThroughputMapping = new HashMap<>(); + prbThroughputMapping = new HashMap<>(); + prbThroughputMapping.put("PrbUsedDl", "dLThptPerSlice"); + prbThroughputMapping.put("PrbUsedUl", "uLThptPerSlice"); + + try { + ricToPrbsMapping = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricToPrbMap.json"))), new TypeReference>>(){}); + sliceMeasList = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/sliceMeasurementList.json"))), new TypeReference>(){}); + ricToCellMapping = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricToCellMapping.json"))), new TypeReference>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToPrbsMapping", ricToPrbsMapping); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "minPercentageChange", 6); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "snssaiMeasurementList", sliceMeasList); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToCellMapping", ricToCellMapping); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "prbThroughputMapping", prbThroughputMapping); + } + + @Test + public void computeSumTest() { + assertEquals(Integer.valueOf(100), snssaiSamplesProcessor.computeSum("PrbUsedDl")); + } + + @Test + public void updateConfigurationTest() { + Map> ricToThroughputMappingExp = new HashMap<>(); + Map ric1 = new HashMap<>(); + Map ric2 = new HashMap<>(); + ric1.put("dLThptPerSlice",50); + ric1.put("uLThptPerSlice",40); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMappingExp.put("1", ric1); + ricToThroughputMappingExp.put("2", ric2); + snssaiSamplesProcessor.updateConfiguration(); + assertEquals(ricToThroughputMappingExp,ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping")); + } + + @Test + public void updateConfigurationTrueTest() { + Map> ricToThroughputMappingExp = new HashMap<>(); + Map ric2 = new HashMap<>(); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMappingExp.put("2", ric2); + + Map> ricToThroughputMapping = new HashMap<>(); + Map ric1 = new HashMap<>(); + ric2 = new HashMap<>(); + ric2.put("dLThptPerSlice",50); + ric2.put("uLThptPerSlice",30); + ricToThroughputMapping.put("1", ric1); + ricToThroughputMapping.put("2", ric2); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToThroughputMapping", ricToThroughputMapping); + + snssaiSamplesProcessor.updateConfiguration(); + System.out.println(); + assertEquals(ricToThroughputMappingExp, ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping")); + } + + @Test + public void calculatePercentageChangeTest() { + Map> ricConfiguration = null; + Map> exp = new HashMap<>(); + Map ric1 = new HashMap<>(); + Map ric2 = new HashMap<>(); + ric1.put("dLThptPerSlice", 50); + ric2.put("dLThptPerSlice", 50); + ric2.put("uLThptPerSlice", 30); + exp.put("1", ric1); + exp.put("2", ric2); + try { + ricConfiguration = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricConfiguration.json"))), new TypeReference>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + snssaiSamplesProcessor.calculatePercentageChange(ricConfiguration, "uLThptPerSlice"); + assertEquals(exp,ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping")); + + ricConfiguration.get("2").put("dLThptPerSlice",60); + exp.get("1").remove("dLThptPerSlice"); + snssaiSamplesProcessor.calculatePercentageChange(ricConfiguration, "dLThptPerSlice"); + assertEquals(exp,ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping")); + } + + @Test + public void sumOfPrbsAcrossCellsTest() { + Map> ricToPrbsMapping = new HashMap<>(); + Map> ricToPrbsMappingExp = new HashMap<>(); + + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToPrbsMapping", ricToPrbsMapping); + + try { + ricToPrbsMappingExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricToPrbOutput.json"))), new TypeReference>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + snssaiSamplesProcessor.sumOfPrbsAcrossCells("PrbUsedDl"); + assertEquals(ricToPrbsMappingExp, ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToPrbsMapping")); + } + + @Test + public void computeThroughputTest() { + Map> ricToThroughputMapping = new HashMap<>(); + ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToThroughputMapping", ricToThroughputMapping); + + Map> ricToThroughputMappingExp = new HashMap<>(); + try { + ricToThroughputMappingExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricToThroughputMappingOutput.json"))), new TypeReference>>(){}); + } + catch (IOException e) { + e.printStackTrace(); + } + Map sliceConfiguration = new HashMap(); + sliceConfiguration.put("dLThptPerSlice",120); + sliceConfiguration.put("uLThptPerSlice",100); + snssaiSamplesProcessor.computeThroughput(sliceConfiguration, 100, "PrbUsedDl"); + snssaiSamplesProcessor.computeThroughput(sliceConfiguration, 70, "PrbUsedUl"); + assertEquals(ricToThroughputMappingExp, ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping")); + } +} -- cgit 1.2.3-korg