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
 
  10  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  18  * SPDX-License-Identifier: Apache-2.0
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.dcaegen2.kpi.computation;
 
  24 import static org.junit.Assert.assertEquals;
 
  25 import static org.mockito.Mockito.mock;
 
  26 import static org.mockito.Mockito.when;
 
  28 import java.util.List;
 
  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;
 
  35 import java.math.BigDecimal;
 
  36 import java.math.RoundingMode;
 
  38 public class KpiComputationTest {
 
  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";
 
  45     public void testKpiComputation() {
 
  48         String strKpiConfig = FileUtils.getFileContents(KPI_CONFIG_FILE);
 
  50         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
 
  52         Configuration config = mock(Configuration.class);
 
  53         when(config.getKpiConfig()).thenReturn(strKpiConfig);
 
  54         List<VesEvent> vesList = new KpiComputation().checkAndDoComputation(vesMessage, config);
 
  56         VesEvent vesEvent = vesList.get(0);
 
  57         assertEquals(vesEvent.getEvent().getPerf3gppFields().getMeasDataCollection().getMeasInfoList().get(0)
 
  58                 .getMeasValuesList().get(0).getMeasResults().get(0).getSvalue(), "40");
 
  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");