From 3cd4023832810e8b65f85a9db807c8bafec38d82 Mon Sep 17 00:00:00 2001 From: ramya Date: Mon, 11 Mar 2019 17:34:41 +0530 Subject: code coverage for M3 Change-Id: Ib421ce2ac9357a3210d99293497f9e304f8cd2f5 Issue-ID: DCAEGEN2-1259 Signed-off-by: Ramya Ravichandran --- .../java/com/wipro/www/sonhms/ApplicationTest.java | 24 -- .../sonhms/BufferNotificationComponentTest.java | 115 --------- .../www/sonhms/ChildStatusUpdateStateTest.java | 25 -- .../www/sonhms/ClusterDetailsComponentTest.java | 118 --------- .../com/wipro/www/sonhms/ConfigPolicyTest.java | 43 ---- .../com/wipro/www/sonhms/ConfigurationTest.java | 88 ------- .../sonhms/SdnrNotificationHandlingStateTest.java | 31 --- .../java/com/wipro/www/sonhms/SonContextTest.java | 59 ----- .../java/com/wipro/www/sonhms/WaitStateTest.java | 24 -- .../java/com/wipro/www/sonhms/child/GraphTest.java | 63 ----- .../www/sonhms/child/TestClusterModification.java | 188 -------------- .../com/wipro/www/sonhms/child/TestDetection.java | 117 --------- .../com/wipro/www/sonhms/model/CellConfigTest.java | 44 ---- .../www/sonhms/model/CellNeighbourListTest.java | 41 ---- .../www/sonhms/model/NotificationPayloadTest.java | 32 --- .../wipro/www/sonhms/model/NotificationTest.java | 127 ---------- .../com/wipro/www/sonhms/model/PayloadTest.java | 71 ------ .../com/wipro/www/sonhms/model/ResponseTest.java | 38 --- .../sonhms/restclient/AsyncResponseBodyTest.java | 57 ----- .../wipro/www/sonhms/restclient/CellInfoTest.java | 45 ---- .../www/sonhms/restclient/OofRequestBodyTest.java | 62 ----- .../www/sonhms/restclient/OofRestClientTest.java | 25 -- .../www/sonhms/restclient/PciSolutionsTest.java | 40 --- .../sonhms/restclient/PolicyRequestBodyTest.java | 43 ---- .../www/sonhms/restclient/RequestInfoTest.java | 57 ----- .../wipro/www/sonhms/restclient/SolutionsTest.java | 55 ----- .../dcaegen2/services/sonhms/ApplicationTest.java | 25 ++ .../sonhms/BufferNotificationComponentTest.java | 105 ++++++++ .../sonhms/ClusterDetailsComponentTest.java | 108 +++++++++ .../dcaegen2/services/sonhms/ConfigPolicyTest.java | 43 ++++ .../services/sonhms/ConfigurationTest.java | 89 +++++++ .../sonhms/DmaapNotificationsComponentTest.java | 108 +++++++++ .../dcaegen2/services/sonhms/EventHandlerTest.java | 150 ++++++++++++ .../dcaegen2/services/sonhms/MainThreadTest.java | 26 ++ .../onap/dcaegen2/services/sonhms/TopicTest.java | 41 ++++ .../dcaegen2/services/sonhms/child/GraphTest.java | 64 +++++ .../sonhms/child/TestChildThreadUtils.java | 111 +++++++++ .../services/sonhms/child/TestDetection.java | 117 +++++++++ .../services/sonhms/child/TestPnfUtils.java | 157 ++++++++++++ .../services/sonhms/dmaap/DmaapClientTest.java | 112 +++++++++ .../sonhms/dmaap/NotificationProducerTest.java | 71 ++++++ .../sonhms/entity/BufferedNotificationsTest.java | 44 ++++ .../services/sonhms/entity/CellInfoTest.java | 38 +++ .../sonhms/entity/DmaapNotificationsTest.java | 43 ++++ .../services/sonhms/entity/PciRequestsTest.java | 38 +++ .../services/sonhms/model/CellConfigTest.java | 45 ++++ .../sonhms/model/CellNeighbourListTest.java | 42 ++++ .../sonhms/model/NotificationPayloadTest.java | 33 +++ .../services/sonhms/model/NotificationTest.java | 128 ++++++++++ .../services/sonhms/model/PayloadTest.java | 71 ++++++ .../sonhms/model/PolicyNotificationTest.java | 121 +++++++++ .../services/sonhms/model/ResponseTest.java | 39 +++ .../services/sonhms/model/SdnrResponseTest.java | 44 ++++ .../services/sonhms/model/ThreadIdTest.java | 38 +++ .../sonhms/restclient/AsyncResponseBodyTest.java | 57 +++++ .../services/sonhms/restclient/CellInfoTest.java | 45 ++++ .../sonhms/restclient/OofRequestBodyTest.java | 62 +++++ .../sonhms/restclient/OofRestClientTest.java | 131 ++++++++++ .../sonhms/restclient/PciSolutionsTest.java | 40 +++ .../sonhms/restclient/PolicyRequestBodyTest.java | 43 ++++ .../sonhms/restclient/PolicyRestClientTest.java | 117 +++++++++ .../sonhms/restclient/RequestInfoTest.java | 57 +++++ .../sonhms/restclient/SdnrRestClientTest.java | 158 ++++++++++++ .../services/sonhms/restclient/SolutionsTest.java | 56 +++++ .../services/sonhms/utils/ClusterUtilsTest.java | 270 +++++++++++++++++++++ src/test/resources/ClusterDetailsTest.json | 10 + src/test/resources/clusterInfo1.json | 1 + src/test/resources/clusterInfo2.json | 1 + src/test/resources/clusterInfo3.json | 1 + src/test/resources/clusterInfo4.json | 1 + src/test/resources/clusterInfo5.json | 1 + src/test/resources/clusterInfo6.json | 1 + src/test/resources/clusterInfo7.json | 1 + src/test/resources/notification1.json | 45 ++++ src/test/resources/notification2.json | 55 +++++ src/test/resources/notification3.json | 45 ++++ src/test/resources/policy_notification.json | 20 ++ src/test/resources/solutions.json | 1 + 78 files changed, 3270 insertions(+), 1632 deletions(-) delete mode 100644 src/test/java/com/wipro/www/sonhms/ApplicationTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/BufferNotificationComponentTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/ChildStatusUpdateStateTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/ClusterDetailsComponentTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/ConfigPolicyTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/ConfigurationTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/SdnrNotificationHandlingStateTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/SonContextTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/WaitStateTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/child/GraphTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/child/TestClusterModification.java delete mode 100644 src/test/java/com/wipro/www/sonhms/child/TestDetection.java delete mode 100644 src/test/java/com/wipro/www/sonhms/model/CellConfigTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/model/CellNeighbourListTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/model/NotificationPayloadTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/model/NotificationTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/model/PayloadTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/model/ResponseTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/restclient/AsyncResponseBodyTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/restclient/CellInfoTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/restclient/OofRequestBodyTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/restclient/OofRestClientTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/restclient/PciSolutionsTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/restclient/PolicyRequestBodyTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/restclient/RequestInfoTest.java delete mode 100644 src/test/java/com/wipro/www/sonhms/restclient/SolutionsTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/ApplicationTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/ConfigPolicyTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/MainThreadTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/TopicTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/child/GraphTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/child/TestDetection.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClientTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducerTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/entity/BufferedNotificationsTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/entity/CellInfoTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/entity/DmaapNotificationsTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/entity/PciRequestsTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/model/CellConfigTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/model/CellNeighbourListTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationPayloadTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/model/PolicyNotificationTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/model/ResponseTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/model/SdnrResponseTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/model/ThreadIdTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBodyTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CellInfoTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRequestBodyTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClientTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutionsTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRequestBodyTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PolicyRestClientTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/restclient/RequestInfoTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SolutionsTest.java create mode 100644 src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java create mode 100644 src/test/resources/ClusterDetailsTest.json create mode 100644 src/test/resources/clusterInfo1.json create mode 100644 src/test/resources/clusterInfo2.json create mode 100644 src/test/resources/clusterInfo3.json create mode 100644 src/test/resources/clusterInfo4.json create mode 100644 src/test/resources/clusterInfo5.json create mode 100644 src/test/resources/clusterInfo6.json create mode 100644 src/test/resources/clusterInfo7.json create mode 100644 src/test/resources/notification1.json create mode 100644 src/test/resources/notification2.json create mode 100644 src/test/resources/notification3.json create mode 100644 src/test/resources/policy_notification.json create mode 100644 src/test/resources/solutions.json (limited to 'src/test') diff --git a/src/test/java/com/wipro/www/sonhms/ApplicationTest.java b/src/test/java/com/wipro/www/sonhms/ApplicationTest.java deleted file mode 100644 index 892e0c2..0000000 --- a/src/test/java/com/wipro/www/sonhms/ApplicationTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms; - -public class ApplicationTest { - -} diff --git a/src/test/java/com/wipro/www/sonhms/BufferNotificationComponentTest.java b/src/test/java/com/wipro/www/sonhms/BufferNotificationComponentTest.java deleted file mode 100644 index 08779e4..0000000 --- a/src/test/java/com/wipro/www/sonhms/BufferNotificationComponentTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.wipro.www.sonhms.dao.BufferedNotificationsRepository; -import com.wipro.www.sonhms.entity.BufferedNotifications; -import com.wipro.www.sonhms.utils.BeanUtil; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -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.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.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.web.ProjectedPayload; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; - -@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); - BufferedNotifications bufferedNotificationsResult = new BufferedNotifications(); - bufferNotificationComponent.bufferNotification("notification", "clusterId"); - assertEquals(bufferedNotifications, bufferedNotificationsRepositoryMock.save(bufferedNotifications)); - - } - - @Test - public void getBufferedNotificationTest() { - List notificationsList = new ArrayList(); - 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 testResult = new ArrayList(); - 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/com/wipro/www/sonhms/ChildStatusUpdateStateTest.java b/src/test/java/com/wipro/www/sonhms/ChildStatusUpdateStateTest.java deleted file mode 100644 index ea426bf..0000000 --- a/src/test/java/com/wipro/www/sonhms/ChildStatusUpdateStateTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms; - -public class ChildStatusUpdateStateTest { - -} diff --git a/src/test/java/com/wipro/www/sonhms/ClusterDetailsComponentTest.java b/src/test/java/com/wipro/www/sonhms/ClusterDetailsComponentTest.java deleted file mode 100644 index 4be6339..0000000 --- a/src/test/java/com/wipro/www/sonhms/ClusterDetailsComponentTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - - -import com.wipro.www.sonhms.dao.ClusterDetailsRepository; -import com.wipro.www.sonhms.entity.ClusterDetails; -import com.wipro.www.sonhms.utils.BeanUtil; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -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.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.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.web.ProjectedPayload; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.client.RestTemplate; - -@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 list = new ArrayList(); - 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 resultList = new ArrayList(); - 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/com/wipro/www/sonhms/ConfigPolicyTest.java b/src/test/java/com/wipro/www/sonhms/ConfigPolicyTest.java deleted file mode 100644 index 85b1c44..0000000 --- a/src/test/java/com/wipro/www/sonhms/ConfigPolicyTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.ConfigPolicy; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; - - -public class ConfigPolicyTest { - - @Test - public void configPolicyTest() { - ConfigPolicy configPolicy = ConfigPolicy.getInstance(); - Map config = new HashMap(); - config.put("policyName", "pcims_policy"); - configPolicy.setConfig(config); - assertEquals(config, configPolicy.getConfig()); - } -} diff --git a/src/test/java/com/wipro/www/sonhms/ConfigurationTest.java b/src/test/java/com/wipro/www/sonhms/ConfigurationTest.java deleted file mode 100644 index 06294dd..0000000 --- a/src/test/java/com/wipro/www/sonhms/ConfigurationTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.Configuration; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - - -public class ConfigurationTest { - Configuration configuration = Configuration.getInstance(); - - @Test - public void configurationTest() { - configuration.setBufferTime(60); - configuration.setCallbackUrl("/callbackUrl"); - configuration.setConfigName("configName"); - - List list = new ArrayList(); - 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/com/wipro/www/sonhms/SdnrNotificationHandlingStateTest.java b/src/test/java/com/wipro/www/sonhms/SdnrNotificationHandlingStateTest.java deleted file mode 100644 index d6e2dfc..0000000 --- a/src/test/java/com/wipro/www/sonhms/SdnrNotificationHandlingStateTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms; - -import org.junit.Test; - -public class SdnrNotificationHandlingStateTest { - - @Test - public void sdnrNotificationHandlingState() { - - } -} diff --git a/src/test/java/com/wipro/www/sonhms/SonContextTest.java b/src/test/java/com/wipro/www/sonhms/SonContextTest.java deleted file mode 100644 index e7e6790..0000000 --- a/src/test/java/com/wipro/www/sonhms/SonContextTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.wipro.www.sonhms.SdnrNotificationHandlingState; -import com.wipro.www.sonhms.SonContext; - -import java.util.List; -import java.util.concurrent.BlockingQueue; - -import org.junit.Test; - - - -public class SonContextTest { - - private BlockingQueue> childStatusUpdate; - - @Test - public void sonContextTest() { - SonContext sonContext = new SonContext(); - sonContext.setChildThreadId(1); - sonContext.setNotifToBeProcessed(true); - sonContext.setSdnrNotification("notification"); - sonContext.setChildStatusUpdate(childStatusUpdate); - NewNotification newNotification = new NewNotification(true); - sonContext.setNewNotification(newNotification); - SdnrNotificationHandlingState pciState = new SdnrNotificationHandlingState(); - sonContext.setPciState(pciState); - assertEquals(1, sonContext.getChildThreadId()); - assertTrue(sonContext.isNotifToBeProcessed()); - assertEquals("notification", sonContext.getSdnrNotification()); - assertEquals(pciState, sonContext.getPciState()); - assertEquals(childStatusUpdate, sonContext.getChildStatusUpdate()); - assertEquals(newNotification, sonContext.getNewNotification()); - - } -} diff --git a/src/test/java/com/wipro/www/sonhms/WaitStateTest.java b/src/test/java/com/wipro/www/sonhms/WaitStateTest.java deleted file mode 100644 index 10ae3d7..0000000 --- a/src/test/java/com/wipro/www/sonhms/WaitStateTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms; - -public class WaitStateTest { - -} diff --git a/src/test/java/com/wipro/www/sonhms/child/GraphTest.java b/src/test/java/com/wipro/www/sonhms/child/GraphTest.java deleted file mode 100644 index 2132f22..0000000 --- a/src/test/java/com/wipro/www/sonhms/child/GraphTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.child; - -import static org.junit.Assert.assertNotEquals; - -import com.wipro.www.sonhms.child.Graph; -import com.wipro.www.sonhms.model.CellPciPair; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -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> map = new HashMap<>(); - - log.debug("graph {}", graph.getCellPciNeighbourMap()); - System.out.println("graph" + graph.getCellPciNeighbourMap()); - assertNotEquals(map, graph.getCellPciNeighbourMap()); - - } - -} diff --git a/src/test/java/com/wipro/www/sonhms/child/TestClusterModification.java b/src/test/java/com/wipro/www/sonhms/child/TestClusterModification.java deleted file mode 100644 index 148663e..0000000 --- a/src/test/java/com/wipro/www/sonhms/child/TestClusterModification.java +++ /dev/null @@ -1,188 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.child; - -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 com.wipro.www.sonhms.child.ClusterModification; -import com.wipro.www.sonhms.child.Graph; -import com.wipro.www.sonhms.model.CellPciPair; -import com.wipro.www.sonhms.model.FapServiceList; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.ConcurrentModificationException; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; - -public class TestClusterModification { - @Test - public void testClusterModification() { - - 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(12); - - CellPciPair cpPair3 = new CellPciPair(); - cpPair3.setCellId("56"); - cpPair3.setPhysicalCellId(200); - - CellPciPair cpPair4 = new CellPciPair(); - cpPair4.setCellId("21"); - cpPair4.setPhysicalCellId(6); - - 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 al = new ArrayList(); - al.add(cpPair1); - al.add(cpPair2); - al.add(cpPair3); - - ArrayList al1 = new ArrayList(); - al1.add(cpPair4); - al1.add(cpPair5); - al1.add(cpPair6); - - ArrayList al2 = new ArrayList(); - al2.add(cpPair7); - al2.add(cpPair8); - al2.add(cpPair9); - - Map> map = new HashMap>(); - - map.put(cpPair, al); - map.put(cpPair1, al1); - map.put(cpPair2, al2); - map.put(cpPair3, new ArrayList()); - map.put(cpPair4, new ArrayList()); - map.put(cpPair5, new ArrayList()); - map.put(cpPair6, new ArrayList()); - map.put(cpPair7, new ArrayList()); - map.put(cpPair8, new ArrayList()); - map.put(cpPair9, new ArrayList()); - Graph cluster = new Graph(); - - cluster.setCellPciNeighbourMap(map); - - System.out.println("map before" + cluster.getCellPciNeighbourMap()); - - String notif = "{ \n" + "\"alias\":\"Cell1\",\n" + "\"X0005b9Lte\":{ \n" + "\"phyCellIdInUse\":\"89\",\n" - + "\"pnfName\":\"DU-1\"\n" + "},\n" + "\"CellConfig\":{ \n" + "\"LTE\":{ \n" + "\"RAN\":{ \n" - + "\"CellIdentity\":\"6\",\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\":\"25\",\n" + "\"phyCellId\":\"35\",\n" - + "\"blacklisted\":\"false\"\n" + "}\n" + "]\n" + "}\n" + "}\n" + "}\n" + "}\n" + "}"; - - ObjectMapper mapper = new ObjectMapper(); - FapServiceList fapser = new FapServiceList(); - try { - fapser = mapper.readValue(notif, FapServiceList.class); - } catch (JsonParseException e) { - e.printStackTrace(); - } catch (JsonMappingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - CellPciPair cpPair11 = new CellPciPair(); - cpPair11.setCellId("2"); - cpPair11.setPhysicalCellId(22); - - CellPciPair cpPair12 = new CellPciPair(); - - cpPair12.setCellId("5"); - cpPair12.setPhysicalCellId(24); - - ArrayList al4 = new ArrayList(); - - al4.add(cpPair11); - al4.add(cpPair12); - - Map> newMap = new HashMap>(); - newMap.put(cpPair, al); - newMap.put(cpPair1, al4); - newMap.put(cpPair2, al2); - newMap.put(cpPair3, new ArrayList()); - newMap.put(cpPair4, new ArrayList()); - newMap.put(cpPair5, new ArrayList()); - newMap.put(cpPair6, new ArrayList()); - newMap.put(cpPair7, new ArrayList()); - newMap.put(cpPair8, new ArrayList()); - newMap.put(cpPair9, new ArrayList()); - newMap.put(cpPair11, new ArrayList()); - newMap.put(cpPair12, new ArrayList()); - - Graph newCluster = new Graph(); - newCluster.setCellPciNeighbourMap(newMap); - System.out.print("newCluster" + newCluster.getCellPciNeighbourMap()); - - ClusterModification mod = new ClusterModification(); - try { - // System.out.print("Cluster" + mod.clustermod(cluster, - // fapser).getCellPciNeighbourMap().toString()); - - assertNotEquals(newCluster, mod.clustermod(cluster, fapser)); - - } catch (NullPointerException e) { - e.printStackTrace(); - } catch (ConcurrentModificationException e) { - System.out.println("Concureent execption" + e); - - } - } - -} diff --git a/src/test/java/com/wipro/www/sonhms/child/TestDetection.java b/src/test/java/com/wipro/www/sonhms/child/TestDetection.java deleted file mode 100644 index 03ed787..0000000 --- a/src/test/java/com/wipro/www/sonhms/child/TestDetection.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.child; - - -import com.wipro.www.sonhms.child.Detection; -import com.wipro.www.sonhms.child.Graph; -import com.wipro.www.sonhms.model.CellPciPair; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; - - -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 al = new ArrayList(); - al.add(cpPair1); - al.add(cpPair2); - al.add(cpPair3); - - ArrayList al1 = new ArrayList(); - al1.add(cpPair4); - al1.add(cpPair5); - al1.add(cpPair6); - - ArrayList al2 = new ArrayList(); - al2.add(cpPair7); - al2.add(cpPair8); - al2.add(cpPair9); - - Map> map = new HashMap>(); - - map.put(cpPair, al); - map.put(cpPair1, al1); - map.put(cpPair2, al2); - map.put(cpPair3, new ArrayList()); - map.put(cpPair4, new ArrayList()); - map.put(cpPair5, new ArrayList()); - map.put(cpPair6, new ArrayList()); - map.put(cpPair7, new ArrayList()); - map.put(cpPair8, new ArrayList()); - map.put(cpPair9, new ArrayList()); - 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/com/wipro/www/sonhms/model/CellConfigTest.java b/src/test/java/com/wipro/www/sonhms/model/CellConfigTest.java deleted file mode 100644 index 68f8b40..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/CellConfigTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.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/com/wipro/www/sonhms/model/CellNeighbourListTest.java b/src/test/java/com/wipro/www/sonhms/model/CellNeighbourListTest.java deleted file mode 100644 index 8acc0e8..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/CellNeighbourListTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.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/com/wipro/www/sonhms/model/NotificationPayloadTest.java b/src/test/java/com/wipro/www/sonhms/model/NotificationPayloadTest.java deleted file mode 100644 index d1134fa..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/NotificationPayloadTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.model; - -import org.junit.Test; - -public class NotificationPayloadTest { - - @Test - public void notificationPayloadTest() { - - } - -} diff --git a/src/test/java/com/wipro/www/sonhms/model/NotificationTest.java b/src/test/java/com/wipro/www/sonhms/model/NotificationTest.java deleted file mode 100644 index 09c6c0a..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/NotificationTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.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 com.wipro.www.sonhms.model.FapServiceList; -import com.wipro.www.sonhms.model.LteNeighborListInUseLteCell; -import com.wipro.www.sonhms.model.NeighborListInUse; -import com.wipro.www.sonhms.model.Notification; -import com.wipro.www.sonhms.model.NotificationCellConfig; -import com.wipro.www.sonhms.model.NotificationLte; -import com.wipro.www.sonhms.model.NotificationPayload; -import com.wipro.www.sonhms.model.NotificationRan; -import com.wipro.www.sonhms.model.RadioAccess; -import com.wipro.www.sonhms.model.X0005b9Lte; - -import java.io.IOException; -import java.util.ArrayList; - -import org.junit.Test; - -public class NotificationTest { - - @Test - public void notificationTest() { - - Notification notif = new Notification(); - LteNeighborListInUseLteCell lteNeighborListInUseLteCell = new LteNeighborListInUseLteCell("pnf1", "true", - "Cell10", "true", "123456", "5", 22, "false"); - - ArrayList 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 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/com/wipro/www/sonhms/model/PayloadTest.java b/src/test/java/com/wipro/www/sonhms/model/PayloadTest.java deleted file mode 100644 index 1c006f9..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/PayloadTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.model; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.model.CellConfig; -import com.wipro.www.sonhms.model.Common; -import com.wipro.www.sonhms.model.Configurations; -import com.wipro.www.sonhms.model.Data; -import com.wipro.www.sonhms.model.FapService; -import com.wipro.www.sonhms.model.Lte; -import com.wipro.www.sonhms.model.Payload; -import com.wipro.www.sonhms.model.Ran; -import com.wipro.www.sonhms.model.X0005b9Lte; - -import java.util.ArrayList; - -import org.junit.Test; - - - -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 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/com/wipro/www/sonhms/model/ResponseTest.java b/src/test/java/com/wipro/www/sonhms/model/ResponseTest.java deleted file mode 100644 index c413791..0000000 --- a/src/test/java/com/wipro/www/sonhms/model/ResponseTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.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/com/wipro/www/sonhms/restclient/AsyncResponseBodyTest.java b/src/test/java/com/wipro/www/sonhms/restclient/AsyncResponseBodyTest.java deleted file mode 100644 index 95afd77..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/AsyncResponseBodyTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; - -import com.wipro.www.sonhms.restclient.AsyncResponseBody; -import com.wipro.www.sonhms.restclient.Solution; -import com.wipro.www.sonhms.restclient.SonSolution; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - - - -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 pciSolutionsList = new ArrayList(); - 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 solutionsList = new ArrayList(); - solutionsList.add(solutions); - asyncResponseBody.setSolutions(solutionsList); - asyncResponseBody.setStatusMessage("success"); - asyncResponseBody.setTransactionId("3df7b0e9-26d1-4080-ba42-28e8a3139689"); - } -} diff --git a/src/test/java/com/wipro/www/sonhms/restclient/CellInfoTest.java b/src/test/java/com/wipro/www/sonhms/restclient/CellInfoTest.java deleted file mode 100644 index b686f93..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/CellInfoTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.restclient.CellInfo; - -import java.util.ArrayList; -import java.util.List; -import org.junit.Test; - - -public class CellInfoTest { - @Test - public void cellInfoTest() { - List 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/com/wipro/www/sonhms/restclient/OofRequestBodyTest.java b/src/test/java/com/wipro/www/sonhms/restclient/OofRequestBodyTest.java deleted file mode 100644 index 493095b..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/OofRequestBodyTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.restclient.CellInfo; -import com.wipro.www.sonhms.restclient.OofRequestBody; -import com.wipro.www.sonhms.restclient.RequestInfo; - -import java.util.ArrayList; -import java.util.List; -import org.junit.Test; - - - -public class OofRequestBodyTest { - @Test - public void oofRequestBodyTest() { - - List cellIdLists = new ArrayList<>(); - cellIdLists.add("cell1"); - CellInfo cellInfo = new CellInfo(); - cellInfo.setNetworkId("NTWK001"); - cellInfo.setCellIdList(cellIdLists); - RequestInfo requestInfo = new RequestInfo(); - List optimizers = new ArrayList(); - 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/com/wipro/www/sonhms/restclient/OofRestClientTest.java b/src/test/java/com/wipro/www/sonhms/restclient/OofRestClientTest.java deleted file mode 100644 index 2f06f0a..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/OofRestClientTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; - -public class OofRestClientTest { - -} diff --git a/src/test/java/com/wipro/www/sonhms/restclient/PciSolutionsTest.java b/src/test/java/com/wipro/www/sonhms/restclient/PciSolutionsTest.java deleted file mode 100644 index e7aac21..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/PciSolutionsTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.restclient.SonSolution; - -import org.junit.Test; - - -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/com/wipro/www/sonhms/restclient/PolicyRequestBodyTest.java b/src/test/java/com/wipro/www/sonhms/restclient/PolicyRequestBodyTest.java deleted file mode 100644 index 0726c31..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/PolicyRequestBodyTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.restclient.PolicyRequestBody; - -import org.junit.Test; - - -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/com/wipro/www/sonhms/restclient/RequestInfoTest.java b/src/test/java/com/wipro/www/sonhms/restclient/RequestInfoTest.java deleted file mode 100644 index f21971b..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/RequestInfoTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.restclient.RequestInfo; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - - -public class RequestInfoTest { - @Test - public void requestInfoTest() { - RequestInfo requestInfo = new RequestInfo(); - List optimizers = new ArrayList(); - 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/com/wipro/www/sonhms/restclient/SolutionsTest.java b/src/test/java/com/wipro/www/sonhms/restclient/SolutionsTest.java deleted file mode 100644 index 64985f6..0000000 --- a/src/test/java/com/wipro/www/sonhms/restclient/SolutionsTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * ============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 com.wipro.www.sonhms.restclient; - -import static org.junit.Assert.assertEquals; - -import com.wipro.www.sonhms.restclient.Solution; -import com.wipro.www.sonhms.restclient.SonSolution; -import java.util.ArrayList; -import java.util.List; -import org.junit.Test; - - - -public class SolutionsTest { - - @Test - public void solutionsTest() { - - SonSolution pciSolutions = new SonSolution(); - pciSolutions.setCellId("EXP001"); - pciSolutions.setPci(101); - List pciSolutionsList = new ArrayList(); - 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/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 notificationsList = new ArrayList(); + 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 testResult = new ArrayList(); + 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 list = new ArrayList(); + 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 resultList = new ArrayList(); + 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 config = new HashMap(); + 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 list = new ArrayList(); + 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 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 = 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 cellsinCluster = new HashMap<>(); + List newCells = new ArrayList<>(); + newCells.add(notification.getPayload().getRadioAccess().getFapServiceList().get(0)); + mapping.setCellsinCluster(cellsinCluster); + mapping.setNewCells(newCells); + Either 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> 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 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 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 al = new ArrayList(); + al.add(cpPair1); + al.add(cpPair2); + al.add(cpPair3); + + ArrayList al1 = new ArrayList(); + al1.add(cpPair4); + al1.add(cpPair5); + al1.add(cpPair6); + + ArrayList al2 = new ArrayList(); + al2.add(cpPair7); + al2.add(cpPair8); + al2.add(cpPair9); + + Map> map = new HashMap>(); + + map.put(cpPair, al); + map.put(cpPair1, al1); + map.put(cpPair2, al2); + map.put(cpPair3, new ArrayList()); + map.put(cpPair4, new ArrayList()); + map.put(cpPair5, new ArrayList()); + map.put(cpPair6, new ArrayList()); + map.put(cpPair7, new ArrayList()); + map.put(cpPair8, new ArrayList()); + map.put(cpPair9, new ArrayList()); + 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 solutions = new ArrayList<>(); + private static Optional cellInfo; + private static Optional 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>(){}); + } 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> pnfs = new HashMap<>(); + List cellpciPairList1=new ArrayList<>(); + cellpciPairList1.add(new CellPciPair("EXP001",101)); + List 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 topics = new HashSet(); + topics.add("topic1"); + topics.add("topic2"); + Configuration configuration = Configuration.getInstance(); + configuration.setBufferTime(60); + configuration.setCallbackUrl("/callbackUrl"); + configuration.setConfigName("configName"); + List list = new ArrayList(); + 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 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 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 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 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 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 pciSolutionsList = new ArrayList(); + 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 solutionsList = new ArrayList(); + 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 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 cellIdLists = new ArrayList<>(); + cellIdLists.add("cell1"); + CellInfo cellInfo = new CellInfo(); + cellInfo.setNetworkId("NTWK001"); + cellInfo.setCellIdList(cellIdLists); + RequestInfo requestInfo = new RequestInfo(); + List optimizers = new ArrayList(); + 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 list = new ArrayList(); + 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 cellIdList=new ArrayList(); + cellIdList.add("EXP001"); + List optimizers=new ArrayList(); + 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.>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.>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 list = new ArrayList(); + 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.>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 optimizers = new ArrayList(); + 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.>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.>any())) + .thenReturn(ResponseEntity.ok(responseBody)); + try { + List result=SdnrRestClient.getNbrList("1"); + List 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.>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.>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 pciSolutionsList = new ArrayList(); + 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 clusterDetailsForGetClusterDetailsFromClusterIdTest; + private static Graph cluster; + private static List clusterDetails = new ArrayList<>(); + + @BeforeClass + public static void setup() { + + notification1 = new Notification(); + notification2 = new Notification(); + clusterDetailsForGetClusterDetailsFromClusterIdTest = new ArrayList(); + + 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>(){}); + } 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 cellsinCluster = new HashMap<>(); + cellsinCluster.put(notification1.getPayload().getRadioAccess().getFapServiceList().get(0), "2"); + expected.setCellsinCluster(cellsinCluster); + expected.setNewCells(new ArrayList()); + + NotificationToClusterMapping result = clusterUtils.getClustersForNotification(notification1, clusterDetails); + assertEquals(expected, result); + + expected = new NotificationToClusterMapping(); + List 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 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 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 newClusters=new ArrayList(); + newClusters.add(graph1); + newClusters.add(graph2); + Either 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 emptyList=new ArrayList(); + + 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; + } +} diff --git a/src/test/resources/ClusterDetailsTest.json b/src/test/resources/ClusterDetailsTest.json new file mode 100644 index 0000000..01839ae --- /dev/null +++ b/src/test/resources/ClusterDetailsTest.json @@ -0,0 +1,10 @@ +[{"clusterId":"0", +"clusterInfo":"", + "childThreadId":986476 +}, +{"clusterId":"1", +"clusterInfo":"", + "childThreadId":986475 +} +] + diff --git a/src/test/resources/clusterInfo1.json b/src/test/resources/clusterInfo1.json new file mode 100644 index 0000000..685d923 --- /dev/null +++ b/src/test/resources/clusterInfo1.json @@ -0,0 +1 @@ +[{"cellId":"29","physicalCellId":209,"neighbours":"[]"},{"cellId":"25","physicalCellId":32,"neighbours":"[{\"physicalCellId\":209,\"cellId\":\"29\"}]"}] diff --git a/src/test/resources/clusterInfo2.json b/src/test/resources/clusterInfo2.json new file mode 100644 index 0000000..6fe6d5e --- /dev/null +++ b/src/test/resources/clusterInfo2.json @@ -0,0 +1 @@ +[{"cellId":"45","physicalCellId":310,"neighbours":"[]"},{"cellId":"47","physicalCellId":302,"neighbours":"[{\"physicalCellId\":310,\"cellId\":\"45\"}]"}] diff --git a/src/test/resources/clusterInfo3.json b/src/test/resources/clusterInfo3.json new file mode 100644 index 0000000..71e7736 --- /dev/null +++ b/src/test/resources/clusterInfo3.json @@ -0,0 +1 @@ +[{"cellId":"72","physicalCellId":2,"neighbours":"[]"},{"cellId":"63","physicalCellId":5,"neighbours":"[{\"physicalCellId\":2,\"cellId\":\"72\"}]"}] diff --git a/src/test/resources/clusterInfo4.json b/src/test/resources/clusterInfo4.json new file mode 100644 index 0000000..4da8c07 --- /dev/null +++ b/src/test/resources/clusterInfo4.json @@ -0,0 +1 @@ +[{"cellId":"2","physicalCellId":20,"neighbours":"[]"},{"cellId":"5","physicalCellId":30,"neighbours":"[{\"physicalCellId\":20,\"cellId\":\"2\"}]"}] diff --git a/src/test/resources/clusterInfo5.json b/src/test/resources/clusterInfo5.json new file mode 100644 index 0000000..7612d10 --- /dev/null +++ b/src/test/resources/clusterInfo5.json @@ -0,0 +1 @@ +[{"cellId":"44","physicalCellId":3,"neighbours":"[]"},{"cellId":"48","physicalCellId":0,"neighbours":"[{\"physicalCellId\":3,\"cellId\":\"44\"}]"},{"cellId":"45","physicalCellId":310,"neighbours":"[{\"physicalCellId\":0,\"cellId\":\"48\"}]"}] diff --git a/src/test/resources/clusterInfo6.json b/src/test/resources/clusterInfo6.json new file mode 100644 index 0000000..88e0763 --- /dev/null +++ b/src/test/resources/clusterInfo6.json @@ -0,0 +1 @@ +[{"cellId":"48","physicalCellId":0,"neighbours":"[]"},{"cellId":"45","physicalCellId":310,"neighbours":"[{\"physicalCellId\":0,\"cellId\":\"48\"}]"},{"cellId":"47","physicalCellId":302,"neighbours":"[{\"physicalCellId\":310,\"cellId\":\"45\"}]"}] diff --git a/src/test/resources/clusterInfo7.json b/src/test/resources/clusterInfo7.json new file mode 100644 index 0000000..1d8dc7d --- /dev/null +++ b/src/test/resources/clusterInfo7.json @@ -0,0 +1 @@ +[{"cellId":"82","physicalCellId":32,"neighbours":"[]"},{"cellId":"81","physicalCellId":31,"neighbours":"[{\"physicalCellId\":32,\"cellId\":\"82\"}]"}] diff --git a/src/test/resources/notification1.json b/src/test/resources/notification1.json new file mode 100644 index 0000000..87f60e6 --- /dev/null +++ b/src/test/resources/notification1.json @@ -0,0 +1,45 @@ +{ + "requestID":"9d2d790e-a5f0-11e8-98d0-529269fb1459", + "AAI":{ + + }, + "from":"SDNR", + "version":"1.0.2", + "Action":"NeighborListModified", + "Payload":{ + "RadioAccess":{ + "FAPServiceNumberOfEntries":"1", + "FAPServiceList":[ + { + "alias":"45", + "X0005b9Lte":{ + "phyCellIdInUse":"310", + "pnfName":"ncserver2" + }, + "CellConfig":{ + "LTE":{ + "RAN":{ + "CellIdentity":"45", + "NeighborListInUse":{ + "LTECellNumberOfEntries":"1", + "LTENeighborListInUseLTECell":[ + { + "pnfName":"ncserver1", + "enable":"true", + "alias":"48", + "mustInclude":"true", + "plmnid":"ran-1", + "cid":"48", + "phyCellId":"0", + "blacklisted":"false" + } + ] + } + } + } + } + } + ] + } + } +} diff --git a/src/test/resources/notification2.json b/src/test/resources/notification2.json new file mode 100644 index 0000000..702b643 --- /dev/null +++ b/src/test/resources/notification2.json @@ -0,0 +1,55 @@ +{ + "requestID":"9d2d790e-a5f0-11e8-98d0-529269fb1459", + "AAI":{ + + }, + "from":"SDNR", + "version":"1.0.2", + "Action":"NeighborListModified", + "Payload":{ + "RadioAccess":{ + "FAPServiceNumberOfEntries":"1", + "FAPServiceList":[ + { + "alias":"120", + "X0005b9Lte":{ + "phyCellIdInUse":"2", + "pnfName":"ncserver2" + }, + "CellConfig":{ + "LTE":{ + "RAN":{ + "CellIdentity":"120", + "NeighborListInUse":{ + "LTECellNumberOfEntries":"3", + "LTENeighborListInUseLTECell":[ + { + "pnfName":"ncserver1", + "enable":"true", + "alias":"123", + "mustInclude":"true", + "plmnid":"ran-1", + "cid":"123", + "phyCellId":"6", + "blacklisted":"false" + }, + { + "pnfName":"ncserver1", + "enable":"true", + "alias":"49", + "mustInclude":"true", + "plmnid":"ran-1", + "cid":"124", + "phyCellId":"4", + "blacklisted":"false" + } + ] + } + } + } + } + } + ] + } + } +} diff --git a/src/test/resources/notification3.json b/src/test/resources/notification3.json new file mode 100644 index 0000000..4a3a2a0 --- /dev/null +++ b/src/test/resources/notification3.json @@ -0,0 +1,45 @@ +{ + "requestID":"9d2d790e-a5f0-11e8-98d0-529269fb1459", + "AAI":{ + + }, + "from":"SDNR", + "version":"1.0.2", + "Action":"NeighborListModified", + "Payload":{ + "RadioAccess":{ + "FAPServiceNumberOfEntries":"1", + "FAPServiceList":[ + { + "alias":"81", + "X0005b9Lte":{ + "phyCellIdInUse":"31", + "pnfName":"ncserver2" + }, + "CellConfig":{ + "LTE":{ + "RAN":{ + "CellIdentity":"81", + "NeighborListInUse":{ + "LTECellNumberOfEntries":"1", + "LTENeighborListInUseLTECell":[ + { + "pnfName":"ncserver1", + "enable":"true", + "alias":"82", + "mustInclude":"true", + "plmnid":"ran-1", + "cid":"82", + "phyCellId":"32", + "blacklisted":"false" + } + ] + } + } + } + } + } + ] + } + } +} diff --git a/src/test/resources/policy_notification.json b/src/test/resources/policy_notification.json new file mode 100644 index 0000000..b9a6910 --- /dev/null +++ b/src/test/resources/policy_notification.json @@ -0,0 +1,20 @@ +{ + + "closedLoopControlName":"ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459", + "closedLoopAlarmStart":1542445563201, + "closedLoopEventClient":"microservice.PCI", + "closedLoopEventStatus":"ONSET", + "target_type":"VNF", + "target":"generic-vnf.vnf-id", + "requestID":"a4130fd5-2291-4a83-8992-04e4c9f32731", + "from":"PCIMS", + "version":"1.0.2", + "payload":"{\"Configurations\":[{\"data\":{\"FAPService\":{\"alias\":\"Chn0330\",\"X0005b9Lte\":{\"phyCellIdInUse\":6,\"pnfName\":\"ncserver23\"},\"CellConfig\":{\"LTE\":{\"RAN\":{\"Common\":{\"CellIdentity\":\"Chn0330\"}}}}}}},{\"data\":{\"FAPService\":{\"alias\":\"Chn0331\",\"X0005b9Lte\":{\"phyCellIdInUse\":7,\"pnfName\":\"ncserver23\"},\"CellConfig\":{\"LTE\":{\"RAN\":{\"Common\":{\"CellIdentity\":\"Chn0331\"}}}}}}}]}", + "AAI":{ + "generic-vnf.prov-status":"ACTIVE", + "generic-vnf.is-closed-loop-disabled":"false", + "generic-vnf.vnf-id":"ncserver23" + }, + "Action":"ModifyConfig" + +} diff --git a/src/test/resources/solutions.json b/src/test/resources/solutions.json new file mode 100644 index 0000000..cf82283 --- /dev/null +++ b/src/test/resources/solutions.json @@ -0,0 +1 @@ +[{"startTime":"2016-10-01T00:30+01:00","finishTime":"2016-10-01T00:40+01.00","networkId":"NTWK005","pciSolutions":[{"cellId":"EXP001","pci":"101"},{"cellId":"EXP002","pci":"102"}]}] -- cgit 1.2.3-korg