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
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.dmaap;
24 import static org.mockito.Mockito.when;
26 import java.io.IOException;
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;
42 import com.google.gson.JsonObject;
43 import com.google.gson.JsonParser;
44 import com.google.gson.JsonPrimitive;
46 import reactor.core.publisher.Flux;
48 @RunWith(SpringRunner.class)
49 @SpringBootTest(classes = NotificationProducerTest.class)
50 public class NotificationProducerTest {
52 private static final String VES_MESSAGE_FILE = "kpi/ves_message.json";
53 private static final String CBS_CONFIG_FILE = "kpi/cbs_config2.json";
56 MessageRouterPublisher messageRouterPublisher;
59 MessageRouterPublishRequest messageRouterPublishRequest;
62 NotificationProducer notificationProducer;
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))
70 Flux<MessageRouterPublishResponse> responses = Flux.just(expectedResponse);
71 when(messageRouterPublisher.put(Mockito.any(), Mockito.any())).thenReturn(responses);
72 notificationProducer.sendNotification("msg");
76 public void kpiResultWithoutConfigTest() {
78 String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
79 KpiComputationCallBack callback = new KpiComputationCallBack();
80 callback.activateCallBack(vesMessage);
85 public void kpiResultWithConfigTest() {
87 String vesMessage = FileUtils.getFileContents(VES_MESSAGE_FILE);
88 String strCbsConfig = FileUtils.getFileContents(CBS_CONFIG_FILE);
90 JsonObject jsonObject = new JsonParser().parse(strCbsConfig).getAsJsonObject().getAsJsonObject("config");
91 Configuration config = new Configuration();
92 config.updateConfigurationFromJsonObject(jsonObject);
94 KpiComputationCallBack callback = new KpiComputationCallBack();
95 callback.kpiComputation(vesMessage, config);