2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 China Mobile.
4 * Copyright (C) 2022 Deutsche Telekom AG. All rights reserved.
5 * Copyright (C) 2022 Wipro Limited. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.dcaegen2.kpi.computation;
25 import static org.junit.Assert.assertEquals;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import java.util.List;
31 import org.junit.Test;
32 import org.onap.dcaegen2.kpi.computation.KpiComputation;
33 import org.onap.dcaegen2.kpi.models.Configuration;
34 import org.onap.dcaegen2.kpi.models.VesEvent;
36 import java.math.BigDecimal;
37 import java.math.RoundingMode;
39 public class KpiComputationTest {
41 private static final String KPI_CONFIG_FILE = "kpi/kpi_config.json";
42 private static final String VES_MESSAGE_FILE = "kpi/ves_message.json";
43 private static final String KPI_CONFIG_RATIO_FILE = "kpi/kpi_config_ratio.json";
44 private static final String KPI_CONFIG_SLICING_RATIO_FILE = "kpi/kpi_config_slicing.json";
45 private static final String KPI_CONFIG_SUMRATIO_FILE = "kpi/kpi_config_sumratio.json";
46 private static final String VES_MESSAGE_EMPTY_FILE = "kpi/ves_message_empty.json";
47 private static final String VES_MESSAGE_NULL_FILE = "kpi/ves_message_null.json";
48 private static final String VES_MESSAGE_SLICING_FILE = "kpi/ves_message_slicing.json";
49 private static final String VES_MESSAGE_EVENTNAME_FILE = "kpi/ves_message_eventname.json";
52 public void testKpiComputation() {
55 String strKpiConfig = FileUtils.getFileContents(KPI_CONFIG_FILE);
57 String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
59 Configuration config = mock(Configuration.class);
60 when(config.getKpiConfig()).thenReturn(strKpiConfig);
61 List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
63 VesEvent vesEvent = vesList.get(0);
64 assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
65 .getMeasValuesList().get(0).getMeasResults().get(0).getSvalue(), "40");
69 public void testKpiComputationRatio() {
70 String strKpiConfigRatio = FileUtils.getFileContents(KPI_CONFIG_RATIO_FILE);
71 String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
72 Configuration config = mock(Configuration.class);
73 when(config.getKpiConfig()).thenReturn(strKpiConfigRatio);
74 List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
75 VesEvent vesEvent = vesList.get(0);
76 assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
77 .getMeasValuesList().get(0).getMeasResults().get(0).getSvalue(), "50");
81 public void testKpiComputationSlicingRatio() {
82 String strKpiConfigRatio = FileUtils.getFileContents(KPI_CONFIG_SLICING_RATIO_FILE);
83 String vesMessage = FileUtils.getFileContents(VES_MESSAGE_SLICING_FILE);
84 Configuration config = mock(Configuration.class);
85 when(config.getKpiConfig()).thenReturn(strKpiConfigRatio);
86 List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
87 VesEvent vesEvent = vesList.get(0);
88 assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
89 .getMeasValuesList().get(0).getMeasResults().get(0).getSvalue(), "158");
93 public void testKpiComputationSumRatio() {
95 String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_SUMRATIO_FILE);
96 String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
97 Configuration config = mock(Configuration.class);
98 when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio);
99 List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
100 VesEvent vesEvent = vesList.get(0);
101 assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
102 .getMeasValuesList().get(0).getMeasResults().get(0).getSvalue(), "67");
106 public void testKpiComputationSumRatioEmptyCheck() {
107 String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_SUMRATIO_FILE);
109 String vesMessage = FileUtils.getFileContents(VES_MESSAGE_EMPTY_FILE);
110 Configuration config = mock(Configuration.class);
111 when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio);
112 List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
113 assertEquals(0, vesList.size());
117 public void testKpiComputationSumRatioOperandsCheck() {
118 String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_SUMRATIO_FILE);
120 String vesMessage = FileUtils.getFileContents(VES_MESSAGE_NULL_FILE);
121 Configuration config = mock(Configuration.class);
122 when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio);
123 List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
124 assertEquals(0, vesList.size());
128 public void testKpiComputationSumRatioEventNameCheck() {
129 String strKpiConfigSumRatio = FileUtils.getFileContents(KPI_CONFIG_SUMRATIO_FILE);
131 String vesMessage = FileUtils.getFileContents(VES_MESSAGE_EVENTNAME_FILE);
132 Configuration config = mock(Configuration.class);
133 when(config.getKpiConfig()).thenReturn(strKpiConfigSumRatio);
134 List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
135 assertEquals(null, vesList);