[DCAEGEN2] Improvements to kpi-computation-ms Microservice
[dcaegen2/services.git] / components / kpi-computation-ms / src / test / java / org / onap / dcaegen2 / kpi / computation / KpiComputationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 China Mobile.
4  *  Copyright (C) 2021 Deutsche Telekom AG. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.dcaegen2.kpi.computation;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
27
28 import java.util.List;
29
30 import org.junit.Test;
31 import org.onap.dcaegen2.kpi.computation.KpiComputation;
32 import org.onap.dcaegen2.kpi.models.Configuration;
33 import org.onap.dcaegen2.kpi.models.VesEvent;
34
35 import java.math.BigDecimal;
36 import java.math.RoundingMode;
37
38 public class KpiComputationTest {
39
40     private static final String KPI_CONFIG_FILE = "kpi/kpi_config.json";
41     private static final String VES_MESSAGE_FILE = "kpi/ves_message.json";
42     private static final String KPI_CONFIG_RATIO_FILE = "kpi/kpi_config_ratio.json";
43
44     @Test
45     public void testKpiComputation() {
46
47
48         String strKpiConfig = FileUtils.getFileContents(KPI_CONFIG_FILE);
49
50         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
51
52         Configuration config = mock(Configuration.class);
53         when(config.getKpiConfig()).thenReturn(strKpiConfig);
54         List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
55
56         VesEvent vesEvent = vesList.get(0);
57         assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
58                 .getMeasValuesList().get(0).getMeasResults().get(0).getSvalue(), "40");
59     }
60
61     @Test
62     public void testKpiComputationRatio() {
63         String strKpiConfigRatio = FileUtils.getFileContents(KPI_CONFIG_RATIO_FILE);
64         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
65         Configuration config = mock(Configuration.class);
66         when(config.getKpiConfig()).thenReturn(strKpiConfigRatio);
67         List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
68         VesEvent vesEvent = vesList.get(0);
69         assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
70                  .getMeasValuesList().get(0).getMeasResults().get(0).getSvalue(), "50");
71     }
72
73 }