8d72d3cd538a926722cb9fea986a71c05d212d3f
[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.junit.Assert.assertNotNull;
25 import static org.mockito.Mockito.when;
26
27 import java.time.Duration;
28
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterSubscriber;
35 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterSubscribeRequest;
36 import org.springframework.boot.test.context.SpringBootTest;
37 import org.springframework.test.context.junit4.SpringRunner;
38
39 import com.google.gson.JsonElement;
40
41 import reactor.core.CoreSubscriber;
42 import reactor.core.publisher.Flux;
43
44 @RunWith(SpringRunner.class)
45 @SpringBootTest(classes = NotificationConsumerTest.class)
46 public class NotificationConsumerTest {
47
48     @Mock
49     NotificationCallback notificationCallback;
50
51     @InjectMocks
52     NotificationConsumer notificationConsumer;
53     
54     @Mock
55     MessageRouterSubscriber messageSubscriber;
56     
57     @Mock
58     MessageRouterSubscribeRequest subscriberRequest;
59
60     @Test
61     public void testNotificationConsumer() {
62         try {
63             Flux<JsonElement> json = new Flux<JsonElement>() {
64                 @Override
65                 public void subscribe(CoreSubscriber<? super JsonElement> actual) {
66                 }
67             };
68             Mockito.doNothing().when(notificationCallback).activateCallBack(Mockito.anyString());
69             when(messageSubscriber.subscribeForElements(subscriberRequest, Duration.ofMinutes(1))).thenReturn(json);
70             assertNotNull(messageSubscriber.subscribeForElements(subscriberRequest, Duration.ofMinutes(1)));
71         } catch (Exception e) {
72             e.printStackTrace();
73         }
74     }
75
76 }