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.assertTrue;
25 import java.io.IOException;
26 import java.util.HashMap;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.onap.dcaegen2.kpi.models.Configuration;
37 import org.onap.dcaegen2.kpi.utils.DmaapUtils;
38 import org.springframework.boot.test.context.SpringBootTest;
40 import com.att.nsa.cambria.client.CambriaBatchingPublisher;
41 import com.att.nsa.cambria.client.CambriaConsumer;
43 @RunWith(MockitoJUnitRunner.class)
44 @SpringBootTest(classes = KpiDmaapClient.class)
45 public class KpiDmaapClientTest {
48 Configuration configurationMock;
51 DmaapUtils dmaapUtilsMock;
54 KpiDmaapClient kpiDmaapClient;
57 CambriaConsumer kpiResponseCambriaConsumerMock;
60 CambriaBatchingPublisher cambriaBatchingPublisherMock;
63 NotificationProducer notificationProducerMock;
67 kpiDmaapClient = new KpiDmaapClient(dmaapUtilsMock, configurationMock);
71 public void sendNotificationToPolicyTest() {
72 Map<String, Object> streamsPublishes = new HashMap<>();
73 Map<String, String> topics = new HashMap<>();
74 Map<String, Object> dmaapInfo = new HashMap<>();
75 topics.put("topic_url", "https://message-router.onap.svc.cluster.local:3905/events/DCAE_KPI_OUTPUT");
76 dmaapInfo.put("dmaap_info", topics);
77 streamsPublishes.put("kpi_topic", dmaapInfo);
78 Mockito.when(configurationMock.getStreamsPublishes()).thenReturn(streamsPublishes);
79 Mockito.when(dmaapUtilsMock.buildPublisher(configurationMock, "DCAE_KPI_OUTPUT"))
80 .thenReturn(cambriaBatchingPublisherMock);
82 Mockito.when(cambriaBatchingPublisherMock.send("", "hello")).thenReturn(0);
83 } catch (IOException e) {
86 assertTrue(kpiDmaapClient.sendNotificationToDmaap("hello"));