2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2021 China Mobile.
 
   4  * ================================================================================
 
   5  * Licensed under the Apache License, Version 2.0 (the "License");
 
   6  * you may not use this file except in compliance with the License.
 
   7  * You may obtain a copy of the License at
 
   9  *      http://www.apache.org/licenses/LICENSE-2.0
 
  11  * Unless required by applicable law or agreed to in writing, software
 
  12  * distributed under the License is distributed on an "AS IS" BASIS,
 
  13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  14  * See the License for the specific language governing permissions and
 
  15  * limitations under the License.
 
  17  * SPDX-License-Identifier: Apache-2.0
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.onap.dcaegen2.kpi.dmaap;
 
  23 import static org.junit.Assert.assertEquals;
 
  24 import static org.mockito.Mockito.mock;
 
  25 import static org.mockito.Mockito.when;
 
  27 import com.att.nsa.cambria.client.CambriaBatchingPublisher;
 
  28 import com.google.gson.JsonObject;
 
  29 import com.google.gson.JsonParser;
 
  31 import java.io.IOException;
 
  33 import org.junit.Test;
 
  34 import org.junit.runner.RunWith;
 
  35 import org.mockito.InjectMocks;
 
  36 import org.mockito.Mock;
 
  37 import org.mockito.Mockito;
 
  38 import org.onap.dcaegen2.kpi.computation.FileUtils;
 
  39 import org.onap.dcaegen2.kpi.models.Configuration;
 
  40 import org.powermock.api.mockito.PowerMockito;
 
  41 import org.springframework.boot.test.context.SpringBootTest;
 
  42 import org.springframework.test.context.junit4.SpringRunner;
 
  44 @RunWith(SpringRunner.class)
 
  45 @SpringBootTest(classes = NotificationProducerTest.class)
 
  46 public class NotificationProducerTest {
 
  48     private static final String VES_MESSAGE_FILE = "kpi/ves_message.json";
 
  49     private static final String CBS_CONFIG_FILE = "kpi/cbs_config2.json";
 
  52     CambriaBatchingPublisher cambriaBatchingPublisher;
 
  55     NotificationProducer notificationProducer;
 
  58     public void notificationProducerTest() {
 
  61             when(cambriaBatchingPublisher.send(Mockito.anyString(), Mockito.anyString())).thenReturn(0);
 
  62             int result = notificationProducer.sendNotification("msg");
 
  63             assertEquals(0, result);
 
  64         } catch (IOException e) {
 
  71     public void kpiResultWithoutConfigTest() {
 
  73         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
 
  74         KpiComputationCallBack callback = new KpiComputationCallBack();
 
  75         callback.activateCallBack(vesMessage);
 
  80     public void kpiResultWithConfigTest() {
 
  82         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
 
  83         String strCbsConfig = FileUtils.getFileContents(CBS_CONFIG_FILE);
 
  85         JsonObject jsonObject = new JsonParser().parse(strCbsConfig).getAsJsonObject().getAsJsonObject("config");
 
  86         Configuration config = new Configuration();
 
  87         config.updateConfigurationFromJsonObject(jsonObject);
 
  89         KpiComputationCallBack callback = new KpiComputationCallBack();
 
  90         callback.kpiComputation(vesMessage, config);