c835d49b33d1559c06bbcf383ddaf05fcc0e75ed
[dcaegen2/services.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dcaegen2.kpi.dmaap;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.when;
26
27 import com.att.nsa.cambria.client.CambriaBatchingPublisher;
28 import com.google.gson.JsonObject;
29 import com.google.gson.JsonParser;
30
31 import java.io.IOException;
32
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;
43
44 @RunWith(SpringRunner.class)
45 @SpringBootTest(classes = NotificationProducerTest.class)
46 public class NotificationProducerTest {
47
48     private static final String VES_MESSAGE_FILE = "kpi/ves_message.json";
49     private static final String CBS_CONFIG_FILE = "kpi/cbs_config2.json";
50
51     @Mock
52     CambriaBatchingPublisher cambriaBatchingPublisher;
53
54     @InjectMocks
55     NotificationProducer notificationProducer;
56
57     @Test
58     public void notificationProducerTest() {
59
60         try {
61             when(cambriaBatchingPublisher.send(Mockito.anyString(), Mockito.anyString())).thenReturn(0);
62             int result = notificationProducer.sendNotification("msg");
63             assertEquals(0, result);
64         } catch (IOException e) {
65             e.printStackTrace();
66         }
67
68     }
69
70     @Test
71     public void kpiResultWithoutConfigTest() {
72
73         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
74         KpiComputationCallBack callback = new KpiComputationCallBack();
75         callback.activateCallBack(vesMessage);
76
77     }
78
79     @Test
80     public void kpiResultWithConfigTest() {
81
82         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
83         String strCbsConfig = FileUtils.getFileContents(CBS_CONFIG_FILE);
84
85         JsonObject jsonObject = new JsonParser().parse(strCbsConfig).getAsJsonObject().getAsJsonObject("config");
86         Configuration config = new Configuration();
87         config.updateConfigurationFromJsonObject(jsonObject);
88
89         KpiComputationCallBack callback = new KpiComputationCallBack();
90         callback.kpiComputation(vesMessage, config);
91
92     }
93
94 }