diff options
Diffstat (limited to 'components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java')
-rw-r--r-- | components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java index 4320981b..dc1becb3 100644 --- a/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java +++ b/components/kpi-computation-ms/src/test/java/org/onap/dcaegen2/kpi/computation/KpiComputationTest.java @@ -26,12 +26,21 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.mockito.Spy; import org.onap.dcaegen2.kpi.computation.KpiComputation; +import org.onap.dcaegen2.kpi.exception.KpiComputationException; import org.onap.dcaegen2.kpi.models.Configuration; +import org.onap.dcaegen2.kpi.models.KpiOperand; +import org.onap.dcaegen2.kpi.models.MeasDataCollection; import org.onap.dcaegen2.kpi.models.VesEvent; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.reflect.Whitebox; import java.math.BigDecimal; import java.math.RoundingMode; @@ -47,7 +56,9 @@ public class KpiComputationTest { private static final String VES_MESSAGE_NULL_FILE = "kpi/ves_message_null.json"; private static final String VES_MESSAGE_SLICING_FILE = "kpi/ves_message_slicing.json"; private static final String VES_MESSAGE_EVENTNAME_FILE = "kpi/ves_message_eventname.json"; - + private static final String VES_MESSAGE_FIELD_MISSING ="kpi/ves_message_missing_field.json"; + + @Test public void testKpiComputation() { @@ -88,7 +99,7 @@ public class KpiComputationTest { assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0) .getMeasValuesList().get(0).getMeasResults().get(0).getSvalue(), "158"); } - + @Test public void testKpiComputationSumRatio() { @@ -134,5 +145,47 @@ public class KpiComputationTest { List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config); assertEquals(null, vesList); } + + @Test + public void testKpiComputationException() { + String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_SUMRATIO_FILE); + String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FIELD_MISSING); + Configuration config = mock(Configuration.class); + when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio); + KpiComputationException kpiException = Assertions.assertThrows(KpiComputationException.class, () -> { + List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config); + }); + Assertions.assertEquals("Required Field: EventName not present", kpiException.getMessage()); + } + @Test + public void testNullOperands() throws Exception { + Map<String, List<KpiOperand>> operands = null; + operands = Whitebox.invokeMethod(new KpiComputation(), "getOperands", new MeasDataCollection(), null); + Assertions.assertNull(operands); + } + @Test + public void testEmptyOperands() throws Exception { + Map<String, List<KpiOperand>> operands = null; + List<String> inputOperands = new ArrayList<String>(); + operands = Whitebox.invokeMethod(new KpiComputation(), "getOperands", new MeasDataCollection(), inputOperands); + Assertions.assertNull(operands); + } + @Test + public void testNullVESMessage() { + String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_FILE); + Configuration config = mock(Configuration.class); + when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio); + List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(null, config); + Assertions.assertNull(vesList); + } + @Test + public void testEmptyVESMessage() { + String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_FILE); + Configuration config = mock(Configuration.class); + when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio); + String vesMessage = "{}"; + List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config); + Assertions.assertNull(vesList); + } } |