diff options
author | krishnaa96 <krishna.moorthy6@wipro.com> | 2019-04-05 18:13:32 +0530 |
---|---|---|
committer | krishnaa96 <krishna.moorthy6@wipro.com> | 2019-04-05 18:13:32 +0530 |
commit | 80b0c61808d0958ef7d38a772a206f2c17dfd2a5 (patch) | |
tree | 7e261770b7f974cdc50b5634138714beb311aaaa /src/test | |
parent | ab400d51a639a01f31a60ac9d1e127d4d4d28b24 (diff) |
Implement Enhancements to the Microservice
Change-Id: Ie3b11fe14f1794fdd6880c40bc382eccbef34aa2
Issue-ID: DCAEGEN2-1109
Signed-off-by: krishna moorthy <krishna.moorthy6@wipro.com>
Diffstat (limited to 'src/test')
43 files changed, 1488 insertions, 375 deletions
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java index d2480d2..28ff185 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/BufferNotificationComponentTest.java @@ -70,7 +70,7 @@ public class BufferNotificationComponentTest { .thenReturn(bufferedNotificationsRepositoryMock); when(bufferedNotificationsRepositoryMock.save(bufferedNotifications)).thenReturn(bufferedNotifications); bufferNotificationComponent.bufferNotification("notification", "clusterId"); - assertEquals(bufferedNotifications, bufferedNotificationsRepositoryMock.save(bufferedNotifications)); + assertEquals(bufferedNotifications, bufferedNotificationsRepositoryMock.save(bufferedNotifications)); } diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java index 18bde74..e8b44bf 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ClusterDetailsComponentTest.java @@ -76,7 +76,7 @@ public class ClusterDetailsComponentTest { resultList = clusterDetailsComponent.getClusterDetails(); for (ClusterDetails each : resultList) { assertEquals("clusterId", each.getClusterId()); - assertEquals("clusterInfo", each.getClusterInfo()); + assertEquals("clusterInfo", each.getClusterInfo()); assertEquals(1, each.getChildThreadId()); } diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/CommonEventHeaderTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/CommonEventHeaderTest.java new file mode 100644 index 0000000..c9fc849 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/CommonEventHeaderTest.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * ============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 CommonEventHeaderTest { + + CommonEventHeader common = new CommonEventHeader(); + + @Test + public void commonEventHeaderTest() { + common.setDomain("domain"); + common.setEventId("eventId"); + common.setEventName("eventName"); + common.setLastEpochMicrosec(2L); + common.setNfNamingCode("nfNamingCode"); + common.setNfVendorName("nfVendorName"); + common.setPriority("priority"); + common.setReportingEntityId("reportingEntityId"); + common.setReportingEntityName("reportingEntityName"); + common.setSequence(1); + common.setSourceId("sourceId"); + common.setSourceName("sourceName"); + common.setStartEpochMicrosec(1L); + common.setTimeZoneOffset("timeZoneOffset"); + common.setVersion("version"); + common.setVesEventListenerVersion("vesEventListenerVersion"); + assertEquals("domain", common.getDomain()); + assertEquals("eventId", common.getEventId()); + assertEquals("eventName", common.getEventName()); + assertEquals(2L, common.getLastEpochMicrosec()); + assertEquals("nfNamingCode", common.getNfNamingCode()); + assertEquals("nfVendorName", common.getNfVendorName()); + assertEquals("priority", common.getPriority()); + assertEquals("reportingEntityId", common.getReportingEntityId()); + assertEquals("reportingEntityName", common.getReportingEntityName()); + assertEquals("sourceId", common.getSourceId()); + assertEquals("sourceName", common.getSourceName()); + assertEquals("timeZoneOffset", common.getTimeZoneOffset()); + assertEquals("version", common.getVersion()); + assertEquals("vesEventListenerVersion", common.getVesEventListenerVersion()); + assertEquals(1L, common.getStartEpochMicrosec()); + assertEquals(1, common.getSequence()); + + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java index 851920d..6fb72c3 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java @@ -24,8 +24,11 @@ package org.onap.dcaegen2.services.sonhms; import static org.junit.Assert.assertEquals; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import org.hibernate.sql.ConditionFragment; import org.junit.Test; @@ -39,15 +42,26 @@ public class ConfigurationTest { List<String> list = new ArrayList<String>(); list.add("server"); + Map<String, Object> subscribes = new HashMap<>(); + + configuration.setStreamsSubscribes(subscribes); + configuration.setStreamsPublishes(subscribes); configuration.setDmaapServers(list); configuration.setCg("cg"); configuration.setCid("cid"); - + configuration.setAafPassword("password"); + configuration.setAafUsername("user"); + configuration.setPgHost("pg"); + configuration.setPgPort(5432); + configuration.setPgPassword("password"); + configuration.setPgUsername("user"); configuration.setMaximumClusters(5); configuration.setMinCollision(5); configuration.setMinConfusion(5); configuration.setNumSolutions(1); configuration.setOofService("oofService"); + configuration.setBadThreshold(50); + configuration.setPoorThreshold(70); configuration.setOptimizers(list); configuration.setPollingInterval(30); configuration.setPollingTimeout(100); @@ -57,18 +71,26 @@ public class ConfigurationTest { assertEquals("/callbackUrl", configuration.getCallbackUrl()); assertEquals("cg", configuration.getCg()); assertEquals("cid", configuration.getCid()); - + assertEquals("user", configuration.getAafUsername()); + assertEquals("password", configuration.getAafPassword()); 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("user", configuration.getPgUsername()); + assertEquals("password", configuration.getPgPassword()); + assertEquals("pg", configuration.getPgHost()); + assertEquals(5432, configuration.getPgPort()); assertEquals(30, configuration.getPollingInterval()); assertEquals(100, configuration.getPollingTimeout()); assertEquals("sdnrService", configuration.getConfigDbService()); assertEquals(list, configuration.getDmaapServers()); assertEquals("sourceId", configuration.getSourceId()); + assertEquals(50, configuration.getBadThreshold()); + assertEquals(70, configuration.getPoorThreshold()); + assertEquals(subscribes, configuration.getStreamsSubscribes()); + assertEquals(subscribes, configuration.getStreamsPublishes()); } } diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java index bf5ef97..5bf76b3 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/DmaapNotificationsComponentTest.java @@ -23,6 +23,7 @@ package org.onap.dcaegen2.services.sonhms; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; import fj.data.Either; @@ -37,7 +38,9 @@ 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.dao.PerformanceNotificationsRepository; import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.model.PMNotification; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -55,16 +58,23 @@ public class DmaapNotificationsComponentTest { @Mock DmaapNotificationsRepository dmaapNotificationsRepositoryMock; + + @Mock + PerformanceNotificationsRepository performanceNotificationsRepositoryMock; @InjectMocks DmaapNotificationsComponent component; static String notificationString; + static String pmNotificationString; + @BeforeClass public static void setupTest() { notificationString = readFromFile("/notification1.json"); + pmNotificationString=readFromFile("/pmNotification.json"); + } @Test @@ -75,17 +85,35 @@ public class DmaapNotificationsComponentTest { when(dmaapNotificationsRepositoryMock.getNotificationFromQueue()).thenReturn(notificationString); - Either<Notification, Integer> result = component.getDmaapNotifications(); + Either<Notification, Integer> result = component.getSdnrNotifications(); //assertTrue(result.isLeft()); assertNotNull(result.left().value()); when(dmaapNotificationsRepositoryMock.getNotificationFromQueue()).thenReturn("notification"); - result = component.getDmaapNotifications(); + result = component.getSdnrNotifications(); int resultRight = result.right().value(); assertEquals(400, resultRight); } + + @Test + public void getPmNotificationsTest() { + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(PerformanceNotificationsRepository.class)) + .thenReturn(performanceNotificationsRepositoryMock); + when(performanceNotificationsRepositoryMock.getPerformanceNotificationFromQueue()).thenReturn(pmNotificationString); + + Either<PMNotification,Integer> result = component.getPmNotifications(); + assertTrue(result.isLeft()); + assertNotNull(result.left().value()); + + when(performanceNotificationsRepositoryMock.getPerformanceNotificationFromQueue()).thenReturn("pmNotification"); + result = component.getPmNotifications(); + int res= result.right().value(); + assertEquals(400,res); + + } private static String readFromFile(String file) { String content = new String(); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java index 5032799..02a061b 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java @@ -114,7 +114,7 @@ public class EventHandlerTest { 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); + Mockito.when(threadUtilsMock.createNewThread(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),Mockito.anyString())).thenReturn(true); try { Mockito.when(clusterutilsMock.createCluster(Mockito.any())).thenReturn(cluster); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/EventTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/EventTest.java new file mode 100644 index 0000000..0fe3037 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/EventTest.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * ============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; +import org.onap.dcaegen2.services.sonhms.CommonEventHeader; +import org.onap.dcaegen2.services.sonhms.FaultEvent; +import org.onap.dcaegen2.services.sonhms.FaultFields; + +public class EventTest { + + FaultEvent faultEvent = new FaultEvent(); + + @Test + public void faultEventTest() { + FaultFields faultFields = new FaultFields(); + faultFields.setAlarmCondition("alarmCondition"); + AlarmAdditionalInformation alarmAdditionalInformation = new AlarmAdditionalInformation(); + alarmAdditionalInformation.setCollisions(1); + alarmAdditionalInformation.setConfusions(3); + alarmAdditionalInformation.setNetworkId("networkId"); + faultFields.setAlarmAdditionalInformation(alarmAdditionalInformation); + + faultFields.setEventSeverity("eventSeverity"); + faultFields.setEventSourceType("eventSourceType"); + faultFields.setFaultFieldsVersion(0); + faultFields.setSpecificProblem("specificProblem"); + faultFields.setVfStatus("vfStatus"); + + CommonEventHeader common = new CommonEventHeader(); + + common.setDomain("domain"); + common.setEventId("eventId"); + common.setEventName("eventName"); + common.setLastEpochMicrosec(2L); + common.setNfNamingCode("nfNamingCode"); + common.setNfVendorName("nfVendorName"); + common.setPriority("priority"); + common.setReportingEntityId("reportingEntityId"); + common.setReportingEntityName("reportingEntityName"); + common.setSequence(1); + common.setSourceId("sourceId"); + common.setSourceName("sourceName"); + common.setStartEpochMicrosec(1L); + common.setTimeZoneOffset("timeZoneOffset"); + common.setVersion("version"); + common.setVesEventListenerVersion("vesEventListenerVersion"); + Event event=new Event(); + event.setCommonEventHeader(common); + event.setFaultFields(faultFields); + faultEvent.setEvent(event); + + assertEquals(common, faultEvent.getEvent().getCommonEventHeader()); + assertEquals(faultFields, faultEvent.getEvent().getFaultFields()); + + } +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/FaultFieldsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/FaultFieldsTest.java new file mode 100644 index 0000000..c940917 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/FaultFieldsTest.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * ============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 FaultFieldsTest { + + FaultFields faultFields=new FaultFields(); + @Test + public void faultFieldsTest() { + faultFields.setAlarmCondition("alarmCondition"); + AlarmAdditionalInformation alarmAdditionalInformation = new AlarmAdditionalInformation(); + alarmAdditionalInformation.setCollisions(1); + alarmAdditionalInformation.setConfusions(3); + alarmAdditionalInformation.setNetworkId("networkId"); + + faultFields.setEventSeverity("eventSeverity"); + faultFields.setEventSourceType("eventSourceType"); + faultFields.setFaultFieldsVersion(0); + faultFields.setAlarmAdditionalInformation(alarmAdditionalInformation); + + faultFields.setSpecificProblem("specificProblem"); + faultFields.setVfStatus("vfStatus"); + assertEquals("alarmCondition", faultFields.getAlarmCondition()); + assertEquals(1, faultFields.getAlarmAdditionalInformation().getCollisions()); + assertEquals(3, faultFields.getAlarmAdditionalInformation().getConfusions()); + assertEquals(0, faultFields.getFaultFieldsVersion()); + assertEquals("eventSeverity", faultFields.getEventSeverity()); + assertEquals("eventSourceType", faultFields.getEventSourceType()); + assertEquals("networkId", faultFields.getAlarmAdditionalInformation().getNetworkId()); + assertEquals("specificProblem", faultFields.getSpecificProblem()); + assertEquals("vfStatus", faultFields.getVfStatus()); + + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponentTest.java new file mode 100644 index 0000000..17fd484 --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/FaultNotificationComponentTest.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * ============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.assertNotNull; +import static org.mockito.Mockito.when; + +import fj.data.Either; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.List; + +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.FaultNotificationsRepository; +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 = FaultNotificationComponentTest.class) + +public class FaultNotificationComponentTest { + + @Mock + FaultNotificationsRepository faultNotificationsRepositoryMock; + + @InjectMocks + FaultNotificationComponent 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(FaultNotificationsRepository.class)) + .thenReturn(faultNotificationsRepositoryMock); + when(faultNotificationsRepositoryMock.getFaultNotificationFromQueue()).thenReturn(notificationString); + + Either<List<FaultEvent>, Integer> result = component.getFaultNotifications(); + // assertTrue(result.isLeft()); + assertNotNull(result); + + + } + + 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/HoMetricsComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponentTest.java new file mode 100644 index 0000000..9ac056b --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponentTest.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * ============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 java.util.List; + +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.HandOverMetricsRepository; +import org.onap.dcaegen2.services.sonhms.model.HoDetails; +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 = HoMetricsComponentTest.class) +public class HoMetricsComponentTest { + + @Mock + HandOverMetricsRepository handOverMetricsRepositoryMock; + + @InjectMocks + HoMetricsComponent hoMetricsComponent; + + static String hoDetailsString; + + @BeforeClass + public static void setup() { + hoDetailsString=readFromFile("/hoDetails.json"); + } + + @Test + public void getHoMetricsTest() { + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil + .getBean(HandOverMetricsRepository.class)).thenReturn(handOverMetricsRepositoryMock); + when(handOverMetricsRepositoryMock.getHandOverMetrics("")).thenReturn(hoDetailsString); + Either<List<HoDetails>, Integer> result = hoMetricsComponent.getHoMetrics(""); + assertNotNull(result.left().value()); + when(handOverMetricsRepositoryMock.getHandOverMetrics("")).thenReturn("wrongText"); + result = hoMetricsComponent.getHoMetrics(""); + int res= result.right().value(); + assertEquals(400,res); + } + + private static String readFromFile(String file) { + String content = new String(); + try { + + InputStream is = HoMetricsComponentTest.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/PMNotificationHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java new file mode 100644 index 0000000..e2e702c --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * ============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 static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +import com.fasterxml.jackson.databind.ObjectMapper; + +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.mockito.Mockito; +import org.onap.dcaegen2.services.sonhms.dao.HandOverMetricsRepository; +import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; +import org.onap.dcaegen2.services.sonhms.entity.HandOverMetrics; +import org.onap.dcaegen2.services.sonhms.model.PMNotification; +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 = PMNotificationHandlerTest.class) +public class PMNotificationHandlerTest { + + @Mock + HandOverMetricsRepository handOverMetricsRepositoryMock; + + @InjectMocks + PMNotificationHandler pmNotificationHandler; + + @Mock + PolicyDmaapClient policyDmaapClient; + + private static String pmNotificationsString ; + private static String pmNotificationsString1 ; + private static PMNotification pmNotification; + private static PMNotification pmNotification1; + + @BeforeClass + public static void setup() { + pmNotificationsString=readFromFile("/pmNotification.json"); + pmNotificationsString1=readFromFile("/pmNotification1.json"); + ObjectMapper mapper = new ObjectMapper(); + pmNotification = new PMNotification(); + pmNotification1 = new PMNotification(); + + try { + pmNotification = mapper.readValue(pmNotificationsString, PMNotification.class); + pmNotification1 = mapper.readValue(pmNotificationsString1, PMNotification.class); + } catch(Exception e) { + e.printStackTrace(); + } + } + + @Test + public void handlePmNotificationsTest() { + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil + .getBean(HandOverMetricsRepository.class)).thenReturn(handOverMetricsRepositoryMock); + when(handOverMetricsRepositoryMock.save(new HandOverMetrics())).thenReturn(null); + when(policyDmaapClient.sendNotificationToPolicy(Mockito.anyString())).thenReturn(true); + assertTrue(pmNotificationHandler.handlePmNotifications(pmNotification, 50)); + assertFalse(pmNotificationHandler.handlePmNotifications(null, 0)); + assertTrue(pmNotificationHandler.handlePmNotifications(pmNotification1, 50)); + } + + private static String readFromFile(String file) { + String content = new String(); + try { + + InputStream is = HoMetricsComponentTest.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/child/ChildThreadTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadTest.java new file mode 100644 index 0000000..a27360e --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadTest.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * ============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.assertTrue; +import static org.mockito.Mockito.when; + +import fj.data.Either; + +import java.util.ArrayList; +import java.util.List; + +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.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.HoMetricsComponent; +import org.onap.dcaegen2.services.sonhms.model.HoDetails; +import org.springframework.boot.test.context.SpringBootTest; + +@RunWith(MockitoJUnitRunner.class) +@SpringBootTest(classes = ChildThreadTest.class) +public class ChildThreadTest { + + @Mock + HoMetricsComponent hoMetricsComponent; + + @InjectMocks + ChildThread childThread; + + @Test + public void checkAnrTriggerTest() { + ArrayList<String> cellidList = new ArrayList<>(); + cellidList.add("cell1"); + //PowerMockito.mockStatic(Configuration.class); + Configuration config = Configuration.getInstance() ; + config.setPoorThreshold(70); + //PowerMockito.when(Configuration.getInstance()).thenReturn(config); + Either<List<HoDetails>, Integer> response = null; + HoDetails hoDetail = new HoDetails(); + hoDetail.setDstCellId("dstCell1"); + hoDetail.setSuccessRate(60); + List<HoDetails> hoDetailsList = new ArrayList<>(); + hoDetailsList.add(hoDetail); + response = Either.left(hoDetailsList); + when(hoMetricsComponent.getHoMetrics(Mockito.anyString())).thenReturn(response); + assertTrue(childThread.checkAnrTrigger(cellidList).isLeft()); + } + +} diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/StateOofTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/StateOofTest.java new file mode 100644 index 0000000..32bfbcf --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/StateOofTest.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * ============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.assertNotNull; + +import java.util.ArrayList; +import java.util.UUID; +import java.util.concurrent.LinkedBlockingQueue; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.dcaegen2.services.sonhms.exceptions.OofNotFoundException; +import org.onap.dcaegen2.services.sonhms.restclient.OofRestClient; +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({OofRestClient.class}) +@SpringBootTest(classes = StateOof.class) +public class StateOofTest { + + StateOof oof; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + oof = new StateOof(new LinkedBlockingQueue<>()); + } + + + UUID transactionId; + + @SuppressWarnings("unchecked") + @Test + public void triggerOofTest() { + ArrayList<String> cellList = new ArrayList<>(); + cellList.add("cell1"); + PowerMockito.mockStatic(OofRestClient.class); + try { + PowerMockito.when(OofRestClient.queryOof(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.anyList(), + Mockito.anyString(), Mockito.anyList(), Mockito.anyList())).thenReturn("oofResponse"); + } catch (OofNotFoundException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + try { + transactionId = oof.triggerOof(cellList, "networkId", null); + } catch (OofNotFoundException | InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertNotNull(transactionId); + } +} 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 index ca5f5fd..ab4119d 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java @@ -21,6 +21,11 @@ package org.onap.dcaegen2.services.sonhms.child; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + import com.fasterxml.jackson.databind.ObjectMapper; import java.io.BufferedReader; @@ -35,77 +40,175 @@ import java.util.Map; 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.MockitoAnnotations; import org.onap.dcaegen2.services.sonhms.ConfigPolicy; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.dao.SonRequestsRepository; +import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; +import org.onap.dcaegen2.services.sonhms.entity.SonRequests; +import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.onap.dcaegen2.services.sonhms.model.PolicyNotification; +import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; +import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; +import org.onap.dcaegen2.services.sonhms.restclient.Solutions; +import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest; +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, SdnrRestClient.class }) +@SpringBootTest(classes = TestChildThreadUtils.class) public class TestChildThreadUtils { - - ChildThreadUtils childThreadUtils; - - @Before - public void setup() { - - ConfigPolicy configPolicy = ConfigPolicy.getInstance(); - - Map<String, Object> configPolicyMap = new HashMap<>(); - configPolicyMap.put("PCI_MODCONFIG_POLICY_NAME", "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459"); - configPolicy.setConfig(configPolicyMap); - childThreadUtils = new ChildThreadUtils(configPolicy); - } - - @Test - public void getNotificationStringTest() { - - String policy_notif = readFromFile("/policy_notification.json"); - PolicyNotification expected = new PolicyNotification(); - ObjectMapper mapper = new ObjectMapper(); - - try { - expected = mapper.readValue(policy_notif, PolicyNotification.class); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - String pnfName = "ncserver23"; - List<CellPciPair> cellPciPairs = new ArrayList<>(); - - cellPciPairs.add(new CellPciPair("Chn0330", 6)); - cellPciPairs.add(new CellPciPair("Chn0331", 7)); - String requestId = "a4130fd5-2291-4a83-8992-04e4c9f32731"; - Long alarmStart = Long.parseLong("1542445563201"); - - String result = childThreadUtils.getNotificationString(pnfName, cellPciPairs, requestId, alarmStart); - PolicyNotification actual = new PolicyNotification(); - try { - actual = mapper.readValue(result, PolicyNotification.class); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Assert.assertEquals(expected.hashCode(), actual.hashCode()); - } - - private static String readFromFile(String file) { - String content = new String(); + + ChildThreadUtils childThreadUtils; + @Mock + private SonRequestsRepository repository; + + @Mock + private PnfUtils pnfUtils; + @Mock + private PolicyDmaapClient policyDmaapClient; + + @InjectMocks + private ChildThreadUtils childThreadUtils2; + + @Before + public void setup() { + + ConfigPolicy configPolicy = ConfigPolicy.getInstance(); + Configuration config = Configuration.getInstance(); + config.setMinCollision(5); + config.setMinConfusion(5); + Map<String, Object> configPolicyMap = new HashMap<>(); + configPolicyMap.put("PCI_MODCONFIG_POLICY_NAME", "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459"); + configPolicy.setConfig(configPolicyMap); + childThreadUtils = new ChildThreadUtils(configPolicy, pnfUtils, policyDmaapClient); + MockitoAnnotations.initMocks(this); + + } + + @Test + public void savePciRequestTest() { + SonRequests sonRequest = new SonRequests(); + sonRequest.setTransactionId("transactionId"); + sonRequest.setChildThreadId(1L); + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(SonRequestsRepository.class)) + .thenReturn(repository); + when(repository.save(sonRequest)).thenReturn(sonRequest); + childThreadUtils2.saveRequest("transactionId",1L);; + assertEquals(sonRequest, repository.save(sonRequest)); + } + + @Test + public void triggerOrWaitTest() { + Map<String, ArrayList<Integer>> collisionConfusionResult = new HashMap<String, ArrayList<Integer>>(); + ArrayList<Integer> list = new ArrayList<Integer>(); + list.add(6); + list.add(7); + collisionConfusionResult.put("cellId", list); + + Boolean result = childThreadUtils.triggerOrWait(collisionConfusionResult); + assertTrue(result); + Map<String, ArrayList<Integer>> collisionConfusionResult1 = new HashMap<String, ArrayList<Integer>>(); + + ArrayList<Integer> list1 = new ArrayList<Integer>(); + list1.add(1); + list1.add(2); + collisionConfusionResult1.put("cell1", list1); + result = childThreadUtils.triggerOrWait(collisionConfusionResult1); + assertFalse(result); + + } + + @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) { + e.printStackTrace(); + } + + String pnfName = "ncserver23"; + List<CellPciPair> cellPciPairs = new ArrayList<>(); + + cellPciPairs.add(new CellPciPair("Chn0330", 6)); + cellPciPairs.add(new CellPciPair("Chn0331", 7)); + String requestId = "a4130fd5-2291-4a83-8992-04e4c9f32731"; + Long alarmStart = Long.parseLong("1542445563201"); + + String result = childThreadUtils.getNotificationString(pnfName, cellPciPairs, requestId, alarmStart); + PolicyNotification actual = new PolicyNotification(); + try { + actual = mapper.readValue(result, PolicyNotification.class); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("actual :; "+result+"\nexp "+policy_notif); + Assert.assertEquals(expected.hashCode(), actual.hashCode()); + } + + @Test + public void sendToPolicyTest() throws ConfigDbNotFoundException { + + PowerMockito.mockStatic(SdnrRestClient.class); + String asyncRspBodyString = readFromFile("/AsyncRespBody.json"); + ObjectMapper mapper = new ObjectMapper(); + AsyncResponseBody async = new AsyncResponseBody (); 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) { + async = mapper.readValue(asyncRspBodyString, AsyncResponseBody.class); + } catch (Exception e) { e.printStackTrace(); - content = null; } - return content; - } + PowerMockito.when(SdnrRestClient.getPci(Mockito.anyString())).thenReturn(3); + PowerMockito.when(SdnrRestClient.getPnfName(Mockito.anyString())).thenReturn("pnfName"); + when(policyDmaapClient.sendNotificationToPolicy(Mockito.anyString())).thenReturn(true); + Map<String,List<CellPciPair>> pnfsMap = new HashMap<String,List<CellPciPair>>(); + CellPciPair cell1 = new CellPciPair("cell0", 1); + CellPciPair cell2 = new CellPciPair("cell1", 2); + CellPciPair cell3 = new CellPciPair("cell2", 3); + List<CellPciPair> pciPairList = new ArrayList<>(); + pciPairList.add(cell1); + pciPairList.add(cell2); + pciPairList.add(cell3); + pnfsMap.put("pnf1", pciPairList); + when(pnfUtils.getPnfs(Mockito.any(Solutions.class))).thenReturn(pnfsMap); + childThreadUtils.sendToPolicy(async); + } + + 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 index 05d3e79..81641f3 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestDetection.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestDetection.java @@ -22,6 +22,8 @@ package org.onap.dcaegen2.services.sonhms.child; +import static org.junit.Assert.assertEquals; + import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -105,10 +107,9 @@ public class TestDetection { cluster.setCellPciNeighbourMap(map); - System.out.println("mapsssssss" + cluster.getCellPciNeighbourMap()); Detection detect = new Detection(); - detect.detectCollisionConfusion(cluster); - System.out.println("result" + detect.detectCollisionConfusion(cluster)); + Map<String,ArrayList<Integer>> resultmap=detect.detectCollisionConfusion(cluster); + assertEquals("{78=[], 56=[], 67=[], 24=[], 25=[0, 1], 69=[], 38=[], 42=[0, 0], 21=[], 32=[1, 0]}", resultmap.toString()); } 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 index 0349521..4b36598 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java @@ -22,7 +22,6 @@ package org.onap.dcaegen2.services.sonhms.child; import static org.junit.Assert.assertEquals; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.BufferedReader; @@ -48,7 +47,7 @@ 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.restclient.Solutions; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.onap.dcaegen2.services.sonhms.utils.ClusterUtilsTest; import org.powermock.api.mockito.PowerMockito; @@ -69,7 +68,7 @@ public class TestPnfUtils { private CellInfoRepository cellInfoRepositoryMock; private static final Logger log = org.slf4j.LoggerFactory.getLogger(TestPnfUtils.class); - private static List<Solution> solutions = new ArrayList<>(); + private static Solutions solutions = new Solutions(); private static Optional<CellInfo> cellInfo; private static Optional<CellInfo> cellInfoNull; @@ -85,7 +84,7 @@ public class TestPnfUtils { ObjectMapper mapper = new ObjectMapper(); try { - solutions=mapper.readValue(solutionsString,new TypeReference<List<Solution>>(){}); + solutions=mapper.readValue(solutionsString, Solutions.class); } catch (IOException e) { log.debug("Exception in StateOof Test "+e); 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 index 4fa8227..486ed27 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducerTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/NotificationProducerTest.java @@ -27,6 +27,7 @@ import static org.mockito.Mockito.when; import com.att.nsa.cambria.client.CambriaBatchingPublisher; import java.io.IOException; + import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; 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 index bf22fd6..488c671 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/entity/PciRequestsTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/entity/PciRequestsTest.java @@ -29,10 +29,10 @@ 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()); + SonRequests sonRequests=new SonRequests(); + sonRequests.setChildThreadId(1L); + sonRequests.setTransactionId("transactionId"); + assertEquals(1L, sonRequests.getChildThreadId()); + assertEquals("transactionId", sonRequests.getTransactionId()); } } 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 index 29590f9..12c4912 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/NotificationTest.java @@ -45,7 +45,7 @@ public class NotificationTest { ArrayList<LteNeighborListInUseLteCell> list = new ArrayList<>(); list.add(lteNeighborListInUseLteCell); - NeighborListInUse neighborListInUse = new NeighborListInUse(list, "1"); + NeighborListInUse neighborListInUse = new NeighborListInUse(list, null, "1"); NotificationRan notificationRan = new NotificationRan(neighborListInUse, "Cell25"); NotificationLte notificationLte = new NotificationLte(notificationRan); 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 index 1aae8c2..e89c8c3 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/model/PayloadTest.java @@ -35,7 +35,7 @@ public class PayloadTest { public void payloadTest() { Common common = new Common("cell1"); - Ran ran = new Ran(common); + Ran ran = new Ran(common, null); Lte lte = new Lte(ran); 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 index fcc2c31..a97bd1a 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBodyTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/AsyncResponseBodyTest.java @@ -21,6 +21,8 @@ package org.onap.dcaegen2.services.sonhms.restclient; +import static org.junit.Assert.assertEquals; + import java.util.ArrayList; import java.util.List; @@ -35,20 +37,28 @@ public class AsyncResponseBodyTest { AsyncResponseBody asyncResponseBody = new AsyncResponseBody(); asyncResponseBody.setRequestId("e44a4165-3cf4-4362-89de-e2375eed97e7"); asyncResponseBody.setRequestStatus("completed"); - SonSolution pciSolutions = new SonSolution(); + PciSolutions pciSolutions = new PciSolutions(); + AnrSolutions anrSolutions = new AnrSolutions(); + pciSolutions.setCellId("EXP001"); pciSolutions.setPci(101); - List<SonSolution> pciSolutionsList = new ArrayList<SonSolution>(); + anrSolutions.setCellId("cell2"); + + List<PciSolutions> pciSolutionsList = new ArrayList<PciSolutions>(); + List<AnrSolutions> anrSolutionsList = new ArrayList<AnrSolutions>(); + + anrSolutionsList.add(anrSolutions); pciSolutionsList.add(pciSolutions); - Solution solutions = new Solution(); - solutions.setFinishTime("2018-10-01T00:40+01.00"); - solutions.setNetworkId("EXP001"); + Solutions solutions = new Solutions(); solutions.setPciSolutions(pciSolutionsList); - solutions.setStartTime("2018-10-01T00:30+01:00"); - ArrayList<Solution> solutionsList = new ArrayList<Solution>(); - solutionsList.add(solutions); - asyncResponseBody.setSolutions(solutionsList); + solutions.setAnrSolutions(anrSolutionsList); + asyncResponseBody.setSolutions(solutions); asyncResponseBody.setStatusMessage("success"); asyncResponseBody.setTransactionId("3df7b0e9-26d1-4080-ba42-28e8a3139689"); + assertEquals("success", asyncResponseBody.getStatusMessage()); + assertEquals("3df7b0e9-26d1-4080-ba42-28e8a3139689", asyncResponseBody.getTransactionId()); + assertEquals(solutions, asyncResponseBody.getSolutions()); + assertEquals("completed", asyncResponseBody.getRequestStatus()); + assertEquals("e44a4165-3cf4-4362-89de-e2375eed97e7", asyncResponseBody.getRequestId()); } } 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 index 75af4fe..7451ca5 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClientTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/OofRestClientTest.java @@ -34,6 +34,7 @@ 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.model.AnrInput; import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -85,6 +86,7 @@ public class OofRestClientTest { cellIdList.add("EXP001"); List<String> optimizers=new ArrayList<String>(); optimizers.add("pci"); + List<AnrInput> anrInputList = new ArrayList<>(); PowerMockito.mockStatic(SonHandlerRestTemplate.class); PowerMockito.mockStatic(Configuration.class); @@ -94,7 +96,8 @@ public class OofRestClientTest { try { - String result=OofRestClient.queryOof(1, "xxx-xxx-xxxx", "create", cellIdList, "NTWK005", optimizers); + + String result=OofRestClient.queryOof(1, "xxx-xxx-xxxx", "create", cellIdList, "NTWK005", optimizers, anrInputList); assertEquals(ResponseEntity.ok(responseBody).getBody(), result); @@ -105,9 +108,8 @@ public class OofRestClientTest { PowerMockito.when(SonHandlerRestTemplate.sendPostRequestToOof(Mockito.anyString(),Mockito.anyString() ,Matchers.<ParameterizedTypeReference<String>>any())) .thenReturn(null); try { - String result=OofRestClient.queryOof(1, "xxx-xxx-xxxx", "create", cellIdList, "NTWK005", optimizers); - assertEquals(ResponseEntity.ok(responseBody).getBody(), result); + OofRestClient.queryOof(1, "xxx-xxx-xxxx", "create", cellIdList, "NTWK005", optimizers, new ArrayList<>()); } catch (OofNotFoundException e) { // TODO Auto-generated catch block 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 index 79d27ad..1ff0546 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutionsTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/PciSolutionsTest.java @@ -29,7 +29,7 @@ import org.junit.Test; public class PciSolutionsTest { @Test public void pciSolutionsTest() { - SonSolution pciSolutions = new SonSolution(); + PciSolutions pciSolutions = new PciSolutions(); pciSolutions.setCellId("EXP001"); pciSolutions.setPci(101); assertEquals("EXP001", pciSolutions.getCellId()); 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 index bffccfc..1557e51 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java @@ -37,6 +37,7 @@ 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.BeanUtil; import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -53,7 +54,9 @@ import org.springframework.test.context.junit4.SpringRunner; @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 @@ -68,6 +71,7 @@ public class SdnrRestClientTest { " \"string\"\n" + "]"; PowerMockito.mockStatic(SonHandlerRestTemplate.class); + PowerMockito.mockStatic(BeanUtil.class); PowerMockito.mockStatic(Configuration.class); PowerMockito.when(Configuration.getInstance()).thenReturn(configuration); PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any())) 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 index 9286629..75cd881 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SolutionsTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SolutionsTest.java @@ -35,20 +35,26 @@ public class SolutionsTest { @Test public void solutionsTest() { - SonSolution pciSolutions = new SonSolution(); + Solutions solutions = new Solutions(); + List<AnrSolutions> anrSolutionsList = new ArrayList<>(); + List<PciSolutions> pciSolutionsList = new ArrayList<>(); + + PciSolutions pciSolutions = new PciSolutions(); pciSolutions.setCellId("EXP001"); pciSolutions.setPci(101); - List<SonSolution> pciSolutionsList = new ArrayList<SonSolution>(); pciSolutionsList.add(pciSolutions); - Solution solutions = new Solution(); - solutions.setFinishTime("2018-10-01T00:40+01.00"); + AnrSolutions anrSolutions = new AnrSolutions(); + anrSolutions.setCellId("EXP001"); + List<String> removeableNeighbors = new ArrayList<>(); + removeableNeighbors.add("cell001"); + anrSolutions.setRemoveableNeighbors(removeableNeighbors); + anrSolutionsList.add(anrSolutions); solutions.setNetworkId("EXP001"); solutions.setPciSolutions(pciSolutionsList); - solutions.setStartTime("2018-10-01T00:30+01:00"); - assertEquals("2018-10-01T00:40+01.00", solutions.getFinishTime()); + solutions.setAnrSolutions(anrSolutionsList); assertEquals("EXP001", solutions.getNetworkId()); assertEquals(pciSolutionsList, solutions.getPciSolutions()); - assertEquals("2018-10-01T00:30+01:00", solutions.getStartTime()); + assertEquals(anrSolutionsList, solutions.getAnrSolutions()); } 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 index 48813e1..03305a1 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java @@ -67,205 +67,211 @@ import org.springframework.test.context.junit4.SpringRunner; @PowerMockRunnerDelegate(SpringRunner.class) @PrepareForTest({ SdnrRestClient.class, BeanUtil.class }) @SpringBootTest(classes = ClusterUtils.class) -public class ClusterUtilsTest { - +public class ClusterUtilsTest { + @Mock private ClusterDetailsRepository clusterDetailsRepositoryMock; - + @InjectMocks ClusterUtils clusterUtils; - + private static Notification notification1; private static Notification notification2; private static List<ClusterDetails> clusterDetailsForGetClusterDetailsFromClusterIdTest; private static Graph cluster; private static List<ClusterDetails> clusterDetails = new ArrayList<>(); - + @BeforeClass public static void setup() { - + notification1 = new Notification(); notification2 = new Notification(); clusterDetailsForGetClusterDetailsFromClusterIdTest = new ArrayList<ClusterDetails>(); - + String notificationString1 = readFromFile("/notification1.json"); String notificationString2 = readFromFile("/notification2.json"); - String clusterDetailsListString=readFromFile("/ClusterDetailsTest.json"); - + String 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); - + cluster = new Graph(clusterInfo); + clusterDetails.add(new ClusterDetails("1", clusterInfo1, 35)); clusterDetails.add(new ClusterDetails("2", clusterInfo2, 36)); clusterDetails.add(new ClusterDetails("3", clusterInfo3, 37)); clusterDetails.add(new ClusterDetails("4", clusterInfo4, 38)); - - + ObjectMapper mapper = new ObjectMapper(); - + try { notification1 = mapper.readValue(notificationString1, Notification.class); notification2 = mapper.readValue(notificationString2, Notification.class); - clusterDetailsForGetClusterDetailsFromClusterIdTest=mapper.readValue(clusterDetailsListString,new TypeReference<List<ClusterDetails>>(){}); + clusterDetailsForGetClusterDetailsFromClusterIdTest = mapper.readValue(clusterDetailsListString, + new TypeReference<List<ClusterDetails>>() { + }); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } - - - + } - + @Before public void setupTest() { - clusterUtils = new ClusterUtils(); + clusterUtils = new ClusterUtils(); MockitoAnnotations.initMocks(this); - } - + } + @Test - public void getClustersForNotificationTest(){ - + public void getClustersForNotificationTest() { + NotificationToClusterMapping expected = new NotificationToClusterMapping(); Map<FapServiceList, String> cellsinCluster = new HashMap<>(); cellsinCluster.put(notification1.getPayload().getRadioAccess().getFapServiceList().get(0), "2"); expected.setCellsinCluster(cellsinCluster); expected.setNewCells(new ArrayList<FapServiceList>()); - + NotificationToClusterMapping result = clusterUtils.getClustersForNotification(notification1, clusterDetails); assertEquals(expected, result); - + expected = new NotificationToClusterMapping(); List<FapServiceList> newCells = new ArrayList<>(); newCells.add(notification2.getPayload().getRadioAccess().getFapServiceList().get(0)); expected.setCellsinCluster(new HashMap<>()); expected.setNewCells(newCells); - + result = clusterUtils.getClustersForNotification(notification2, clusterDetails); assertEquals(expected, result); } - + @Test public void createClusterTest() throws ConfigDbNotFoundException { - - FapServiceList fapServiceList = notification1.getPayload().getRadioAccess().getFapServiceList().get(0); - + + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = new HashMap<CellPciPair, ArrayList<CellPciPair>>(); + + List<CellPciPair> firstNbrList = new ArrayList<>(); List<CellPciPair> nbrList = new ArrayList<>(); - + + firstNbrList.add(new CellPciPair("48", 0)); nbrList.add(new CellPciPair("44", 3)); - + PowerMockito.mockStatic(SdnrRestClient.class); - + PowerMockito.when(SdnrRestClient.getNbrList(Mockito.anyString())).thenReturn(nbrList); - - assertEquals(cluster, clusterUtils.createCluster(fapServiceList)); - - - + + clusterMap.put(new CellPciPair("45", 310), (ArrayList<CellPciPair>) firstNbrList); + + assertEquals(cluster, clusterUtils.createCluster(clusterMap)); + } - + @Test public void getClusterDetailsFromClusterIdTest() { - ClusterDetails responseValue=null; + ClusterDetails responseValue = null; Integer responseVal = null; - Integer expectedValue=404; - Either<ClusterDetails, Integer> response=clusterUtils.getClusterDetailsFromClusterId("0",clusterDetailsForGetClusterDetailsFromClusterIdTest); + Integer expectedValue = 404; + Either<ClusterDetails, Integer> response = clusterUtils.getClusterDetailsFromClusterId("0", + clusterDetailsForGetClusterDetailsFromClusterIdTest); assertTrue(response.isLeft()); - if(response.isLeft()) { - responseValue=response.left().value(); + if (response.isLeft()) { + responseValue = response.left().value(); } - assertEquals(clusterDetailsForGetClusterDetailsFromClusterIdTest.get(0),responseValue); - response=clusterUtils.getClusterDetailsFromClusterId("1",clusterDetailsForGetClusterDetailsFromClusterIdTest); + assertEquals(clusterDetailsForGetClusterDetailsFromClusterIdTest.get(0), responseValue); + response = clusterUtils.getClusterDetailsFromClusterId("1", + clusterDetailsForGetClusterDetailsFromClusterIdTest); assertTrue(response.isLeft()); - if(response.isLeft()) { - responseValue=response.left().value(); + if (response.isLeft()) { + responseValue = response.left().value(); } - assertEquals(clusterDetailsForGetClusterDetailsFromClusterIdTest.get(1),responseValue); - response=clusterUtils.getClusterDetailsFromClusterId("9",clusterDetailsForGetClusterDetailsFromClusterIdTest); + assertEquals(clusterDetailsForGetClusterDetailsFromClusterIdTest.get(1), responseValue); + response = clusterUtils.getClusterDetailsFromClusterId("9", + clusterDetailsForGetClusterDetailsFromClusterIdTest); assertTrue(response.isRight()); - if(response.isRight()) { - responseVal=response.right().value(); + if (response.isRight()) { + responseVal = response.right().value(); } - assertEquals(expectedValue,responseVal); + 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)); + ClusterDetails details = new ClusterDetails(); + details.setClusterId("123e4567-e89b-12d3-a456-426655440000"); + details.setClusterInfo("cellPciNeighbourString"); + details.setChildThreadId(978668); + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil.getBean(ClusterDetailsRepository.class)).thenReturn(clusterDetailsRepositoryMock); + Mockito.when(clusterDetailsRepositoryMock.save(details)).thenReturn(details); + Long threadId = (long) 978668; + clusterUtils.saveCluster(cluster, UUID.fromString("123e4567-e89b-12d3-a456-426655440000"), threadId); + assertEquals(details, clusterDetailsRepositoryMock.save(details)); } - + @Test public void getClusterForCellTest() { - FapServiceList fapServiceList= notification1.getPayload().getRadioAccess().getFapServiceList().get(0); - String clusterInfo1=readFromFile("/clusterInfo1.json"); - String clusterInfo2=readFromFile("/clusterInfo2.json"); - Graph graph1=new Graph(clusterInfo1); - Graph graph2=new Graph(clusterInfo2); - List<Graph> newClusters=new ArrayList<Graph>(); + FapServiceList fapServiceList = notification1.getPayload().getRadioAccess().getFapServiceList().get(0); + String clusterInfo1 = readFromFile("/clusterInfo1.json"); + String clusterInfo2 = readFromFile("/clusterInfo2.json"); + Graph graph1 = new Graph(clusterInfo1); + Graph graph2 = new Graph(clusterInfo2); + List<Graph> newClusters = new ArrayList<Graph>(); newClusters.add(graph1); newClusters.add(graph2); - Either<Graph, Integer> result=clusterUtils.getClusterForCell(fapServiceList, newClusters); + Either<Graph, Integer> result = clusterUtils.getClusterForCell(fapServiceList, newClusters); assertTrue(result.isLeft()); - + newClusters = new ArrayList<>(); newClusters.add(graph1); - result=clusterUtils.getClusterForCell(fapServiceList, newClusters); + result = clusterUtils.getClusterForCell(fapServiceList, newClusters); assertTrue(result.isRight()); - int resultRight=result.right().value(); + int resultRight = result.right().value(); assertEquals(404, resultRight); - - List<Graph> emptyList=new ArrayList<Graph>(); - - result=clusterUtils.getClusterForCell(fapServiceList, emptyList); + + List<Graph> emptyList = new ArrayList<Graph>(); + + result = clusterUtils.getClusterForCell(fapServiceList, emptyList); assertTrue(result.isRight()); - resultRight=result.right().value(); + 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))); + Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = new HashMap<CellPciPair, ArrayList<CellPciPair>>(); + + ArrayList<CellPciPair> firstNbrList = new ArrayList<>(); + firstNbrList.add(new CellPciPair("48",0)); + clusterMap.put(new CellPciPair("45",310),firstNbrList); + assertEquals(expected, clusterUtils.modifyCluster(cluster,clusterMap)); } - + private static String readFromFile(String file) { - String content = new String(); + 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) { + while ((temp = bufferedReader.readLine()) != null) { content = content.concat(temp); } content = content.trim(); bufferedReader.close(); - } - catch(Exception e) { - content = null; + } catch (Exception e) { + content = null; } return content; } diff --git a/src/test/resources/AsyncRespBody.json b/src/test/resources/AsyncRespBody.json new file mode 100644 index 0000000..08a8e51 --- /dev/null +++ b/src/test/resources/AsyncRespBody.json @@ -0,0 +1,23 @@ +{ + "requestId":"9d2d790e-a5f0-11e8-98d0-529269fb1459", + "transactionId":"9d2d790e-a5f0-11e8-98d0-529269fb1458", + "statusMessage":"accepted", + "requestStatus":"success", + "solutions":{ + "networkId":"NTWK005", + "pciSolutions":[ + { + "cellId":"EXP001", + "pci":"101" + }, + { + "cellId":"EXP002", + "pci":"102" + } + ], + "anrSolutions":[ + {"cellId":"EXP003", + "removeableNeighbors":["EXP006"]} + ] + } +} diff --git a/src/test/resources/ClusterDetailsTest.json b/src/test/resources/ClusterDetailsTest.json index 01839ae..24b6d8d 100644 --- a/src/test/resources/ClusterDetailsTest.json +++ b/src/test/resources/ClusterDetailsTest.json @@ -1,10 +1,13 @@ -[{"clusterId":"0", -"clusterInfo":"", - "childThreadId":986476 -}, -{"clusterId":"1", -"clusterInfo":"", - "childThreadId":986475 -} +[ + { + "clusterId": "0", + "clusterInfo": "", + "childThreadId": 986476 + }, + { + "clusterId": "1", + "clusterInfo": "", + "childThreadId": 986475 + } ] diff --git a/src/test/resources/clusterInfo1.json b/src/test/resources/clusterInfo1.json index 685d923..d78d86e 100644 --- a/src/test/resources/clusterInfo1.json +++ b/src/test/resources/clusterInfo1.json @@ -1 +1,12 @@ -[{"cellId":"29","physicalCellId":209,"neighbours":"[]"},{"cellId":"25","physicalCellId":32,"neighbours":"[{\"physicalCellId\":209,\"cellId\":\"29\"}]"}] +[ + { + "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 index 6fe6d5e..eeadde3 100644 --- a/src/test/resources/clusterInfo2.json +++ b/src/test/resources/clusterInfo2.json @@ -1 +1,12 @@ -[{"cellId":"45","physicalCellId":310,"neighbours":"[]"},{"cellId":"47","physicalCellId":302,"neighbours":"[{\"physicalCellId\":310,\"cellId\":\"45\"}]"}] +[ + { + "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 index 71e7736..2188654 100644 --- a/src/test/resources/clusterInfo3.json +++ b/src/test/resources/clusterInfo3.json @@ -1 +1,12 @@ -[{"cellId":"72","physicalCellId":2,"neighbours":"[]"},{"cellId":"63","physicalCellId":5,"neighbours":"[{\"physicalCellId\":2,\"cellId\":\"72\"}]"}] +[ + { + "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 index 4da8c07..f620e73 100644 --- a/src/test/resources/clusterInfo4.json +++ b/src/test/resources/clusterInfo4.json @@ -1 +1,12 @@ -[{"cellId":"2","physicalCellId":20,"neighbours":"[]"},{"cellId":"5","physicalCellId":30,"neighbours":"[{\"physicalCellId\":20,\"cellId\":\"2\"}]"}] +[ + { + "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 index 7612d10..37c1a13 100644 --- a/src/test/resources/clusterInfo5.json +++ b/src/test/resources/clusterInfo5.json @@ -1 +1,17 @@ -[{"cellId":"44","physicalCellId":3,"neighbours":"[]"},{"cellId":"48","physicalCellId":0,"neighbours":"[{\"physicalCellId\":3,\"cellId\":\"44\"}]"},{"cellId":"45","physicalCellId":310,"neighbours":"[{\"physicalCellId\":0,\"cellId\":\"48\"}]"}] +[ + { + "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 index 88e0763..a49ab9a 100644 --- a/src/test/resources/clusterInfo6.json +++ b/src/test/resources/clusterInfo6.json @@ -1 +1,17 @@ -[{"cellId":"48","physicalCellId":0,"neighbours":"[]"},{"cellId":"45","physicalCellId":310,"neighbours":"[{\"physicalCellId\":0,\"cellId\":\"48\"}]"},{"cellId":"47","physicalCellId":302,"neighbours":"[{\"physicalCellId\":310,\"cellId\":\"45\"}]"}] +[ + { + "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 index 1d8dc7d..b9ebc65 100644 --- a/src/test/resources/clusterInfo7.json +++ b/src/test/resources/clusterInfo7.json @@ -1 +1,12 @@ -[{"cellId":"82","physicalCellId":32,"neighbours":"[]"},{"cellId":"81","physicalCellId":31,"neighbours":"[{\"physicalCellId\":32,\"cellId\":\"82\"}]"}] +[ + { + "cellId": "82", + "physicalCellId": 32, + "neighbours": "[]" + }, + { + "cellId": "81", + "physicalCellId": 31, + "neighbours": "[{\"physicalCellId\":32,\"cellId\":\"82\"}]" + } +] diff --git a/src/test/resources/hoDetails.json b/src/test/resources/hoDetails.json new file mode 100644 index 0000000..be8f161 --- /dev/null +++ b/src/test/resources/hoDetails.json @@ -0,0 +1,14 @@ +[ + { + "dstCellId":"Chn0014", + "attemptsCount":200, + "successCount":190, + "successRate":95 + }, + { + "dstCellId":"Chn0013", + "attemptsCount":300, + "successCount":210, + "successRate":70 + } +] diff --git a/src/test/resources/notification1.json b/src/test/resources/notification1.json index 87f60e6..ee6c847 100644 --- a/src/test/resources/notification1.json +++ b/src/test/resources/notification1.json @@ -1,45 +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" - } - ] - } - } - } - } - } - ] - } - } + "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 index 702b643..7d0a8ad 100644 --- a/src/test/resources/notification2.json +++ b/src/test/resources/notification2.json @@ -1,55 +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" - } - ] - } - } - } - } - } - ] - } - } + "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 index 4a3a2a0..2588f3c 100644 --- a/src/test/resources/notification3.json +++ b/src/test/resources/notification3.json @@ -1,45 +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" - } - ] - } - } - } - } - } - ] - } - } + "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/pmNotification.json b/src/test/resources/pmNotification.json new file mode 100644 index 0000000..a956ae4 --- /dev/null +++ b/src/test/resources/pmNotification.json @@ -0,0 +1,56 @@ + + { + "event":{ + "commonEventHeader":{ + "version":"4.0", + "domain":"measurement", + "eventName":"Measurement_RansimAgent-Wipro_HandoffMetric", + "eventId":"measurement000001", + "sequence":0, + "priority":"Normal", + "reportingEntityId":"cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName":"ncserver1", + "sourceId":"de305d54-75b4-431b-adb2-eb6b9e546456", + "sourceName":"Chn0001", + "startEpochMicrosec":1551772223000000, + "lastEpochMicrosec":1551790542000000, + "nfNamingCode":"RansimAgent", + "nfVendorName":"Wipro", + "vesEventListenerVersion":"7.0.1", + "timeZoneOffset":"UTC-05:30" + }, + "measurement":{ + "measurementInterval":180, + "additionalMeasurements":[ + { + "arrayOfNamedHashMap":[ + { + "networkId":"plmnid1" + }, + { + "InterEnbOutAtt_X2HO":"200" + }, + { + "InterEnbOutSucc_X2HO":"190" + } + ], + "name":"Chn0014" + }, + { + "arrayOfNamedHashMap":[ + { + "networkId":"plmnid1" + }, + { + "InterEnbOutAtt_X2HO":"300" + }, + { + "InterEnbOutSucc_X2HO":"210" + } + ], + "name":"Chn0013" + } + ] + } + } + } diff --git a/src/test/resources/pmNotification1.json b/src/test/resources/pmNotification1.json new file mode 100644 index 0000000..0f046e2 --- /dev/null +++ b/src/test/resources/pmNotification1.json @@ -0,0 +1,55 @@ +{ + "event": { + "commonEventHeader": { + "version": "4.0", + "domain": "measurement", + "eventName": "Measurement_RansimAgent-Wipro_HandoffMetric", + "eventId": "measurement000002", + "sequence": 0, + "priority": "Normal", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e544567", + "reportingEntityName": "ncserver1", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546456", + "sourceName": "Chn0002", + "startEpochMicrosec": 1551772223000000, + "lastEpochMicrosec": 1551790542000000, + "nfNamingCode": "RansimAgent", + "nfVendorName": "Wipro", + "vesEventListenerVersion": "7.0.1", + "timeZoneOffset": "UTC-05:30" + }, + "measurement": { + "measurementInterval": 180, + "additionalMeasurements": [ + { + "arrayOfNamedHashMap": [ + { + "networkId":"plmnid1" + }, + { + "InterEnbOutAtt_X2HO":"300" + }, + { + "InterEnbOutSucc_X2HO":"100" + } + ], + "name": "Chn0004" + }, + { + "arrayOfNamedHashMap": [ + { + "networkId":"plmnid1" + }, + { + "InterEnbOutAtt_X2HO":"250" + }, + { + "InterEnbOutSucc_X2HO":"100" + } + ], + "name": "Chn0001" + } + ] + } + } + } diff --git a/src/test/resources/policy_notification.json b/src/test/resources/policy_notification.json index b9a6910..3863d1c 100644 --- a/src/test/resources/policy_notification.json +++ b/src/test/resources/policy_notification.json @@ -1,20 +1,18 @@ { - - "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" - + "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 index cf82283..8f6f41f 100644 --- a/src/test/resources/solutions.json +++ b/src/test/resources/solutions.json @@ -1 +1,16 @@ -[{"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"}]}] +{ + "networkId":"NTWK005", + "pciSolutions":[ + { + "cellId":"EXP001", + "pci":"101" + }, + { + "cellId":"EXP002", + "pci":"102" + } + ], + "anrSolutions":[ + + ] +} |