diff options
author | krishna <krishna.moorthy6@wipro.com> | 2019-05-20 17:36:59 +0530 |
---|---|---|
committer | Vijay Venkatesh Kumar <vv770d@att.com> | 2019-05-20 19:22:36 +0000 |
commit | d290a8c6849bfd957363ec4c57a477c650429971 (patch) | |
tree | 784e2804b9c053c97e7b98612e715e31178bfab9 /src/test/java/org | |
parent | cf1fb180941364f253de8aea9e1c811abe8b89db (diff) |
Change oof trigger functionality considering multiple PM events
Change-Id: I29ec91238b451263127822480e27c6f423635404
Issue-ID: DCAEGEN2-1513
Signed-off-by: krishna <krishna.moorthy6@wipro.com>
Diffstat (limited to 'src/test/java/org')
8 files changed, 71 insertions, 17 deletions
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 68b94fb..f762a5b 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/ConfigurationTest.java @@ -61,7 +61,8 @@ public class ConfigurationTest { configuration.setOofService("oofService"); configuration.setBadThreshold(50); configuration.setPoorThreshold(70); - configuration.setOptimizers(list); + configuration.setPciOptimizer("pci"); + configuration.setPciAnrOptimizer("pci-anr"); configuration.setPollingInterval(30); configuration.setPollingTimeout(100); configuration.setConfigDbService("sdnrService"); @@ -77,7 +78,8 @@ public class ConfigurationTest { assertEquals(5, configuration.getMinConfusion()); assertEquals(1, configuration.getNumSolutions()); assertEquals("oofService", configuration.getOofService()); - assertEquals(list, configuration.getOptimizers()); + assertEquals("pci", configuration.getPciOptimizer()); + assertEquals("pci-anr", configuration.getPciAnrOptimizer()); assertEquals("user", configuration.getPgUsername()); assertEquals("password", configuration.getPgPassword()); assertEquals("pg", configuration.getPgHost()); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponentTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponentTest.java index 9ac056b..4bc4a33 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponentTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/HoMetricsComponentTest.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; @@ -30,6 +31,7 @@ import fj.data.Either; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.ArrayList; import java.util.List; import org.junit.BeforeClass; @@ -38,6 +40,7 @@ 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.entity.HandOverMetrics; import org.onap.dcaegen2.services.sonhms.model.HoDetails; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; import org.powermock.api.mockito.PowerMockito; @@ -80,6 +83,22 @@ public class HoMetricsComponentTest { assertEquals(400,res); } + @Test + public void getAllTest() { + PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.when(BeanUtil + .getBean(HandOverMetricsRepository.class)).thenReturn(handOverMetricsRepositoryMock); + HandOverMetrics hoMetrics = new HandOverMetrics(); + hoMetrics.setHoDetails("hoDetails"); + hoMetrics.setSrcCellId("cell1"); + List<HandOverMetrics> hoList = new ArrayList<>(); + hoList.add(hoMetrics); + Iterable<HandOverMetrics> response = hoList; + when(handOverMetricsRepositoryMock.findAll()).thenReturn(response); + assertTrue(hoMetricsComponent.getAll().isLeft()); + when(handOverMetricsRepositoryMock.findAll()).thenReturn(null); + assertTrue(hoMetricsComponent.getAll().isRight()); + } private static String readFromFile(String file) { String content = new String(); try { diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java index cbd0265..18f9e02 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/PMNotificationHandlerTest.java @@ -99,9 +99,9 @@ public class PMNotificationHandlerTest { when(flagMock.getHolder()).thenReturn("NONE"); when(policyDmaapClient.sendNotificationToPolicy(Mockito.anyString())).thenReturn(true); when(policyDmaapClient.handlePolicyResponse(Mockito.anyString())).thenReturn(true); - assertTrue(pmNotificationHandler.handlePmNotifications(pmNotification, 50)); - assertFalse(pmNotificationHandler.handlePmNotifications(null, 0)); - assertTrue(pmNotificationHandler.handlePmNotifications(pmNotification1, 50)); + assertTrue(pmNotificationHandler.handlePmNotifications(pmNotification, 50, 70, 1)); + assertFalse(pmNotificationHandler.handlePmNotifications(null, 0, 0,0)); + assertTrue(pmNotificationHandler.handlePmNotifications(pmNotification1, 50, 70, 1)); } private static String readFromFile(String file) { 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 index a27360e..2003c2c 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadTest.java @@ -24,6 +24,8 @@ package org.onap.dcaegen2.services.sonhms.child; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; +import com.fasterxml.jackson.databind.ObjectMapper; + import fj.data.Either; import java.util.ArrayList; @@ -33,10 +35,10 @@ 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.entity.HandOverMetrics; import org.onap.dcaegen2.services.sonhms.model.HoDetails; import org.springframework.boot.test.context.SpringBootTest; @@ -52,21 +54,33 @@ public class ChildThreadTest { @Test public void checkAnrTriggerTest() { - ArrayList<String> cellidList = new ArrayList<>(); - cellidList.add("cell1"); //PowerMockito.mockStatic(Configuration.class); Configuration config = Configuration.getInstance() ; config.setPoorThreshold(70); + config.setPoorCountThreshold(3); //PowerMockito.when(Configuration.getInstance()).thenReturn(config); - Either<List<HoDetails>, Integer> response = null; + Either<List<HandOverMetrics>, Integer> response = null; + List<HoDetails> hoDetailsList = new ArrayList<>(); + List<HandOverMetrics> hoMetrics = new ArrayList<>(); HoDetails hoDetail = new HoDetails(); hoDetail.setDstCellId("dstCell1"); hoDetail.setSuccessRate(60); - List<HoDetails> hoDetailsList = new ArrayList<>(); + hoDetail.setPoorCount(4); hoDetailsList.add(hoDetail); - response = Either.left(hoDetailsList); - when(hoMetricsComponent.getHoMetrics(Mockito.anyString())).thenReturn(response); - assertTrue(childThread.checkAnrTrigger(cellidList).isLeft()); + HandOverMetrics hoMetric = new HandOverMetrics(); + hoMetric.setSrcCellId("cell1"); + ObjectMapper mapper = new ObjectMapper(); + String hoDetailsString = null; + try { + hoDetailsString = mapper.writeValueAsString(hoDetailsList); + } catch (Exception e) { + e.printStackTrace(); + } + hoMetric.setHoDetails(hoDetailsString); + hoMetrics.add(hoMetric); + response = Either.left(hoMetrics); + when(hoMetricsComponent.getAll()).thenReturn(response); + assertTrue(childThread.checkAnrTrigger().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 index 32bfbcf..b597311 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/child/StateOofTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/StateOofTest.java @@ -73,7 +73,7 @@ public class StateOofTest { } try { - transactionId = oof.triggerOof(cellList, "networkId", null); + transactionId = oof.triggerOof(cellList, "networkId", new ArrayList<>()); } catch (OofNotFoundException | InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); 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 28940b3..92b2da1 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 @@ -28,6 +28,8 @@ import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.ObjectMapper; +import fj.data.Either; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -47,11 +49,14 @@ 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.HoMetricsComponent; +import org.onap.dcaegen2.services.sonhms.dao.HandOverMetricsRepository; 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.HoDetails; import org.onap.dcaegen2.services.sonhms.model.PolicyNotification; import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody; import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; @@ -79,6 +84,12 @@ public class TestChildThreadUtils { @Mock private PolicyDmaapClient policyDmaapClient; + @Mock + private HandOverMetricsRepository hoMetricRepository; + + @Mock + private HoMetricsComponent hoMetricsComponent; + @InjectMocks private ChildThreadUtils childThreadUtils2; @@ -92,7 +103,7 @@ public class TestChildThreadUtils { 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); + childThreadUtils = new ChildThreadUtils(configPolicy, pnfUtils, policyDmaapClient, hoMetricsComponent); MockitoAnnotations.initMocks(this); } @@ -167,6 +178,8 @@ public class TestChildThreadUtils { public void sendToPolicyTest() throws ConfigDbNotFoundException { PowerMockito.mockStatic(SdnrRestClient.class); + PowerMockito.mockStatic(BeanUtil.class); + String asyncRspBodyString = readFromFile("/AsyncRespBody.json"); ObjectMapper mapper = new ObjectMapper(); AsyncResponseBody async = new AsyncResponseBody (); @@ -198,6 +211,13 @@ public class TestChildThreadUtils { Map<String, List<Map<String,List<String>>>> expected = new HashMap<>(); expected.put("pnfName", list); when(pnfUtils.getPnfsForAnrSolutions(async.getSolutions().getAnrSolutions())).thenReturn(expected); + HoDetails hoDetails = new HoDetails(); + hoDetails.setDstCellId("EXP006"); + List<HoDetails> hoDetailsList = new ArrayList<>(); + hoDetailsList.add(hoDetails); + Either<List<HoDetails>, Integer> hoMetrics = Either.left(hoDetailsList); + when(hoMetricsComponent.getHoMetrics(Mockito.anyString())).thenReturn(hoMetrics); + when(hoMetricsComponent.update(Mockito.anyString(), Mockito.anyString())).thenReturn(true); assertTrue(childThreadUtils2.sendToPolicy(async)); } 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 index 4f28e35..2a249fd 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClientTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/dmaap/DmaapClientTest.java @@ -76,7 +76,6 @@ public class DmaapClientTest { configuration.setMinConfusion(5); configuration.setNumSolutions(1); configuration.setOofService("oofService"); - configuration.setOptimizers(list); configuration.setPollingInterval(30); configuration.setPollingTimeout(100); configuration.setConfigDbService("sdnrService"); 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 7451ca5..8c1168b 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 @@ -71,7 +71,7 @@ public class OofRestClientTest { configuration.setMinConfusion(5); configuration.setNumSolutions(1); configuration.setOofService("oofService"); - configuration.setOptimizers(list); + configuration.setPciOptimizer("pci"); configuration.setPollingInterval(30); configuration.setPollingTimeout(100); configuration.setConfigDbService("sdnrService"); |