f880ec7adf982aab325ab3a05beae532bbd5eec0
[dcaegen2/services.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 China Mobile.
4  *  Copyright (C) 2022 Wipro Limited.
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.dmaap;
23
24 import static org.mockito.Mockito.when;
25
26 import java.io.IOException;
27
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.InjectMocks;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.onap.dcaegen2.kpi.computation.FileUtils;
34 import org.onap.dcaegen2.kpi.models.Configuration;
35 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher;
36 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterPublishResponse;
37 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest;
38 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse;
39 import org.springframework.boot.test.context.SpringBootTest;
40 import org.springframework.test.context.junit4.SpringRunner;
41
42 import com.google.gson.JsonObject;
43 import com.google.gson.JsonParser;
44 import com.google.gson.JsonPrimitive;
45
46 import reactor.core.publisher.Flux;
47
48 @RunWith(SpringRunner.class)
49 @SpringBootTest(classes = NotificationProducerTest.class)
50 public class NotificationProducerTest {
51
52     private static final String VES_MESSAGE_FILE = "kpi/ves_message.json";
53     private static final String CBS_CONFIG_FILE = "kpi/cbs_config2.json";
54
55     @Mock
56     MessageRouterPublisher messageRouterPublisher;                                                                                                                               
57     
58     @Mock
59     MessageRouterPublishRequest messageRouterPublishRequest;
60     
61     @InjectMocks
62     NotificationProducer notificationProducer;
63
64     @Test
65     public void notificationProducerTest() throws IOException {
66         io.vavr.collection.List<String> expectedItems = io.vavr.collection.List.of("kpi-1", "kpi-2", "kpi-3");
67         MessageRouterPublishResponse expectedResponse = ImmutableMessageRouterPublishResponse
68                 .builder().items(expectedItems.map(JsonPrimitive::new))
69                 .build();
70         Flux<MessageRouterPublishResponse> responses = Flux.just(expectedResponse);
71         when(messageRouterPublisher.put(Mockito.any(), Mockito.any())).thenReturn(responses);
72         notificationProducer.sendNotification("msg");
73     }
74     
75     @Test
76     public void kpiResultWithoutConfigTest() {
77
78         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
79         KpiComputationCallBack callback = new KpiComputationCallBack();
80         callback.activateCallBack(vesMessage);
81
82     }
83
84     @Test
85     public void kpiResultWithConfigTest() {
86
87         String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
88         String strCbsConfig = FileUtils.getFileContents(CBS_CONFIG_FILE);
89
90         JsonObject jsonObject = new JsonParser().parse(strCbsConfig).getAsJsonObject().getAsJsonObject("config");
91         Configuration config = new Configuration();
92         config.updateConfigurationFromJsonObject(jsonObject);
93
94         KpiComputationCallBack callback = new KpiComputationCallBack();
95         callback.kpiComputation(vesMessage, config);
96
97     }
98
99 }