summaryrefslogtreecommitdiffstats
path: root/components/slice-analysis-ms/src/test/java/org/onap/slice
diff options
context:
space:
mode:
authorVijay Venkatesh Kumar <vv770d@att.com>2020-09-15 17:11:53 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-15 17:11:53 +0000
commit6da43d9c2d7f38f2eca2a0b44f59cc4fc49b8d82 (patch)
tree47c0cc0e2e4f65efcffa86df0e897762dd673a4d /components/slice-analysis-ms/src/test/java/org/onap/slice
parent2640b87e40e3bbc8853189fa743019b0fc502266 (diff)
parent8882e23eedce9e9236e1d979b2056b62dd974d91 (diff)
Merge "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"
Diffstat (limited to 'components/slice-analysis-ms/src/test/java/org/onap/slice')
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/configdb/ConfigDbInterfaceServiceTest.java127
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/DmaapClientTest.java51
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/NotificationConsumerTest.java10
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/dmaap/PolicyDmaapClientTest.java10
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigPolicyTest.java (renamed from components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigPolicyTest.java)2
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigurationTest.java (renamed from components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/beans/ConfigurationTest.java)2
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ModelsTest.java92
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/pmnotification/PmModelsTest.java106
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/policy/PolicyModelsTest.java69
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/restclients/RestClientTest.java120
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/AverageCalculatorTest.java117
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/MLMessageProcessorTest.java93
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmDataQueueTest.java152
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PmEventProcessorTest.java65
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/PolicyServiceTest.java84
-rw-r--r--components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/service/SnssaiSamplesProcessorTest.java193
16 files changed, 1255 insertions, 38 deletions
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<String, Integer> responsemap=new HashMap<>();
+ responsemap.put("dLThptPerSlice", 1);
+ responsemap.put("uLThptPerSlice", 2);
+ Mockito.when(restclient.sendGetRequest(Mockito.anyString(), Mockito.any())).thenReturn(new ResponseEntity<Object>(responsemap, HttpStatus.OK));
+ assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfSlice("snssai"));
+ }
+
+ @Test
+ public void fetchCurrentConfigurationOfRIC() {
+ Map<String,Integer> map=new HashMap<>();
+ Map<String, Map<String,Integer>> 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<Object>(responsemap, HttpStatus.OK));
+ assertEquals(responsemap, configdbservice.fetchCurrentConfigurationOfSlice("snssai"));
+
+ }
+ @Test
+ public void fetchRICsOfSnssai() {
+ Map<String, List<CellsModel>> response=new HashMap<>();
+ List<CellsModel> cellslist=new ArrayList<>();
+ List<CellsModel> 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<Object>(response, HttpStatus.OK));
+ List<String> outputlist=new ArrayList<>();
+ outputlist.add("1111");
+ outputlist.add("2222");
+ Map<String,List<String>> output= configdbservice.fetchRICsOfSnssai("snssai");
+ assertEquals(outputlist, output.get("1"));
+
+ }
+
+ @Test
+ public void fetchNetworkFunctionsOfSnssai() {
+
+ List<String> responsemap=new ArrayList<>();
+ List<NetworkFunctionModel> networkfunctionslist=new ArrayList<NetworkFunctionModel>();
+ 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<Object>(networkfunctionslist, HttpStatus.OK));
+ responsemap=configdbservice.fetchNetworkFunctionsOfSnssai("snssai");
+ assertEquals(3, responsemap.size());
+
+ }
+ public void fetchServiceProfile() {
+ Map<String,String> responseMap=new HashMap<String, String>();
+ 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<Object>(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/beans/ConfigPolicyTest.java b/components/slice-analysis-ms/src/test/java/org/onap/slice/analysis/ms/models/ConfigPolicyTest.java
index 66f97d96..2b137e3a 100644
--- 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/models/ConfigPolicyTest.java
@@ -20,7 +20,7 @@
*******************************************************************************/
-package org.onap.slice.analysis.ms.beans;
+package org.onap.slice.analysis.ms.models;
import static org.junit.Assert.assertEquals;
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/models/ConfigurationTest.java
index a3487773..eb492800 100644
--- 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/models/ConfigurationTest.java
@@ -20,7 +20,7 @@
*******************************************************************************/
-package org.onap.slice.analysis.ms.beans;
+package org.onap.slice.analysis.ms.models;
import static org.junit.Assert.assertEquals;
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<Map<String,Integer>> responseType = null;
+ HttpHeaders headers = new HttpHeaders();
+ headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ HttpEntity<Object> requestEntity = new HttpEntity<>( headers);
+ Map<String, Integer> 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<Map<String,Integer>> 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<String> 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<Object> requestEntity = new HttpEntity<>(requestBody, headers);
+ PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.OK));
+ ResponseEntity<String> resp = restclient.sendPostRequest(headers, requestUrl, requestBody,responseType);
+ assertEquals(resp.getStatusCode(), HttpStatus.OK);
+ }
+
+ @Test
+ public void sendPostRequestTest2() {
+ ParameterizedTypeReference<String> 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<Object> requestEntity = new HttpEntity<>(requestBody, headers);
+ PowerMockito.when(restTemplate.exchange(requestUrl, HttpMethod.POST,requestEntity,responseType)).thenReturn(new ResponseEntity(HttpStatus.NOT_FOUND));
+ ResponseEntity<String> 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<String> pmNames = new ArrayList<>();
+ pmNames.add("PrbUsedDl");
+ pmNames.add("PrbUsedUl");
+ ReflectionTestUtils.setField(averageCalculator, "pmNames", pmNames);
+ }
+
+ @Test
+ public void findAverageOfSamplesTest() {
+ ObjectMapper obj = new ObjectMapper();
+ List<List<MeasurementObject>> input = null;
+ List<MeasurementObject> output = null;
+ try {
+ input = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/measurementObjectList.json"))), new TypeReference<List<List<MeasurementObject>>>(){});
+ output = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/average.json"))), new TypeReference<List<MeasurementObject>>(){});
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ assertEquals(output, averageCalculator.findAverageOfSamples(input));
+ }
+
+ @Test
+ public void findAvgTest() {
+ List<MeasurementObject> result = new ArrayList<>();
+ Map<String, Integer> 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<MeasurementObject> 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<String, Integer> existingMap = new HashMap<>();
+ existingMap.put("PrbUsedDl", 50);
+ existingMap.put("PrbUsedUl", 48);
+
+ Map<String, Integer> currentMap = new HashMap<>();
+ currentMap.put("PrbUsedDl", 40);
+ currentMap.put("PrbUsedUl", 38);
+
+ Map<String, Integer> 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<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);
+ }
+
+}
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<List<MeasurementObject>> measList = null;
+ try {
+ measList = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/measurementObjectList.json"))), new TypeReference<Queue<List<MeasurementObject>>>(){});
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ SubCounter sub1 = new SubCounter("nf1", "nssai1");
+ Map<SubCounter, Queue<List<MeasurementObject>>> subCounterMap = Collections.synchronizedMap(new LinkedHashMap<SubCounter, Queue<List<MeasurementObject>>>());
+ subCounterMap.put(sub1, measList);
+ ReflectionTestUtils.setField(pmDataQueue, "subCounterMap", subCounterMap);
+
+ Queue<String> 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<SubCounter, Queue<List<MeasurementObject>>> subCounterMapExp = Collections.synchronizedMap(new LinkedHashMap<SubCounter, Queue<List<MeasurementObject>>>());
+ List<MeasurementObject> measObj = null;
+ Queue<List<MeasurementObject>> measObjExp = null;
+ try {
+ measObj = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/average.json"))), new TypeReference<List<MeasurementObject>>(){});
+ measObjExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/appendData.json"))), new TypeReference<Queue<List<MeasurementObject>>>(){});
+
+ }
+ 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<SubCounter, Queue<List<MeasurementObject>>> subCounterMapExp = Collections.synchronizedMap(new LinkedHashMap<SubCounter, Queue<List<MeasurementObject>>>());
+ List<MeasurementObject> measObj = null;
+ Queue<List<MeasurementObject>> measObjExp = null;
+ Queue<List<MeasurementObject>> measObjExp1 = new LinkedBlockingQueue<>();
+ try {
+ measObj = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/average.json"))), new TypeReference<List<MeasurementObject>>(){});
+ measObjExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/measurementObjectList.json"))), new TypeReference<Queue<List<MeasurementObject>>>(){});
+ }
+ 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<SubCounter,Queue<List<MeasurementObject>>>) ReflectionTestUtils.getField(pmDataQueue, "subCounterMap")).get(sub));
+ assertEquals(subCounterMapExp.get(sub1).contains(measObj), ((Map<SubCounter,Queue<List<MeasurementObject>>>) ReflectionTestUtils.getField(pmDataQueue, "subCounterMap")).get(sub1).contains(measObj));
+ }
+
+ @Test
+ public void getSamplesFromQueueTest() {
+ SubCounter sub = new SubCounter("nf1", "nssai1");
+ List<List<MeasurementObject>> measObj = null;
+ try {
+ measObj = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/getResponse.json"))), new TypeReference<List<List<MeasurementObject>>>(){});
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ assertEquals(measObj, pmDataQueue.getSamplesFromQueue(sub, 1));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void putSnssaiToQueueTest() {
+ pmDataQueue.putSnssaiToQueue("nssai1");
+ assertEquals(3, ((Queue<String>)ReflectionTestUtils.getField(pmDataQueue, "snssaiList")).size());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void putNewSnssaiToQueueTest() {
+ pmDataQueue.putSnssaiToQueue("nssai9");
+ assertEquals(4, ((Queue<String>)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<String, List<MeasurementObject>> 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<Map<String, List<MeasurementObject>>>(){});
+ }
+ 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<String, String> input = null;
+ OnsetMessage output = null;
+ String expected = "";
+ String actual = "";
+ Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>();
+ Map<String, Integer> ric1 = new HashMap<>();
+ Map<String, Integer> 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<Map<String,String>>(){});
+ 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<Map<String, Map<String, Integer>>> 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<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>();
+ Map<String, Integer> ric1 = new HashMap<>();
+ Map<String, Integer> 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<String, Map<String, Integer>> ricToPrbsMapping = null;
+ List<MeasurementObject> sliceMeasList = null;
+ Map<String, List<String>> ricToCellMapping = null;
+ Map<String, String> 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<Map<String, Map<String, Integer>>>(){});
+ sliceMeasList = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/sliceMeasurementList.json"))), new TypeReference<List<MeasurementObject>>(){});
+ ricToCellMapping = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricToCellMapping.json"))), new TypeReference<Map<String, List<String>>>(){});
+ }
+ 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<String, Map<String, Integer>> ricToThroughputMappingExp = new HashMap<>();
+ Map<String, Integer> ric1 = new HashMap<>();
+ Map<String, Integer> 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<String, Map<String, Integer>> ricToThroughputMappingExp = new HashMap<>();
+ Map<String, Integer> ric2 = new HashMap<>();
+ ric2.put("dLThptPerSlice",50);
+ ric2.put("uLThptPerSlice",30);
+ ricToThroughputMappingExp.put("2", ric2);
+
+ Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>();
+ Map<String, Integer> 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<String, Map<String, Integer>> ricConfiguration = null;
+ Map<String, Map<String, Integer>> exp = new HashMap<>();
+ Map<String, Integer> ric1 = new HashMap<>();
+ Map<String, Integer> 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<Map<String, Map<String, Integer>>>(){});
+ }
+ 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<String, Map<String, Integer>> ricToPrbsMapping = new HashMap<>();
+ Map<String, Map<String, Integer>> 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<Map<String, Map<String, Integer>>>(){});
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ snssaiSamplesProcessor.sumOfPrbsAcrossCells("PrbUsedDl");
+ assertEquals(ricToPrbsMappingExp, ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToPrbsMapping"));
+ }
+
+ @Test
+ public void computeThroughputTest() {
+ Map<String, Map<String, Integer>> ricToThroughputMapping = new HashMap<>();
+ ReflectionTestUtils.setField(snssaiSamplesProcessor, "ricToThroughputMapping", ricToThroughputMapping);
+
+ Map<String, Map<String, Integer>> ricToThroughputMappingExp = new HashMap<>();
+ try {
+ ricToThroughputMappingExp = obj.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/ricToThroughputMappingOutput.json"))), new TypeReference<Map<String, Map<String, Integer>>>(){});
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ Map<String, Integer> sliceConfiguration = new HashMap<String, Integer>();
+ sliceConfiguration.put("dLThptPerSlice",120);
+ sliceConfiguration.put("uLThptPerSlice",100);
+ snssaiSamplesProcessor.computeThroughput(sliceConfiguration, 100, "PrbUsedDl");
+ snssaiSamplesProcessor.computeThroughput(sliceConfiguration, 70, "PrbUsedUl");
+ assertEquals(ricToThroughputMappingExp, ReflectionTestUtils.getField(snssaiSamplesProcessor, "ricToThroughputMapping"));
+ }
+}