aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/dcaegen2
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/dcaegen2')
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/ApplicationTest.java25
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java105
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java108
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/ConfigPolicyTest.java43
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java89
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java108
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java150
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/MainThreadTest.java26
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/TopicTest.java41
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/child/GraphTest.java64
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java111
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/child/TestDetection.java117
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java157
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClientTest.java112
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducerTest.java71
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/entity/BufferedNotificationsTest.java44
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/entity/CellInfoTest.java38
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/entity/DmaapNotificationsTest.java43
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/entity/PciRequestsTest.java38
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/model/CellConfigTest.java45
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/model/CellNeighbourListTest.java42
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayloadTest.java33
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java128
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java71
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotificationTest.java121
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/model/ResponseTest.java39
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponseTest.java44
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/model/ThreadIdTest.java38
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBodyTest.java57
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfoTest.java45
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBodyTest.java62
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClientTest.java131
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutionsTest.java40
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBodyTest.java43
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRestClientTest.java117
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfoTest.java57
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java158
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SolutionsTest.java56
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java270
39 files changed, 3087 insertions, 0 deletions
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/ApplicationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ApplicationTest.java
new file mode 100644
index 0000000..1b3453a
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ApplicationTest.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms;
+
+public class ApplicationTest {
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java
new file mode 100644
index 0000000..19fe536
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.dcaegen2.services.sonhms.dao.BufferedNotificationsRepository;
+import org.onap.dcaegen2.services.sonhms.entity.BufferedNotifications;
+import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
+import org.powermock.api.mockito.PowerMockito;
+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.test.context.junit4.SpringRunner;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(SpringRunner.class)
+@PrepareForTest({ BeanUtil.class })
+@SpringBootTest(classes = BufferNotificationComponent.class)
+public class BufferNotificationComponentTest {
+
+ @Mock
+ private BufferedNotificationsRepository bufferedNotificationsRepositoryMock;
+
+ @InjectMocks
+ private BufferNotificationComponent bufferNotificationComponent;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void bufferNotificationTest() {
+ BufferedNotifications bufferedNotifications = new BufferedNotifications();
+ bufferedNotifications.setClusterId("clusterId");
+ bufferedNotifications.setNotification("notification");
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.when(BeanUtil.getBean(BufferedNotificationsRepository.class))
+ .thenReturn(bufferedNotificationsRepositoryMock);
+ when(bufferedNotificationsRepositoryMock.save(bufferedNotifications)).thenReturn(bufferedNotifications);
+ bufferNotificationComponent.bufferNotification("notification", "clusterId");
+ assertEquals(bufferedNotifications, bufferedNotificationsRepositoryMock.save(bufferedNotifications));
+
+ }
+
+ @Test
+ public void getBufferedNotificationTest() {
+ List<String> notificationsList = new ArrayList<String>();
+ notificationsList.add("NOTIF1");
+ notificationsList.add("NOTIF2");
+ String clusterId = "clusterId";
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.when(BeanUtil.getBean(BufferedNotificationsRepository.class))
+ .thenReturn(bufferedNotificationsRepositoryMock);
+ when(bufferedNotificationsRepositoryMock.getNotificationsFromQueue(clusterId)).thenReturn((notificationsList));
+
+ List<String> testResult = new ArrayList<String>();
+ testResult = bufferNotificationComponent.getBufferedNotification(clusterId);
+ for (int i = 1; i <= testResult.size(); i++) {
+ assertEquals("NOTIF" + i, testResult.get(i - 1));
+ }
+ }
+
+ @Test
+ public void getClusterIdTest() {
+ String notification = "NOTIF1";
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.when(BeanUtil.getBean(BufferedNotificationsRepository.class))
+ .thenReturn(bufferedNotificationsRepositoryMock);
+ when(bufferedNotificationsRepositoryMock.getClusterIdForNotification(notification)).thenReturn(("clusterId"));
+ String clusterId = bufferNotificationComponent.getClusterId(notification);
+ assertEquals("clusterId", clusterId);
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java
new file mode 100644
index 0000000..22d0ccf
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository;
+import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails;
+import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
+import org.powermock.api.mockito.PowerMockito;
+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.test.context.junit4.SpringRunner;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(SpringRunner.class)
+@PrepareForTest({BeanUtil.class})
+@SpringBootTest(classes = ClusterDetailsComponent.class)
+public class ClusterDetailsComponentTest {
+
+ @Mock
+ private ClusterDetailsRepository clusterDetailsRepositorymock;
+
+
+ @InjectMocks
+ private ClusterDetailsComponent clusterDetailsComponent;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void getClusterDetailsTest() {
+ ClusterDetails clusterDetails = new ClusterDetails("clusterId", "clusterInfo", 1);
+ List<ClusterDetails> list = new ArrayList<ClusterDetails>();
+ list.add(clusterDetails);
+
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.when(BeanUtil.getBean(ClusterDetailsRepository.class)).thenReturn(clusterDetailsRepositorymock);
+ System.out.println(clusterDetailsRepositorymock);
+ when(clusterDetailsRepositorymock.getAllClusterDetails()).thenReturn((list));
+
+ List<ClusterDetails> resultList = new ArrayList<ClusterDetails>();
+ resultList = clusterDetailsComponent.getClusterDetails();
+ for (ClusterDetails each : resultList) {
+ assertEquals("clusterId", each.getClusterId());
+ assertEquals("clusterInfo", each.getClusterInfo());
+ assertEquals(1, each.getChildThreadId());
+
+ }
+
+ }
+
+ @Test
+ public void getChildThreadTest() {
+ String clusterId = "clusterId";
+
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.when(BeanUtil.getBean(ClusterDetailsRepository.class)).thenReturn(clusterDetailsRepositorymock);
+ when(clusterDetailsRepositorymock.getChildThreadForCluster(clusterId)).thenReturn((long)1);
+ long childThreadId = clusterDetailsComponent.getChildThread(clusterId);
+ assertEquals(1, childThreadId);
+
+ }
+
+ @Test
+ public void getClusterIdTest() {
+ long childThreadId = 1;
+
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.when(BeanUtil.getBean(ClusterDetailsRepository.class)).thenReturn(clusterDetailsRepositorymock);
+ when(clusterDetailsRepositorymock.getClusterIdForChildThread(childThreadId))
+ .thenReturn("clusterId");
+ String clusterId = clusterDetailsComponent.getClusterId(childThreadId);
+ assertEquals("clusterId", clusterId);
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigPolicyTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigPolicyTest.java
new file mode 100644
index 0000000..ca12095
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigPolicyTest.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.ConfigPolicy;
+
+
+public class ConfigPolicyTest {
+
+ @Test
+ public void configPolicyTest() {
+ ConfigPolicy configPolicy = ConfigPolicy.getInstance();
+ Map<String, Object> config = new HashMap<String, Object>();
+ config.put("policyName", "pcims_policy");
+ configPolicy.setConfig(config);
+ assertEquals(config, configPolicy.getConfig());
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java
new file mode 100644
index 0000000..02a4f07
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.Configuration;
+
+
+public class ConfigurationTest {
+ Configuration configuration = Configuration.getInstance();
+
+ @Test
+ public void configurationTest() {
+ configuration.setBufferTime(60);
+ configuration.setCallbackUrl("/callbackUrl");
+ configuration.setConfigName("configName");
+
+ List<String> list = new ArrayList<String>();
+ list.add("server");
+ configuration.setServers(list);
+ configuration.setCg("cg");
+ configuration.setCid("cid");
+ configuration.setManagerApiKey("managerApiKey");
+ configuration.setManagerSecretKey("managerSecretKey");
+ configuration.setMaximumClusters(5);
+ configuration.setMinCollision(5);
+ configuration.setMinConfusion(5);
+ configuration.setNumSolutions(1);
+ configuration.setOofService("oofService");
+ configuration.setOptimizers(list);
+ configuration.setPcimsApiKey("pcimsApiKey");
+ configuration.setPcimsSecretKey("pcimsSecretKey");
+ configuration.setPolicyName("policyName");
+ configuration.setPolicyService("policyService");
+ configuration.setPolicyTopic("policyTopic");
+ configuration.setPollingInterval(30);
+ configuration.setPollingTimeout(100);
+ configuration.setSdnrService("sdnrService");
+ configuration.setSdnrTopic("sdnrTopic");
+ configuration.setSourceId("sourceId");
+ assertEquals(60, configuration.getBufferTime());
+ assertEquals("/callbackUrl", configuration.getCallbackUrl());
+ assertEquals("cg", configuration.getCg());
+ assertEquals("cid", configuration.getCid());
+ assertEquals("managerApiKey", configuration.getManagerApiKey());
+ assertEquals("managerSecretKey", configuration.getManagerSecretKey());
+ assertEquals(5, configuration.getMaximumClusters());
+ assertEquals(5, configuration.getMinCollision());
+ assertEquals(5, configuration.getMinConfusion());
+ assertEquals(1, configuration.getNumSolutions());
+ assertEquals("oofService", configuration.getOofService());
+ assertEquals(list, configuration.getOptimizers());
+ assertEquals("pcimsApiKey", configuration.getPcimsApiKey());
+ assertEquals("pcimsSecretKey", configuration.getPcimsSecretKey());
+ assertEquals("policyName", configuration.getPolicyName());
+ assertEquals("policyService", configuration.getPolicyService());
+ assertEquals("policyTopic", configuration.getPolicyTopic());
+ assertEquals(30, configuration.getPollingInterval());
+ assertEquals(100, configuration.getPollingTimeout());
+ assertEquals("sdnrService", configuration.getSdnrService());
+ assertEquals("sdnrTopic", configuration.getSdnrTopic());
+ assertEquals(list, configuration.getServers());
+ assertEquals("sourceId", configuration.getSourceId());
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java
new file mode 100644
index 0000000..cc4d3ad
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+
+import fj.data.Either;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.dcaegen2.services.sonhms.dao.DmaapNotificationsRepository;
+import org.onap.dcaegen2.services.sonhms.model.Notification;
+import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
+import org.powermock.api.mockito.PowerMockito;
+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.test.context.junit4.SpringRunner;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(SpringRunner.class)
+@PrepareForTest({ BeanUtil.class })
+@SpringBootTest(classes = DmaapNotificationsComponentTest.class)
+
+public class DmaapNotificationsComponentTest {
+
+ @Mock
+ DmaapNotificationsRepository dmaapNotificationsRepositoryMock;
+
+ @InjectMocks
+ DmaapNotificationsComponent component;
+
+ static String notificationString;
+
+ @BeforeClass
+ public static void setupTest() {
+
+ notificationString = readFromFile("/notification1.json");
+ }
+
+ @Test
+ public void getDmaapNotificationsTestforLeft() {
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.when(BeanUtil.getBean(DmaapNotificationsRepository.class))
+ .thenReturn(dmaapNotificationsRepositoryMock);
+ when(dmaapNotificationsRepositoryMock.getNotificationFromQueue()).thenReturn(notificationString);
+
+
+ Either<Notification, Integer> result = component.getDmaapNotifications();
+ //assertTrue(result.isLeft());
+ assertNotNull(result.left().value());
+
+ when(dmaapNotificationsRepositoryMock.getNotificationFromQueue()).thenReturn("notification");
+
+ result = component.getDmaapNotifications();
+ int resultRight = result.right().value();
+ assertEquals(400, resultRight);
+
+ }
+
+ private static String readFromFile(String file) {
+ String content = new String();
+ try {
+
+ InputStream is = DmaapNotificationsComponentTest.class.getResourceAsStream(file);
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
+ content = bufferedReader.readLine();
+ String temp;
+ while ((temp = bufferedReader.readLine()) != null) {
+ content = content.concat(temp);
+ }
+ content = content.trim();
+ bufferedReader.close();
+ } catch (Exception e) {
+ content = null;
+ }
+ return content;
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java
new file mode 100644
index 0000000..a79e368
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * pcims
+ * ================================================================================
+ * Copyright (C) 2018 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.dcaegen2.services.sonhms;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.springframework.boot.test.context.SpringBootTest;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.dcaegen2.services.sonhms.child.Graph;
+import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails;
+import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
+import org.onap.dcaegen2.services.sonhms.model.FapServiceList;
+import org.onap.dcaegen2.services.sonhms.model.Notification;
+import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils;
+import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest;
+import org.onap.dcaegen2.services.sonhms.utils.ThreadUtils;
+
+import fj.data.Either;
+
+@RunWith(MockitoJUnitRunner.class)
+@SpringBootTest(classes = EventHandler.class)
+public class EventHandlerTest {
+
+ @Mock
+ ClusterUtils clusterutilsMock;
+
+ @Mock
+ ExecutorService pool;
+
+ @Mock
+ ThreadUtils threadUtilsMock;
+
+ private static Notification notification;
+ private static List<ClusterDetails> clusterDetails = new ArrayList<>();
+
+ @InjectMocks
+ EventHandler eventHandler;
+
+ @Before
+ public void setup() {
+
+ notification = new Notification();
+ String notificationString = readFromFile("/notification3.json");
+ String clusterInfo1 = readFromFile("/clusterInfo1.json");
+ String clusterInfo2 = readFromFile("/clusterInfo2.json");
+ String clusterInfo3 = readFromFile("/clusterInfo3.json");
+ String clusterInfo4 = readFromFile("/clusterInfo4.json");
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ notification = mapper.readValue(notificationString, Notification.class);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ System.out.println(notification.toString());
+
+ clusterDetails.add(new ClusterDetails("1", clusterInfo1, 35));
+ clusterDetails.add(new ClusterDetails("2", clusterInfo2, 36));
+ clusterDetails.add(new ClusterDetails("3", clusterInfo3, 37));
+ clusterDetails.add(new ClusterDetails("4", clusterInfo4, 38));
+
+ }
+
+ @Test
+ public void handleSdnrNotificationTest() {
+
+ String clusterInfo7 = readFromFile("/clusterInfo7.json");
+ Graph cluster = new Graph(clusterInfo7);
+ NotificationToClusterMapping mapping = new NotificationToClusterMapping();
+ Map<FapServiceList, String> cellsinCluster = new HashMap<>();
+ List<FapServiceList> newCells = new ArrayList<>();
+ newCells.add(notification.getPayload().getRadioAccess().getFapServiceList().get(0));
+ mapping.setCellsinCluster(cellsinCluster);
+ mapping.setNewCells(newCells);
+ Either<Graph, Integer> existingCluster = Either.right(404);
+
+
+ Mockito.when(clusterutilsMock.getAllClusters()).thenReturn(clusterDetails);
+ Mockito.when(clusterutilsMock.getClustersForNotification(notification, clusterDetails)).thenReturn(mapping);
+ Mockito.when(clusterutilsMock.getClusterForCell(Mockito.any(), Mockito.any())).thenReturn(existingCluster);
+ Mockito.when(threadUtilsMock.createNewThread(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true);
+
+ try {
+ Mockito.when(clusterutilsMock.createCluster(Mockito.any())).thenReturn(cluster);
+ } catch (ConfigDbNotFoundException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+
+ Assert.assertEquals(true, eventHandler.handleSdnrNotification(notification));
+
+
+
+ }
+
+ private static String readFromFile(String file) {
+ String content = new String();
+ try {
+
+ InputStream is = ClusterUtilsTest.class.getResourceAsStream(file);
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
+ content = bufferedReader.readLine();
+ String temp;
+ while((temp = bufferedReader.readLine()) != null) {
+ content = content.concat(temp);
+ }
+ content = content.trim();
+ bufferedReader.close();
+ }
+ catch(Exception e) {
+ content = null;
+ }
+ return content;
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/MainThreadTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/MainThreadTest.java
new file mode 100644
index 0000000..d06abbf
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/MainThreadTest.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms;
+
+public class MainThreadTest {
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/TopicTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/TopicTest.java
new file mode 100644
index 0000000..6ac6e75
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/TopicTest.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class TopicTest {
+
+ @Test
+ public void topicTest() {
+ Topic topic=new Topic();
+ topic.setConsumer("consumer");
+ topic.setName("name");
+ topic.setProducer("producer");
+ assertEquals("consumer", topic.getConsumer());
+ assertEquals("name", topic.getName());
+ assertEquals("producer", topic.getProducer());
+
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/GraphTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/GraphTest.java
new file mode 100644
index 0000000..3df7f93
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/GraphTest.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.child;
+
+import static org.junit.Assert.assertNotEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.child.Graph;
+import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
+import org.slf4j.Logger;
+
+
+
+public class GraphTest {
+ private static final Logger log = org.slf4j.LoggerFactory.getLogger(GraphTest.class);
+
+ @Test
+ public void graphTest() {
+
+ CellPciPair cpPair1 = new CellPciPair();
+ cpPair1.setCellId("25");
+ cpPair1.setPhysicalCellId(32);
+
+ CellPciPair cpPair2 = new CellPciPair();
+ cpPair2.setCellId("29");
+ cpPair2.setPhysicalCellId(209);
+
+ Graph graph = new Graph();
+
+ graph.addEdge(cpPair1, cpPair2);
+
+ Map<CellPciPair, ArrayList<CellPciPair>> map = new HashMap<>();
+
+ log.debug("graph {}", graph.getCellPciNeighbourMap());
+ System.out.println("graph" + graph.getCellPciNeighbourMap());
+ System.out.println("graphJSON" + graph.getPciNeighbourJson());
+ assertNotEquals(map, graph.getCellPciNeighbourMap());
+
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java
new file mode 100644
index 0000000..03e735f
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.child;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.dcaegen2.services.sonhms.ConfigPolicy;
+import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
+import org.onap.dcaegen2.services.sonhms.model.PolicyNotification;
+import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest;
+
+public class TestChildThreadUtils {
+
+ ChildThreadUtils childThreadUtils;
+
+ @Before
+ public void setup() {
+
+ ConfigPolicy configPolicy = ConfigPolicy.getInstance();
+
+ Map<String, Object> configPolicyMap = new HashMap<>();
+ configPolicyMap.put("PCI_MODCONFIG_POLICY_NAME", "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459");
+ configPolicy.setConfig(configPolicyMap);
+ childThreadUtils = new ChildThreadUtils(configPolicy);
+ }
+
+ @Test
+ public void getNotificationStringTest() {
+
+ String policy_notif = readFromFile("/policy_notification.json");
+ PolicyNotification expected = new PolicyNotification();
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ expected = mapper.readValue(policy_notif, PolicyNotification.class);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ String pnfName = "ncserver23";
+ List<CellPciPair> cellPciPairs = new ArrayList<>();
+
+ cellPciPairs.add(new CellPciPair("Chn0330", 6));
+ cellPciPairs.add(new CellPciPair("Chn0331", 7));
+ String requestId = "a4130fd5-2291-4a83-8992-04e4c9f32731";
+ Long alarmStart = Long.parseLong("1542445563201");
+
+ String result = childThreadUtils.getNotificationString(pnfName, cellPciPairs, requestId, alarmStart);
+ PolicyNotification actual = new PolicyNotification();
+ try {
+ actual = mapper.readValue(result, PolicyNotification.class);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Assert.assertEquals(expected.hashCode(), actual.hashCode());
+ }
+
+ private static String readFromFile(String file) {
+ String content = new String();
+ try {
+
+ InputStream is = ClusterUtilsTest.class.getResourceAsStream(file);
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
+ content = bufferedReader.readLine();
+ String temp;
+ while((temp = bufferedReader.readLine()) != null) {
+ content = content.concat(temp);
+ }
+ content = content.trim();
+ bufferedReader.close();
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ content = null;
+ }
+ return content;
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestDetection.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestDetection.java
new file mode 100644
index 0000000..6e42cce
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestDetection.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.child;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.child.Detection;
+import org.onap.dcaegen2.services.sonhms.child.Graph;
+import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
+
+
+public class TestDetection {
+ @Test
+ public void testDetection() {
+
+ CellPciPair cpPair = new CellPciPair();
+ cpPair.setCellId("32");
+ cpPair.setPhysicalCellId(26);
+
+ CellPciPair cpPair1 = new CellPciPair();
+ cpPair1.setCellId("25");
+ cpPair1.setPhysicalCellId(23);
+
+ CellPciPair cpPair2 = new CellPciPair();
+ cpPair2.setCellId("42");
+ cpPair2.setPhysicalCellId(26);
+
+ CellPciPair cpPair3 = new CellPciPair();
+ cpPair3.setCellId("56");
+ cpPair3.setPhysicalCellId(200);
+
+ CellPciPair cpPair4 = new CellPciPair();
+ cpPair4.setCellId("21");
+ cpPair4.setPhysicalCellId(5);
+
+ CellPciPair cpPair5 = new CellPciPair();
+ cpPair5.setCellId("24");
+ cpPair5.setPhysicalCellId(5);
+
+ CellPciPair cpPair6 = new CellPciPair();
+ cpPair6.setCellId("38");
+ cpPair6.setPhysicalCellId(126);
+
+ CellPciPair cpPair7 = new CellPciPair();
+ cpPair7.setCellId("67");
+ cpPair7.setPhysicalCellId(300);
+
+ CellPciPair cpPair8 = new CellPciPair();
+ cpPair8.setCellId("69");
+ cpPair8.setPhysicalCellId(129);
+
+ CellPciPair cpPair9 = new CellPciPair();
+ cpPair9.setCellId("78");
+ cpPair9.setPhysicalCellId(147);
+
+ ArrayList<CellPciPair> al = new ArrayList<CellPciPair>();
+ al.add(cpPair1);
+ al.add(cpPair2);
+ al.add(cpPair3);
+
+ ArrayList<CellPciPair> al1 = new ArrayList<CellPciPair>();
+ al1.add(cpPair4);
+ al1.add(cpPair5);
+ al1.add(cpPair6);
+
+ ArrayList<CellPciPair> al2 = new ArrayList<CellPciPair>();
+ al2.add(cpPair7);
+ al2.add(cpPair8);
+ al2.add(cpPair9);
+
+ Map<CellPciPair, ArrayList<CellPciPair>> map = new HashMap<CellPciPair, ArrayList<CellPciPair>>();
+
+ map.put(cpPair, al);
+ map.put(cpPair1, al1);
+ map.put(cpPair2, al2);
+ map.put(cpPair3, new ArrayList<CellPciPair>());
+ map.put(cpPair4, new ArrayList<CellPciPair>());
+ map.put(cpPair5, new ArrayList<CellPciPair>());
+ map.put(cpPair6, new ArrayList<CellPciPair>());
+ map.put(cpPair7, new ArrayList<CellPciPair>());
+ map.put(cpPair8, new ArrayList<CellPciPair>());
+ map.put(cpPair9, new ArrayList<CellPciPair>());
+ Graph cluster = new Graph();
+
+ cluster.setCellPciNeighbourMap(map);
+
+ System.out.println("mapsssssss" + cluster.getCellPciNeighbourMap());
+ Detection detect = new Detection();
+ detect.detectCollisionConfusion(cluster);
+ System.out.println("result" + detect.detectCollisionConfusion(cluster));
+
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java
new file mode 100644
index 0000000..e7f822f
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.child;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.modules.junit4.PowerMockRunnerDelegate;
+import org.slf4j.Logger;
+import org.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 org.onap.dcaegen2.services.sonhms.dao.CellInfoRepository;
+import org.onap.dcaegen2.services.sonhms.entity.CellInfo;
+import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
+import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
+import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
+import org.onap.dcaegen2.services.sonhms.restclient.Solution;
+import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
+import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(SpringRunner.class)
+@PrepareForTest({BeanUtil.class, SdnrRestClient.class })
+@SpringBootTest(classes = PnfUtils.class)
+public class TestPnfUtils {
+
+ @Mock
+ private CellInfoRepository cellInfoRepositoryMock;
+
+ private static final Logger log = org.slf4j.LoggerFactory.getLogger(TestPnfUtils.class);
+ private static List<Solution> solutions = new ArrayList<>();
+ private static Optional<CellInfo> cellInfo;
+ private static Optional<CellInfo> cellInfoNull;
+
+
+ @InjectMocks
+ PnfUtils pnfUtils;
+
+ @BeforeClass
+ public static void setup() {
+
+
+ String solutionsString=readFromFile("/solutions.json");
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ solutions=mapper.readValue(solutionsString,new TypeReference<List<Solution>>(){});
+ } catch (IOException e) {
+ log.debug("Exception in StateOof Test "+e);
+ e.printStackTrace();
+ }
+
+ }
+ @Before
+ public void setupTest() {
+ cellInfo = Optional.of(new CellInfo("EXP001","ncserver1"));
+ cellInfoNull = Optional.ofNullable(null);
+ pnfUtils = new PnfUtils();
+ MockitoAnnotations.initMocks(this);
+ }
+ @Test
+ public void getPnfsTest() {
+ Map<String, List<CellPciPair>> pnfs = new HashMap<>();
+ List<CellPciPair> cellpciPairList1=new ArrayList<>();
+ cellpciPairList1.add(new CellPciPair("EXP001",101));
+ List<CellPciPair> cellpciPairList2=new ArrayList<>();
+ cellpciPairList2.add(new CellPciPair("EXP002",102));
+ String pnfName="ncserver2";
+ String cellId="EXP002";
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.mockStatic(SdnrRestClient.class);
+
+ PowerMockito.when(BeanUtil.getBean(CellInfoRepository.class))
+ .thenReturn(cellInfoRepositoryMock);
+
+ Mockito.when(cellInfoRepositoryMock.findById("EXP001"))
+ .thenReturn(cellInfo);
+ Mockito.when(cellInfoRepositoryMock.findById(cellId))
+ .thenReturn(cellInfoNull);
+ try {
+ PowerMockito.when(SdnrRestClient.getPnfName(cellId))
+ .thenReturn(pnfName);
+ PowerMockito.when(cellInfoRepositoryMock.save(new CellInfo(cellId, pnfName))).thenReturn(new CellInfo());
+ } catch (ConfigDbNotFoundException e) {
+ e.printStackTrace();
+ }
+ pnfs.put(pnfName, cellpciPairList2);
+ pnfs.put("ncserver1", cellpciPairList1);
+ System.out.println(solutions);
+ try {
+ assertEquals(pnfs,pnfUtils.getPnfs(solutions));
+ } catch (ConfigDbNotFoundException e) {
+ log.debug("exception in stateOof test {}", e);
+ e.printStackTrace();
+ }
+ }
+ private static String readFromFile(String file) {
+ String content = new String();
+ try {
+
+ InputStream is = ClusterUtilsTest.class.getResourceAsStream(file);
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
+ content = bufferedReader.readLine();
+ String temp;
+ while((temp = bufferedReader.readLine()) != null) {
+ content = content.concat(temp);
+ }
+ content = content.trim();
+ bufferedReader.close();
+ }
+ catch(Exception e) {
+ content = null;
+ }
+ return content;
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClientTest.java
new file mode 100644
index 0000000..63ba5bd
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClientTest.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.dmaap;
+
+import com.att.nsa.cambria.client.CambriaTopicManager;
+
+import static org.mockito.Mockito.when;
+
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+
+import org.onap.dcaegen2.services.sonhms.Configuration;
+import org.onap.dcaegen2.services.sonhms.NewNotification;
+import org.mockito.MockitoAnnotations;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = DmaapClientTest.class)
+public class DmaapClientTest {
+
+ @Mock
+ private CambriaTopicManager topicManager;
+
+
+ @InjectMocks
+ DmaapClient client;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ private Boolean newNotif;
+
+ @Test
+ public void getAllTopicsTest() {
+ Set<String> topics = new HashSet<String>();
+ topics.add("topic1");
+ topics.add("topic2");
+ Configuration configuration = Configuration.getInstance();
+ configuration.setBufferTime(60);
+ configuration.setCallbackUrl("/callbackUrl");
+ configuration.setConfigName("configName");
+ List<String> list = new ArrayList<String>();
+ list.add("server");
+ configuration.setServers(list);
+ configuration.setCg("cg");
+ configuration.setCid("cid");
+ configuration.setManagerApiKey("managerApiKey");
+ configuration.setManagerSecretKey("managerSecretKey");
+ configuration.setMaximumClusters(5);
+ configuration.setMinCollision(5);
+ configuration.setMinConfusion(5);
+ configuration.setNumSolutions(1);
+ configuration.setOofService("oofService");
+ configuration.setOptimizers(list);
+ configuration.setPcimsApiKey("pcimsApiKey");
+ configuration.setPcimsSecretKey("pcimsSecretKey");
+ configuration.setPolicyName("policyName");
+ configuration.setPolicyService("policyService");
+ configuration.setPolicyTopic("policyTopic");
+ configuration.setPollingInterval(30);
+ configuration.setPollingTimeout(100);
+ configuration.setSdnrService("sdnrService");
+ configuration.setSdnrTopic("sdnrTopic");
+ configuration.setSourceId("sourceId");
+ NewNotification newNotification = new NewNotification(newNotif);
+
+ try {
+ when(topicManager.getTopics()).thenReturn(topics);
+ client=Mockito.mock(DmaapClient.class);
+ client.initClient(newNotification);
+ Mockito.verify(client).initClient(newNotification);
+ // Mockito.verifycreateAndConfigureTopics();
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducerTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducerTest.java
new file mode 100644
index 0000000..c76b953
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducerTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.dmaap;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import com.att.nsa.cambria.client.CambriaBatchingPublisher;
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = NotificationProducerTest.class)
+public class NotificationProducerTest {
+
+
+ @Mock
+ CambriaBatchingPublisher cambriaBatchingPublisher;
+
+ @InjectMocks
+ NotificationProducer notificationProducer;
+
+ @Test
+ public void notificationProducerTest() {
+
+
+
+ try {
+
+ when(cambriaBatchingPublisher.send(Mockito.anyString(), Mockito.anyString())).thenReturn(0);
+ int result=notificationProducer.sendNotification("msg");
+ assertEquals(0, result);
+ } catch (GeneralSecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ }
+}
+
+
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/entity/BufferedNotificationsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/BufferedNotificationsTest.java
new file mode 100644
index 0000000..12a3d4d
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/BufferedNotificationsTest.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.entity;
+
+import static org.junit.Assert.assertEquals;
+
+import java.sql.Timestamp;
+
+import org.junit.Test;
+
+public class BufferedNotificationsTest {
+
+ private Timestamp createdAt;
+
+ @Test
+ public void bufferedNotificationsTest() {
+ BufferedNotifications bufferedNotifications=new BufferedNotifications();
+ bufferedNotifications.setClusterId("clusterId");
+ bufferedNotifications.setNotification("notification");
+ bufferedNotifications.setCreatedAt(createdAt);
+ assertEquals("clusterId", bufferedNotifications.getClusterId());
+ assertEquals("notification", bufferedNotifications.getNotification());
+ assertEquals(createdAt, bufferedNotifications.getCreatedAt());
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/entity/CellInfoTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/CellInfoTest.java
new file mode 100644
index 0000000..6732cb6
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/CellInfoTest.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.entity;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class CellInfoTest {
+
+ @Test
+ public void cellInfoTest() {
+ CellInfo cellInfo=new CellInfo();
+ cellInfo.setCellId("cellId");
+ cellInfo.setPnfName("pnfName");
+ assertEquals("cellId", cellInfo.getCellId());
+ assertEquals("pnfName", cellInfo.getPnfName());
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/entity/DmaapNotificationsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/DmaapNotificationsTest.java
new file mode 100644
index 0000000..05ea72e
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/DmaapNotificationsTest.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.entity;
+
+import static org.junit.Assert.assertEquals;
+
+import java.sql.Timestamp;
+
+import org.junit.Test;
+
+public class DmaapNotificationsTest {
+
+ private Timestamp createdAt;
+
+ @Test
+ public void dmaapNotififcationsTest() {
+ DmaapNotifications dmaapNotifications = new DmaapNotifications();
+ dmaapNotifications.setNotification("notification");
+ dmaapNotifications.setCreatedAt(createdAt);
+ assertEquals("notification", dmaapNotifications.getNotification());
+ assertEquals(createdAt, dmaapNotifications.getCreatedAt());
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/entity/PciRequestsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/PciRequestsTest.java
new file mode 100644
index 0000000..bf22fd6
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/PciRequestsTest.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.entity;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class PciRequestsTest {
+
+ @Test
+ public void pciRequestsTest() {
+ PciRequests pciRequests=new PciRequests();
+ pciRequests.setChildThreadId(1L);
+ pciRequests.setTransactionId("transactionId");
+ assertEquals(1L, pciRequests.getChildThreadId());
+ assertEquals("transactionId", pciRequests.getTransactionId());
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellConfigTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellConfigTest.java
new file mode 100644
index 0000000..94f58b1
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellConfigTest.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.model;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class CellConfigTest {
+
+ @Test
+ public void cellConfigTest() {
+
+ Common common = new Common();
+ common.setCellIdentity("cellIdentity");
+ Ran ran = new Ran();
+ ran.setCommon(common);
+ Lte lte = new Lte();
+ lte.setRan(ran);
+ CellConfig cellConfig = new CellConfig();
+ cellConfig.setLte(lte);
+ assertEquals(lte, cellConfig.getLte());
+ assertEquals(ran, lte.getRan());
+ assertEquals(common, ran.getCommon());
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellNeighbourListTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellNeighbourListTest.java
new file mode 100644
index 0000000..d9684dd
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/CellNeighbourListTest.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.model;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class CellNeighbourListTest {
+
+ @Test
+ public void cellNeighbourListTest() {
+ CellNeighbourList cellNeighbourList = new CellNeighbourList();
+ cellNeighbourList.setCellId("cellId");
+ cellNeighbourList.setNeighbours("neighbour");
+ cellNeighbourList.setPhysicalCellId(1);
+ assertEquals("cellId",cellNeighbourList.getCellId() );
+ assertEquals("neighbour",cellNeighbourList.getNeighbours() );
+ assertEquals(1,cellNeighbourList.getPhysicalCellId() );
+
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayloadTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayloadTest.java
new file mode 100644
index 0000000..4505bff
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayloadTest.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.model;
+
+import org.junit.Test;
+
+public class NotificationPayloadTest {
+
+ @Test
+ public void notificationPayloadTest() {
+
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java
new file mode 100644
index 0000000..8ef4778
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.model.FapServiceList;
+import org.onap.dcaegen2.services.sonhms.model.LteNeighborListInUseLteCell;
+import org.onap.dcaegen2.services.sonhms.model.NeighborListInUse;
+import org.onap.dcaegen2.services.sonhms.model.Notification;
+import org.onap.dcaegen2.services.sonhms.model.NotificationCellConfig;
+import org.onap.dcaegen2.services.sonhms.model.NotificationLte;
+import org.onap.dcaegen2.services.sonhms.model.NotificationPayload;
+import org.onap.dcaegen2.services.sonhms.model.NotificationRan;
+import org.onap.dcaegen2.services.sonhms.model.RadioAccess;
+import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte;
+
+public class NotificationTest {
+
+ @Test
+ public void notificationTest() {
+
+ Notification notif = new Notification();
+ LteNeighborListInUseLteCell lteNeighborListInUseLteCell = new LteNeighborListInUseLteCell("pnf1", "true",
+ "Cell10", "true", "123456", "5", 22, "false");
+
+ ArrayList<LteNeighborListInUseLteCell> list = new ArrayList<>();
+ list.add(lteNeighborListInUseLteCell);
+
+ NeighborListInUse neighborListInUse = new NeighborListInUse(list, "1");
+
+ NotificationRan notificationRan = new NotificationRan(neighborListInUse, "Cell25");
+ NotificationLte notificationLte = new NotificationLte(notificationRan);
+ NotificationCellConfig notificationCell = new NotificationCellConfig(notificationLte);
+ X0005b9Lte lte = new X0005b9Lte(126, "pnf2");
+ FapServiceList fap = new FapServiceList("Cell1", lte, notificationCell);
+
+ ArrayList<FapServiceList> al = new ArrayList<>();
+ al.add(fap);
+
+ RadioAccess radioAccess = new RadioAccess("1", al);
+ NotificationPayload payload = new NotificationPayload(radioAccess);
+
+ notif.setRequestId("9d2d790e-a5f0-11e8-98d0-529269fb1459");
+ notif.setAai("{}");
+ notif.setAction("NeighborListModified");
+ notif.setFrom("SDNR");
+ notif.setVersion("1.0.2");
+ notif.setPayload(payload);
+ assertNotEquals("159", notif.getRequestId());
+
+ String test = "{\n" + " \"requestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + " \"AAI\": {},\n"
+ + " \"from\": \"SDNR\",\n" + " \"version\": \"1.0.2\",\n"
+ + " \"Action\": \"NeighborListModified\",\n" + " \"Payload\": {\n" + "\n" + " \"RadioAccess\":{ \n"
+ + " \"FAPServiceNumberOfEntries\":\"2\",\n" + " \"FAPServiceList\":[ \n" + " { \n"
+ + " \"alias\":\"Cell1\",\n" + " \"X0005b9Lte\":{ \n"
+ + " \"phyCellIdInUse\":\"35\",\n" + " \"pnfName\":\"DU-1\"\n"
+ + " },\n" + " \"CellConfig\":{ \n" + " \"LTE\":{ \n"
+ + " \"RAN\":{ \n" + " \"CellIdentity\":\"Cell1\",\n"
+ + " \"NeighborListInUse\":{ \n"
+ + " \"LTECellNumberOfEntries\":\"2\",\n"
+ + " \"LTENeighborListInUseLTECell\":[ \n" + " { \n"
+ + " \"pnfName\":\"DU-2\",\n"
+ + " \"enable\":\"true\",\n"
+ + " \"alias\":\"Cell10\",\n"
+ + " \"mustInclude\":\"true\",\n"
+ + " \"plmnid\":\"123456\",\n"
+ + " \"cid\":\"2\",\n"
+ + " \"phyCellId\":\"22\",\n"
+ + " \"blacklisted\":\"false\"\n" + " },\n"
+ + " { \n" + " \"pnfName\":\"DU-3\",\n"
+ + " \"enable\":\"true\",\n"
+ + " \"alias\":\"Cell15\",\n"
+ + " \"mustInclude\":\"true\",\n"
+ + " \"plmnid\":\"123456\",\n"
+ + " \"cid\":\"5\",\n"
+ + " \"phyCellId\":\"24\",\n"
+ + " \"blacklisted\":\"false\"\n" + " }\n"
+ + " ]\n" + " }\n" + " }\n"
+ + " }\n" + " }\n" + " }\n" + " ]\n" + " }\n" + "}\n" + "}";
+
+ ObjectMapper mapper = new ObjectMapper();
+ Notification notif1 = new Notification();
+ try {
+ notif1 = mapper.readValue(test, Notification.class);
+ } catch (JsonParseException e) {
+ e.printStackTrace();
+ } catch (JsonMappingException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ assertNotEquals(notif, notif1);
+ assertEquals(notif.getAction(), notif1.getAction());
+ assertEquals(notif.getAai().toString(), notif1.getAai().toString());
+
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java
new file mode 100644
index 0000000..a7f0a79
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.model;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.model.CellConfig;
+import org.onap.dcaegen2.services.sonhms.model.Common;
+import org.onap.dcaegen2.services.sonhms.model.Configurations;
+import org.onap.dcaegen2.services.sonhms.model.Data;
+import org.onap.dcaegen2.services.sonhms.model.FapService;
+import org.onap.dcaegen2.services.sonhms.model.Lte;
+import org.onap.dcaegen2.services.sonhms.model.Payload;
+import org.onap.dcaegen2.services.sonhms.model.Ran;
+import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte;
+
+
+
+public class PayloadTest {
+
+ @Test
+ public void payloadTest() {
+ Common common = new Common("cell1");
+
+ Ran ran = new Ran(common);
+
+ Lte lte = new Lte(ran);
+
+ CellConfig cellConfig = new CellConfig(lte);
+
+ X0005b9Lte x0005b9Lte = new X0005b9Lte(0, "pnf2");
+
+ FapService fapService = new FapService("cell6", x0005b9Lte, cellConfig);
+
+ Data data = new Data(fapService);
+
+ Configurations config = new Configurations(data);
+ ArrayList<Configurations> al = new ArrayList<>();
+ al.add(config);
+
+ Payload payload = new Payload(al);
+
+ assertEquals("pnf2", payload.getConfiguration().get(0).getData().getFapservice().getX0005b9Lte().getPnfName());
+
+ assertEquals("cell6", payload.getConfiguration().get(0).getData().getFapservice().getAlias());
+
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotificationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotificationTest.java
new file mode 100644
index 0000000..b99a9d7
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotificationTest.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.model;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest;
+
+public class PolicyNotificationTest {
+ @Test
+ public void policyNotificationTest() {
+ PolicyNotification policyNotification=new PolicyNotification();
+ Map<String, String> aai=new HashMap<>();
+ aai.put("test","test");
+ String target="test";
+ String targetType="targetType";
+ String payload="payload";
+ String closedLoopControlName="closedLoopControlName";
+ String action="action";
+ String version="version";
+ String from="from";
+ String requestId="requestId";
+ String closedLoopEventStatus="closedLoopEventStatus";
+ String closedLoopEventClient="closedLoopEventClient";
+ long closedLoopAlarmStart=96587958;
+ policyNotification.setAai(aai);
+ assertEquals(aai,policyNotification.getAai());
+ policyNotification.setTarget(target);
+ assertEquals(target,policyNotification.getTarget());
+ policyNotification.setTargetType(targetType);
+ assertEquals(targetType,policyNotification.getTargetType());
+ policyNotification.setPayload(payload);
+ assertEquals(payload,policyNotification.getPayload());
+ policyNotification.setClosedLoopControlName(closedLoopControlName);
+ assertEquals(closedLoopControlName,policyNotification.getClosedLoopControlName());
+ policyNotification.setAction(action);
+ assertEquals(action,policyNotification.getAction());
+ policyNotification.setVersion(version);
+ assertEquals(version,policyNotification.getVersion());
+ policyNotification.setFrom(from);
+ assertEquals(from,policyNotification.getFrom());
+ policyNotification.setRequestId(requestId);
+ assertEquals(requestId,policyNotification.getRequestId());
+ policyNotification.setClosedLoopEventStatus(closedLoopEventStatus);
+ assertEquals(closedLoopEventStatus,policyNotification.getClosedLoopEventStatus());
+ policyNotification.setClosedLoopEventClient(closedLoopEventClient);
+ assertEquals(closedLoopEventClient,policyNotification.getClosedLoopEventClient());
+ policyNotification.setClosedLoopAlarmStart(closedLoopAlarmStart);
+ assertEquals(closedLoopAlarmStart,policyNotification.getClosedLoopAlarmStart());
+
+ String notif1 = readFromFile("/policy_notification.json");
+ String notif2 = readFromFile("/policy_notification.json");
+ PolicyNotification policyNotification1 = new PolicyNotification();
+ PolicyNotification policyNotification2 = new PolicyNotification();
+ PolicyNotification policyNotification3 = new PolicyNotification();
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ policyNotification1 = mapper.readValue(notif1, PolicyNotification.class);
+ policyNotification2 = mapper.readValue(notif2, PolicyNotification.class);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ Assert.assertEquals(policyNotification1.hashCode(), policyNotification2.hashCode());
+ Assert.assertNotEquals(policyNotification1.hashCode(), policyNotification3.hashCode());
+
+ }
+
+ private static String readFromFile(String file) {
+ String content = new String();
+ try {
+
+ InputStream is = ClusterUtilsTest.class.getResourceAsStream(file);
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
+ content = bufferedReader.readLine();
+ String temp;
+ while((temp = bufferedReader.readLine()) != null) {
+ content = content.concat(temp);
+ }
+ content = content.trim();
+ bufferedReader.close();
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ content = null;
+ }
+ return content;
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/ResponseTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/ResponseTest.java
new file mode 100644
index 0000000..0fcdb1b
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/ResponseTest.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.model;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class ResponseTest {
+
+ @Test
+ public void respomseTest() {
+ Response response = new Response();
+ response.setCellId("cellId");
+ response.setPci(1);
+ assertEquals("cellId", response.getCellId());
+ assertEquals(1, response.getPci());
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponseTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponseTest.java
new file mode 100644
index 0000000..a65f51b
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponseTest.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.model;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+public class SdnrResponseTest {
+
+ @Test
+ public void sdnrResponseTest() {
+ SdnrResponse sdnrResponse=new SdnrResponse();
+ Response response=new Response();
+ response.setCellId("cellId");
+ response.setPci(2);
+ List<Response> responseList=new ArrayList<>();
+ responseList.add(response);
+ sdnrResponse.setResponse(responseList);
+ assertEquals(responseList,sdnrResponse.getResponse());
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/model/ThreadIdTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/model/ThreadIdTest.java
new file mode 100644
index 0000000..ad23c3a
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/ThreadIdTest.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.model;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class ThreadIdTest {
+
+ @Test
+ public void threadIdtest() {
+ ThreadId threadId=new ThreadId();
+ long Id=987957948;
+ threadId.setChildThreadId(Id);
+ assertEquals(Id,threadId.getChildThreadId());
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBodyTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBodyTest.java
new file mode 100644
index 0000000..085abbb
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBodyTest.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.restclient;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody;
+import org.onap.dcaegen2.services.sonhms.restclient.Solution;
+import org.onap.dcaegen2.services.sonhms.restclient.SonSolution;
+
+
+
+public class AsyncResponseBodyTest {
+
+ @Test
+ public void asyncResponseBodyTest() {
+ AsyncResponseBody asyncResponseBody = new AsyncResponseBody();
+ asyncResponseBody.setRequestId("e44a4165-3cf4-4362-89de-e2375eed97e7");
+ asyncResponseBody.setRequestStatus("completed");
+ SonSolution pciSolutions = new SonSolution();
+ pciSolutions.setCellId("EXP001");
+ pciSolutions.setPci(101);
+ List<SonSolution> pciSolutionsList = new ArrayList<SonSolution>();
+ pciSolutionsList.add(pciSolutions);
+ Solution solutions = new Solution();
+ solutions.setFinishTime("2018-10-01T00:40+01.00");
+ solutions.setNetworkId("EXP001");
+ solutions.setPciSolutions(pciSolutionsList);
+ solutions.setStartTime("2018-10-01T00:30+01:00");
+ ArrayList<Solution> solutionsList = new ArrayList<Solution>();
+ solutionsList.add(solutions);
+ asyncResponseBody.setSolutions(solutionsList);
+ asyncResponseBody.setStatusMessage("success");
+ asyncResponseBody.setTransactionId("3df7b0e9-26d1-4080-ba42-28e8a3139689");
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfoTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfoTest.java
new file mode 100644
index 0000000..24ba1ae
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfoTest.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.restclient;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.restclient.CellInfo;
+
+
+public class CellInfoTest {
+ @Test
+ public void cellInfoTest() {
+ List<String> cellIdLists = new ArrayList<>();
+ cellIdLists.add("cell1");
+
+ CellInfo cellInfo = new CellInfo();
+ cellInfo.setNetworkId("NTWK001");
+ cellInfo.setCellIdList(cellIdLists);
+ assertEquals("NTWK001", cellInfo.getNetworkId());
+ assertEquals(cellIdLists, cellInfo.getCellIdList());
+
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBodyTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBodyTest.java
new file mode 100644
index 0000000..eb0d189
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBodyTest.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.restclient;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.restclient.CellInfo;
+import org.onap.dcaegen2.services.sonhms.restclient.OofRequestBody;
+import org.onap.dcaegen2.services.sonhms.restclient.RequestInfo;
+
+
+
+public class OofRequestBodyTest {
+ @Test
+ public void oofRequestBodyTest() {
+
+ List<String> cellIdLists = new ArrayList<>();
+ cellIdLists.add("cell1");
+ CellInfo cellInfo = new CellInfo();
+ cellInfo.setNetworkId("NTWK001");
+ cellInfo.setCellIdList(cellIdLists);
+ RequestInfo requestInfo = new RequestInfo();
+ List<String> optimizers = new ArrayList<String>();
+ optimizers.add("PCI");
+ requestInfo.setCallbackUrl("");
+ requestInfo.setNumSolutions(1);
+ requestInfo.setOptimizers(optimizers);
+ requestInfo.setRequestId("e44a4165-3cf4-4362-89de-e2375eed97e7");
+ requestInfo.setRequestType("create");
+ requestInfo.setSourceId("PCIHMS");
+ requestInfo.setTimeout(60);
+ requestInfo.setTransactionId("3df7b0e9-26d1-4080-ba42-28e8a3139689");
+
+ OofRequestBody oofRequestBody = new OofRequestBody();
+ oofRequestBody.setCellInfo(cellInfo);
+ oofRequestBody.setRequestInfo(requestInfo);
+ assertEquals(requestInfo, oofRequestBody.getRequestInfo());
+ assertEquals(cellInfo, oofRequestBody.getCellInfo());
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClientTest.java
new file mode 100644
index 0000000..4a9fed5
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClientTest.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.restclient;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.dcaegen2.services.sonhms.Configuration;
+import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException;
+import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate;
+import org.powermock.api.mockito.PowerMockito;
+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;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(SpringRunner.class)
+@PrepareForTest({ SonHandlerRestTemplate.class,Configuration.class })
+@SpringBootTest(classes = OofRestClientTest.class)
+public class OofRestClientTest {
+ Configuration configuration = Configuration.getInstance();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void queryOofTest() {
+ configuration.setBufferTime(60);
+ configuration.setCallbackUrl("/callbackUrl");
+ configuration.setConfigName("configName");
+ List<String> list = new ArrayList<String>();
+ list.add("server");
+ configuration.setServers(list);
+ configuration.setCg("cg");
+ configuration.setCid("cid");
+ configuration.setManagerApiKey("managerApiKey");
+ configuration.setManagerSecretKey("managerSecretKey");
+ configuration.setMaximumClusters(5);
+ configuration.setMinCollision(5);
+ configuration.setMinConfusion(5);
+ configuration.setNumSolutions(1);
+ configuration.setOofService("oofService");
+ configuration.setOptimizers(list);
+ configuration.setPcimsApiKey("pcimsApiKey");
+ configuration.setPcimsSecretKey("pcimsSecretKey");
+ configuration.setPolicyName("policyName");
+ configuration.setPolicyService("policyService");
+ configuration.setPolicyTopic("policyTopic");
+ configuration.setPollingInterval(30);
+ configuration.setPollingTimeout(100);
+ configuration.setSdnrService("sdnrService");
+ configuration.setSdnrTopic("sdnrTopic");
+ configuration.setSourceId("sourceId");
+ String responseBody="{\n" +
+ " \"transactionId\": \"xxx-xxx-xxxx\",\n" +
+ " \"requestId\": \"yyy-yyy-yyyy\",\n" +
+ " \"requestStatus\": \"accepted\",\n" +
+ " \"statusMessage\": \"\"\n" +
+ "}";
+ List<String> cellIdList=new ArrayList<String>();
+ cellIdList.add("EXP001");
+ List<String> optimizers=new ArrayList<String>();
+ optimizers.add("pci");
+
+ PowerMockito.mockStatic(SonHandlerRestTemplate.class);
+ PowerMockito.mockStatic(Configuration.class);
+ PowerMockito.when(Configuration.getInstance()).thenReturn(configuration);
+ PowerMockito.when(SonHandlerRestTemplate.sendPostRequestToOof(Mockito.anyString(),Mockito.anyString() ,Matchers.<ParameterizedTypeReference<String>>any()))
+ .thenReturn(ResponseEntity.ok(responseBody));
+
+
+ try {
+ String result=OofRestClient.queryOof(1, "xxx-xxx-xxxx", "create", cellIdList, "NTWK005", optimizers);
+ assertEquals(ResponseEntity.ok(responseBody).getBody(), result);
+
+
+ } catch (OofNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ PowerMockito.when(SonHandlerRestTemplate.sendPostRequestToOof(Mockito.anyString(),Mockito.anyString() ,Matchers.<ParameterizedTypeReference<String>>any()))
+ .thenReturn(null);
+ try {
+ String result=OofRestClient.queryOof(1, "xxx-xxx-xxxx", "create", cellIdList, "NTWK005", optimizers);
+ assertEquals(ResponseEntity.ok(responseBody).getBody(), result);
+
+
+ } catch (OofNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ }
+
+}
+
+
+
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutionsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutionsTest.java
new file mode 100644
index 0000000..4f59435
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutionsTest.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.restclient;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.restclient.SonSolution;
+
+
+public class PciSolutionsTest {
+ @Test
+ public void pciSolutionsTest() {
+ SonSolution pciSolutions = new SonSolution();
+ pciSolutions.setCellId("EXP001");
+ pciSolutions.setPci(101);
+ assertEquals("EXP001", pciSolutions.getCellId());
+ assertEquals(101, pciSolutions.getPci());
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBodyTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBodyTest.java
new file mode 100644
index 0000000..5de8951
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBodyTest.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.restclient;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.restclient.PolicyRequestBody;
+
+
+public class PolicyRequestBodyTest {
+ @Test
+ public void policyRequestBodyTest() {
+ PolicyRequestBody policyRequestBody = new PolicyRequestBody();
+ policyRequestBody.setConfigName("PCIMS_CONFIG_POLICY");
+ policyRequestBody.setPolicyName("com.PCIMS_CONFIG_POLICY");
+ policyRequestBody.setRequestId("60fe7fe6-2649-4f6c-8468-30eb03fd0527");
+ assertEquals("PCIMS_CONFIG_POLICY", policyRequestBody.getConfigName());
+ assertEquals("com.PCIMS_CONFIG_POLICY", policyRequestBody.getPolicyName());
+ assertEquals("60fe7fe6-2649-4f6c-8468-30eb03fd0527", policyRequestBody.getRequestId());
+
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRestClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRestClientTest.java
new file mode 100644
index 0000000..387b958
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRestClientTest.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.restclient;
+
+import static org.junit.Assert.assertEquals;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.dcaegen2.services.sonhms.Configuration;
+import org.onap.dcaegen2.services.sonhms.restclient.PolicyRestClient;
+import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate;
+import org.powermock.api.mockito.PowerMockito;
+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;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(SpringRunner.class)
+@PrepareForTest({ SonHandlerRestTemplate.class, Configuration.class })
+@SpringBootTest(classes = PolicyRestClientTest.class)
+public class PolicyRestClientTest {
+
+ Configuration configuration = Configuration.getInstance();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void fetchConfigFromPolicyTest() {
+
+ configuration.setBufferTime(60);
+ configuration.setCallbackUrl("/callbackUrl");
+ configuration.setConfigName("configName");
+ List<String> list = new ArrayList<String>();
+ list.add("server");
+ configuration.setServers(list);
+ configuration.setCg("cg");
+ configuration.setCid("cid");
+ configuration.setManagerApiKey("managerApiKey");
+ configuration.setManagerSecretKey("managerSecretKey");
+ configuration.setMaximumClusters(5);
+ configuration.setMinCollision(5);
+ configuration.setMinConfusion(5);
+ configuration.setNumSolutions(1);
+ configuration.setOofService("oofService");
+ configuration.setOptimizers(list);
+ configuration.setPcimsApiKey("pcimsApiKey");
+ configuration.setPcimsSecretKey("pcimsSecretKey");
+ configuration.setPolicyName("policyName");
+ configuration.setPolicyService("policyService");
+ configuration.setPolicyTopic("policyTopic");
+ configuration.setPollingInterval(30);
+ configuration.setPollingTimeout(100);
+ configuration.setSdnrService("sdnrService");
+ configuration.setSdnrTopic("sdnrTopic");
+ configuration.setSourceId("sourceId");
+ String responseBody="{\n" +
+ "\"policyName\": \"com.Config_PCIMS_CONFIG_POLICY\",\n" +
+ "\"policyVersion\": \"1\",\n" +
+ "\"configBody\": \"{ \\\"PCI_NEIGHBOR_CHANGE_CLUSTER_TIMEOUT_IN_SECS\\\":60,\n" +
+ "\\\"PCI_MODCONFIG_POLICY_NAME\\\":\\\"ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-\n" +
+ "529269fb1459\\\", \\\"PCI_OPTMIZATION_ALGO_CATEGORY_IN_OOF\\\":\\\"OOF-PCI-\n" +
+ "OPTIMIZATION\\\", \\\"PCI_SDNR_TARGET_NAME\\\":\\\"SDNR\\\" }\",\n" +
+ "\"policyClass\": \"Config\",\n" +
+ "\"policyConfigType\": \"Base\",\n" +
+ "\"ttlDate\": \"2018-08-29T06:28:16.830Z\",\n" +
+ "\"onapName\": \"DCAE\",\n" +
+ "\"configName\": \"PCIMS_CONFIG_POLICY\",\n" +
+ "\"configBodyType\": \"JSON\"\n" +
+ "}\n" +
+ "";
+ PowerMockito.mockStatic(SonHandlerRestTemplate.class);
+ PowerMockito.mockStatic(Configuration.class);
+ PowerMockito.when(Configuration.getInstance()).thenReturn(configuration);
+
+ PowerMockito.when(SonHandlerRestTemplate.sendPostToPolicy(Mockito.anyString(),Mockito.anyString() ,Matchers.<ParameterizedTypeReference<String>>any()))
+ .thenReturn(ResponseEntity.ok(responseBody));
+ String result=PolicyRestClient.fetchConfigFromPolicy();
+ assertEquals(ResponseEntity.ok(responseBody).getBody(), result);
+
+
+
+
+
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfoTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfoTest.java
new file mode 100644
index 0000000..4d360d8
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfoTest.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.restclient;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.restclient.RequestInfo;
+
+
+public class RequestInfoTest {
+ @Test
+ public void requestInfoTest() {
+ RequestInfo requestInfo = new RequestInfo();
+ List<String> optimizers = new ArrayList<String>();
+ optimizers.add("PCI");
+ requestInfo.setCallbackUrl("");
+ requestInfo.setNumSolutions(1);
+ requestInfo.setOptimizers(optimizers);
+ requestInfo.setRequestId("e44a4165-3cf4-4362-89de-e2375eed97e7");
+ requestInfo.setRequestType("create");
+ requestInfo.setSourceId("PCIHMS");
+ requestInfo.setTimeout(60);
+ requestInfo.setTransactionId("3df7b0e9-26d1-4080-ba42-28e8a3139689");
+ assertEquals(1, requestInfo.getNumSolutions());
+ assertEquals(optimizers, requestInfo.getOptimizers());
+ assertEquals("create", requestInfo.getRequestType());
+ assertEquals("PCIHMS", requestInfo.getSourceId());
+ assertEquals("3df7b0e9-26d1-4080-ba42-28e8a3139689", requestInfo.getTransactionId());
+ assertEquals("e44a4165-3cf4-4362-89de-e2375eed97e7", requestInfo.getRequestId());
+ assertEquals(60, requestInfo.getTimeout());
+ assertEquals("", requestInfo.getCallbackUrl());
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java
new file mode 100644
index 0000000..c13b698
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.restclient;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.dcaegen2.services.sonhms.Configuration;
+import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
+import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
+import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate;
+import org.powermock.api.mockito.PowerMockito;
+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.slf4j.Logger;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(SpringRunner.class)
+@PrepareForTest({ SonHandlerRestTemplate.class,Configuration.class })
+@SpringBootTest(classes = SdnrRestClientTest.class)
+public class SdnrRestClientTest {
+
+ Configuration configuration = Configuration.getInstance();
+ private static final Logger log = org.slf4j.LoggerFactory.getLogger(SdnrRestClient.class);
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void getCellListTest() {
+
+ String responseBody="[\n" +
+ " \"string\"\n" +
+ "]";
+ PowerMockito.mockStatic(SonHandlerRestTemplate.class);
+ PowerMockito.mockStatic(Configuration.class);
+ PowerMockito.when(Configuration.getInstance()).thenReturn(configuration);
+ PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any()))
+ .thenReturn(ResponseEntity.ok(responseBody));
+ try {
+ String result=SdnrRestClient.getCellList("12345");
+ assertEquals(ResponseEntity.ok(responseBody).getBody(),result);
+ } catch (ConfigDbNotFoundException e) {
+ log.debug("ConfigDbNotFoundException {}",e.toString());;
+ }
+
+ }
+
+ @Test
+ public void getNbrListTest() {
+
+ String responseBody="[\n" +
+ " {\n" +
+ " \"cellId\": \"string\",\n" +
+ " \"pciValue\": 0\n" +
+ " }\n" +
+ "]";
+ PowerMockito.mockStatic(SonHandlerRestTemplate.class);
+ PowerMockito.mockStatic(Configuration.class);
+ PowerMockito.when(Configuration.getInstance()).thenReturn(configuration);
+ PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any()))
+ .thenReturn(ResponseEntity.ok(responseBody));
+ try {
+ List<CellPciPair> result=SdnrRestClient.getNbrList("1");
+ List<CellPciPair> nbrList = new ArrayList<>();
+ String response=ResponseEntity.ok(responseBody).getBody();
+ JSONArray nbrListObj = new JSONArray(response);
+ for (int i = 0; i < nbrListObj.length(); i++) {
+ JSONObject cellObj = nbrListObj.getJSONObject(i);
+ CellPciPair cell = new CellPciPair(cellObj.getString("cellId"), cellObj.getInt("pciValue"));
+ nbrList.add(cell);
+ }
+ assertEquals(nbrList,result);
+ } catch (ConfigDbNotFoundException e) {
+ log.debug("ConfigDbNotFoundException {}",e.toString());;
+ }
+
+ }
+ @Test
+ public void getPciTest() {
+
+ String responseBody="{\n" +
+ " \"attribute-name\": \"string\",\n" +
+ " \"value\": 0\n" +
+ "}";
+ PowerMockito.mockStatic(SonHandlerRestTemplate.class);
+ PowerMockito.mockStatic(Configuration.class);
+ PowerMockito.when(Configuration.getInstance()).thenReturn(configuration);
+ PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any()))
+ .thenReturn(ResponseEntity.ok(responseBody));
+ try {
+ int result=SdnrRestClient.getPci("1");
+ String response=ResponseEntity.ok(responseBody).getBody();
+ JSONObject respObj = new JSONObject(response);
+ assertEquals(respObj.getInt("value"),result);
+ } catch (ConfigDbNotFoundException e) {
+ log.debug("ConfigDbNotFoundException {}",e.toString());;
+ }
+
+ }
+ @Test
+ public void getPnfNameTest() {
+
+ String responseBody="{\n" +
+ " \"attribute-name\": \"string\",\n" +
+ " \"value\": \"string\"\n" +
+ "}";
+ PowerMockito.mockStatic(SonHandlerRestTemplate.class);
+ PowerMockito.mockStatic(Configuration.class);
+ PowerMockito.when(Configuration.getInstance()).thenReturn(configuration);
+ PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any()))
+ .thenReturn(ResponseEntity.ok(responseBody));
+ try {
+ String result=SdnrRestClient.getPnfName("1");
+ String response=ResponseEntity.ok(responseBody).getBody();
+ JSONObject respObj = new JSONObject(response);
+ assertEquals(respObj.getString("value"),result);
+ } catch (ConfigDbNotFoundException e) {
+ log.debug("ConfigDbNotFoundException {}",e.toString());;
+ }
+
+ }
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SolutionsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SolutionsTest.java
new file mode 100644
index 0000000..9decce0
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SolutionsTest.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.restclient;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.onap.dcaegen2.services.sonhms.restclient.Solution;
+import org.onap.dcaegen2.services.sonhms.restclient.SonSolution;
+
+
+
+public class SolutionsTest {
+
+ @Test
+ public void solutionsTest() {
+
+ SonSolution pciSolutions = new SonSolution();
+ pciSolutions.setCellId("EXP001");
+ pciSolutions.setPci(101);
+ List<SonSolution> pciSolutionsList = new ArrayList<SonSolution>();
+ pciSolutionsList.add(pciSolutions);
+ Solution solutions = new Solution();
+ solutions.setFinishTime("2018-10-01T00:40+01.00");
+ solutions.setNetworkId("EXP001");
+ solutions.setPciSolutions(pciSolutionsList);
+ solutions.setStartTime("2018-10-01T00:30+01:00");
+ assertEquals("2018-10-01T00:40+01.00", solutions.getFinishTime());
+ assertEquals("EXP001", solutions.getNetworkId());
+ assertEquals(pciSolutionsList, solutions.getPciSolutions());
+ assertEquals("2018-10-01T00:30+01:00", solutions.getStartTime());
+
+ }
+
+}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java
new file mode 100644
index 0000000..dd3059a
--- /dev/null
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java
@@ -0,0 +1,270 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * son-handler
+ * ================================================================================
+ * Copyright (C) 2019 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.dcaegen2.services.sonhms.utils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.dcaegen2.services.sonhms.NotificationToClusterMapping;
+import org.onap.dcaegen2.services.sonhms.child.Graph;
+import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository;
+import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails;
+import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
+import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
+import org.onap.dcaegen2.services.sonhms.model.FapServiceList;
+import org.onap.dcaegen2.services.sonhms.model.Notification;
+import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
+import org.powermock.api.mockito.PowerMockito;
+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.test.context.junit4.SpringRunner;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import fj.data.Either;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockRunnerDelegate(SpringRunner.class)
+@PrepareForTest({ SdnrRestClient.class, BeanUtil.class })
+@SpringBootTest(classes = ClusterUtils.class)
+public class ClusterUtilsTest {
+
+ @Mock
+ private ClusterDetailsRepository clusterDetailsRepositoryMock;
+
+ @InjectMocks
+ ClusterUtils clusterUtils;
+
+ private static Notification notification1;
+ private static Notification notification2;
+ private static List<ClusterDetails> clusterDetailsForGetClusterDetailsFromClusterIdTest;
+ private static Graph cluster;
+ private static List<ClusterDetails> clusterDetails = new ArrayList<>();
+
+ @BeforeClass
+ public static void setup() {
+
+ notification1 = new Notification();
+ notification2 = new Notification();
+ clusterDetailsForGetClusterDetailsFromClusterIdTest = new ArrayList<ClusterDetails>();
+
+ String notificationString1 = readFromFile("/notification1.json");
+ String notificationString2 = readFromFile("/notification2.json");
+ String clusterDetailsListString=readFromFile("/ClusterDetailsTest.json");
+
+ String clusterInfo1 = readFromFile("/clusterInfo1.json");
+ String clusterInfo2 = readFromFile("/clusterInfo2.json");
+ String clusterInfo3 = readFromFile("/clusterInfo3.json");
+ String clusterInfo4 = readFromFile("/clusterInfo4.json");
+ String clusterInfo = readFromFile("/clusterInfo5.json");
+ cluster=new Graph(clusterInfo);
+
+ clusterDetails.add(new ClusterDetails("1", clusterInfo1, 35));
+ clusterDetails.add(new ClusterDetails("2", clusterInfo2, 36));
+ clusterDetails.add(new ClusterDetails("3", clusterInfo3, 37));
+ clusterDetails.add(new ClusterDetails("4", clusterInfo4, 38));
+
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ notification1 = mapper.readValue(notificationString1, Notification.class);
+ notification2 = mapper.readValue(notificationString2, Notification.class);
+ clusterDetailsForGetClusterDetailsFromClusterIdTest=mapper.readValue(clusterDetailsListString,new TypeReference<List<ClusterDetails>>(){});
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+
+ }
+
+ @Before
+ public void setupTest() {
+ clusterUtils = new ClusterUtils();
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void getClustersForNotificationTest(){
+
+ NotificationToClusterMapping expected = new NotificationToClusterMapping();
+ Map<FapServiceList, String> cellsinCluster = new HashMap<>();
+ cellsinCluster.put(notification1.getPayload().getRadioAccess().getFapServiceList().get(0), "2");
+ expected.setCellsinCluster(cellsinCluster);
+ expected.setNewCells(new ArrayList<FapServiceList>());
+
+ NotificationToClusterMapping result = clusterUtils.getClustersForNotification(notification1, clusterDetails);
+ assertEquals(expected, result);
+
+ expected = new NotificationToClusterMapping();
+ List<FapServiceList> newCells = new ArrayList<>();
+ newCells.add(notification2.getPayload().getRadioAccess().getFapServiceList().get(0));
+ expected.setCellsinCluster(new HashMap<>());
+ expected.setNewCells(newCells);
+
+ result = clusterUtils.getClustersForNotification(notification2, clusterDetails);
+ assertEquals(expected, result);
+ }
+
+ @Test
+ public void createClusterTest() throws ConfigDbNotFoundException {
+
+ FapServiceList fapServiceList = notification1.getPayload().getRadioAccess().getFapServiceList().get(0);
+
+ List<CellPciPair> nbrList = new ArrayList<>();
+
+ nbrList.add(new CellPciPair("44", 3));
+
+ PowerMockito.mockStatic(SdnrRestClient.class);
+
+ PowerMockito.when(SdnrRestClient.getNbrList(Mockito.anyString())).thenReturn(nbrList);
+
+ assertEquals(cluster, clusterUtils.createCluster(fapServiceList));
+
+
+
+ }
+
+ @Test
+ public void getClusterDetailsFromClusterIdTest() {
+ ClusterDetails responseValue=null;
+ Integer responseVal = null;
+ Integer expectedValue=404;
+ Either<ClusterDetails, Integer> response=clusterUtils.getClusterDetailsFromClusterId("0",clusterDetailsForGetClusterDetailsFromClusterIdTest);
+ assertTrue(response.isLeft());
+ if(response.isLeft()) {
+ responseValue=response.left().value();
+ }
+ assertEquals(clusterDetailsForGetClusterDetailsFromClusterIdTest.get(0),responseValue);
+ response=clusterUtils.getClusterDetailsFromClusterId("1",clusterDetailsForGetClusterDetailsFromClusterIdTest);
+ assertTrue(response.isLeft());
+ if(response.isLeft()) {
+ responseValue=response.left().value();
+ }
+ assertEquals(clusterDetailsForGetClusterDetailsFromClusterIdTest.get(1),responseValue);
+ response=clusterUtils.getClusterDetailsFromClusterId("9",clusterDetailsForGetClusterDetailsFromClusterIdTest);
+ assertTrue(response.isRight());
+ if(response.isRight()) {
+ responseVal=response.right().value();
+ }
+ assertEquals(expectedValue,responseVal);
+
+ }
+
+ @Test
+ public void saveClusterTest() {
+ ClusterDetails details = new ClusterDetails();
+ details.setClusterId("123e4567-e89b-12d3-a456-426655440000");
+ details.setClusterInfo("cellPciNeighbourString");
+ details.setChildThreadId(978668);
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.when(BeanUtil.getBean(ClusterDetailsRepository.class))
+ .thenReturn(clusterDetailsRepositoryMock);
+ Mockito.when(clusterDetailsRepositoryMock.save(details)).thenReturn(details);
+ Long threadId=(long) 978668;
+ clusterUtils.saveCluster(cluster, UUID.fromString("123e4567-e89b-12d3-a456-426655440000"),threadId);
+ assertEquals(details, clusterDetailsRepositoryMock.save(details));
+
+ }
+
+ @Test
+ public void getClusterForCellTest() {
+ FapServiceList fapServiceList= notification1.getPayload().getRadioAccess().getFapServiceList().get(0);
+ String clusterInfo1=readFromFile("/clusterInfo1.json");
+ String clusterInfo2=readFromFile("/clusterInfo2.json");
+ Graph graph1=new Graph(clusterInfo1);
+ Graph graph2=new Graph(clusterInfo2);
+ List<Graph> newClusters=new ArrayList<Graph>();
+ newClusters.add(graph1);
+ newClusters.add(graph2);
+ Either<Graph, Integer> result=clusterUtils.getClusterForCell(fapServiceList, newClusters);
+ assertTrue(result.isLeft());
+
+ newClusters = new ArrayList<>();
+ newClusters.add(graph1);
+ result=clusterUtils.getClusterForCell(fapServiceList, newClusters);
+ assertTrue(result.isRight());
+ int resultRight=result.right().value();
+ assertEquals(404, resultRight);
+
+ List<Graph> emptyList=new ArrayList<Graph>();
+
+ result=clusterUtils.getClusterForCell(fapServiceList, emptyList);
+ assertTrue(result.isRight());
+ resultRight=result.right().value();
+ assertEquals(404, resultRight);
+
+ }
+
+ @Test
+ public void modifyClusterTest() {
+
+ String clusterInfo = readFromFile("/clusterInfo2.json");
+ String clusterInfo2 = readFromFile("/clusterInfo6.json");
+
+ Graph cluster = new Graph(clusterInfo);
+ Graph expected = new Graph(clusterInfo2);
+
+ assertEquals(expected, clusterUtils.modifyCluster(cluster, notification1.getPayload().getRadioAccess().getFapServiceList().get(0)));
+ }
+
+ private static String readFromFile(String file) {
+ String content = new String();
+ try {
+
+ InputStream is = ClusterUtilsTest.class.getResourceAsStream(file);
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
+ content = bufferedReader.readLine();
+ String temp;
+ while((temp = bufferedReader.readLine()) != null) {
+ content = content.concat(temp);
+ }
+ content = content.trim();
+ bufferedReader.close();
+ }
+ catch(Exception e) {
+ content = null;
+ }
+ return content;
+ }
+}