d39c0af610028da73d070ddc019bb2f85fd9a94f
[dcaegen2/services.git] /
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  slice-analysis-ms
4  *  ================================================================================
5  *   Copyright (C) 2020 Wipro Limited.
6  *   Copyright (C) 2022 CTC, Inc.
7  *   ==============================================================================
8  *     Licensed under the Apache License, Version 2.0 (the "License");
9  *     you may not use this file except in compliance with the License.
10  *     You may obtain a copy of the License at
11  *
12  *          http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *     Unless required by applicable law or agreed to in writing, software
15  *     distributed under the License is distributed on an "AS IS" BASIS,
16  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *     See the License for the specific language governing permissions and
18  *     limitations under the License.
19  *     ============LICENSE_END=========================================================
20  *
21  *******************************************************************************/
22
23
24 package org.onap.slice.analysis.ms.dmaap;
25
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.Mockito.when;
28
29 import com.google.gson.JsonPrimitive;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher;
35 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterPublishResponse;
36 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest;
37 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse;
38 import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.test.context.junit4.SpringRunner;
40 import reactor.core.publisher.Flux;
41
42 import java.io.IOException;
43
44 @RunWith(SpringRunner.class)
45 @SpringBootTest(classes = NotificationProducerTest.class)
46 public class NotificationProducerTest {
47
48     @Mock
49     MessageRouterPublisher publisher;
50
51     @Mock
52     MessageRouterPublishRequest request;
53
54     @InjectMocks
55     NotificationProducer notificationProducer;
56
57     @Test
58     public void notificationProducerTest() throws IOException {
59             io.vavr.collection.List<String> expectedItems = io.vavr.collection.List.of("I", "like", "pizza");
60             MessageRouterPublishResponse expectedResponse = ImmutableMessageRouterPublishResponse
61                     .builder().items(expectedItems.map(JsonPrimitive::new))
62                     .build();
63             Flux<MessageRouterPublishResponse> responses = Flux.just(expectedResponse);
64 //            Flux<JsonPrimitive> singleMessage = Flux.just("msg").map(JsonPrimitive::new);
65             when(publisher.put(any(), any())).thenReturn(responses);
66
67             notificationProducer.sendNotification("msg");
68     }
69 }