2 * ============LICENSE_START=======================================================
3 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * Copyright (c) 2022 Huawei. All rights reserved.
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.
17 * ============LICENSE_END=========================================================
21 package org.onap.dcae.analytics.web.config;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import org.junit.jupiter.api.Test;
25 import org.mockito.Mockito;
26 import org.onap.dcae.analytics.web.dmaap.MrSubscriberPollingPreferences;
27 import org.onap.dcae.analytics.web.dmaap.MrSubscriberPreferences;
28 import org.onap.dcae.analytics.web.dmaap.MrTriggerMessageProvider;
29 import org.onap.dcae.analytics.web.dmaap.MrSubscriberPollingAdvice;
30 import org.onap.dcae.analytics.web.dmaap.MrMessageSplitter;
31 import org.onap.dcae.analytics.web.dmaap.MrPublisherPreferences;
32 import org.springframework.http.HttpHeaders;
33 import org.springframework.integration.channel.DirectChannel;
34 import org.springframework.integration.channel.QueueChannel;
35 import org.springframework.integration.core.MessageSource;
36 import org.springframework.integration.dsl.IntegrationFlow;
37 import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice;
38 import org.springframework.integration.scheduling.PollerMetadata;
39 import org.springframework.integration.store.BasicMessageGroupStore;
40 import org.springframework.web.client.RestTemplate;
43 import java.util.Arrays;
45 import static org.junit.jupiter.api.Assertions.assertNotNull;
46 import static org.junit.jupiter.api.Assertions.assertTrue;
47 import static org.junit.jupiter.api.Assertions.assertEquals;
49 public class DmaapMrTestConfig {
52 public void mrPublisherInputChannelTest () throws Exception {
53 DmaapMrConfig dmaapMrConfig = new DmaapMrConfig();
54 DirectChannel directChannel = dmaapMrConfig.mrPublisherInputChannel();
55 assertNotNull(directChannel);
59 public void mrTriggerMessageProviderTest () throws Exception {
60 URL proxyURL = new URL("http://localhost");
61 MrSubscriberPollingPreferences pollingPreferences = Mockito.mock(MrSubscriberPollingPreferences.class);
62 HttpHeaders headers = Mockito.mock(HttpHeaders.class);
63 MrSubscriberPreferences subscriberPreferences =
64 new MrSubscriberPreferences("http://localhost:8080",
65 "TestClientId", headers,
66 "TestUserName", "TestPassword",
67 proxyURL, true, false, "TestGroup",
68 Arrays.asList("TestId1"),
69 new Integer(4), new Integer(3), pollingPreferences);
70 DmaapMrConfig dmaapMrConfig = new DmaapMrConfig();
71 MrTriggerMessageProvider mrTriggerMessageProvider = dmaapMrConfig.mrTriggerMessageProvider(subscriberPreferences);
72 assertEquals("getTriggerMessage", mrTriggerMessageProvider.TRIGGER_METHOD_NAME);
73 assertEquals("http://localhost:8080/TestGroup/TestId1?limit=4&timeout=3",
74 mrTriggerMessageProvider.getTriggerMessage().getPayload());
78 public void mrMessageSourceTest () throws Exception {
79 URL proxyURL = new URL("http://localhost");
80 MrSubscriberPollingPreferences pollingPreferences = Mockito.mock(MrSubscriberPollingPreferences.class);
81 HttpHeaders headers = Mockito.mock(HttpHeaders.class);
82 MrSubscriberPreferences subscriberPreferences =
83 new MrSubscriberPreferences("http://localhost:8080",
84 "TestClientId", headers,
85 "TestUserName", "TestPassword",
86 proxyURL, true, false, "TestGroup",
87 Arrays.asList("TestId1", "TestId2"),
88 new Integer(4), new Integer(3), pollingPreferences);
89 DmaapMrConfig dmaapMrConfig = new DmaapMrConfig();
90 MrTriggerMessageProvider mrTriggerMessageProvider = dmaapMrConfig.mrTriggerMessageProvider(subscriberPreferences);
91 MessageSource messageSource = dmaapMrConfig.mrMessageSource(mrTriggerMessageProvider);
92 assertEquals("inbound_channel_adapter", messageSource.getIntegrationPatternType().name());
96 public void mrSubscriberOutputChannelTest () throws Exception {
97 BasicMessageGroupStore basicMessageGroupStore = Mockito.mock(BasicMessageGroupStore.class);
98 DmaapMrConfig dmaapMrConfig = new DmaapMrConfig();
99 QueueChannel queueChannel = dmaapMrConfig.mrSubscriberOutputChannel(basicMessageGroupStore);
100 assertTrue(queueChannel.getRemainingCapacity() > 0);
104 public void mrSubscriberFlowTest () throws Exception {
105 PollerMetadata pollerMetadata = Mockito.mock(PollerMetadata.class);
106 QueueChannel queueChannel = Mockito.mock(QueueChannel.class);
107 RestTemplate restTemplate = Mockito.mock(RestTemplate.class);
108 MessageSource messageSource = Mockito.mock(MessageSource.class);
109 MrMessageSplitter mrMessageSplitter = Mockito.mock(MrMessageSplitter.class);
110 MrSubscriberPollingAdvice mrSubscriberPollingAdvice = Mockito.mock(MrSubscriberPollingAdvice.class);
111 DmaapMrConfig dmaapMrConfig = new DmaapMrConfig();
112 IntegrationFlow integratedFlow = dmaapMrConfig.mrSubscriberFlow(pollerMetadata,restTemplate,messageSource,queueChannel, mrMessageSplitter, mrSubscriberPollingAdvice);
113 assertNotNull(integratedFlow.getInputChannel());
117 public void mrPublisherFlowTest () throws Exception {
118 RequestHandlerRetryAdvice requestHandlerRetryAdvice = Mockito.mock(RequestHandlerRetryAdvice.class);
119 DirectChannel directChannel = Mockito.mock(DirectChannel.class);
120 RestTemplate restTemplate = Mockito.mock(RestTemplate.class);
121 MrPublisherPreferences mrPublisherPreferences = Mockito.mock(MrPublisherPreferences.class);
122 DmaapMrConfig dmaapMrConfig = new DmaapMrConfig();
123 IntegrationFlow integratedFlow = dmaapMrConfig.mrPublisherFlow(mrPublisherPreferences,restTemplate,directChannel,requestHandlerRetryAdvice);
124 assertNotNull(integratedFlow.getInputChannel());
128 public void mrMessageSplitterTest () throws Exception {
129 ObjectMapper objectMapper = new ObjectMapper();
130 int processingBatchSize = 100;
131 DmaapMrConfig dmaapMrConfig = new DmaapMrConfig();
132 MrMessageSplitter mrMessageSplitter = dmaapMrConfig.mrMessageSplitter(objectMapper, processingBatchSize);
133 assertNotNull(mrMessageSplitter);