CodeCoverage improvement for dcaegen2-analytics-tca-gen2
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-web / src / test / java / org / onap / dcae / analytics / web / config / DmaapRetryTestConfig.java
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (c) 2022 Huawei. All rights reserved.
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  * ============LICENSE_END=========================================================
17  *
18  */
19
20 package org.onap.dcae.analytics.web.config;
21
22 import org.junit.jupiter.api.Test;
23 import org.mockito.Mockito;
24 import org.springframework.integration.channel.QueueChannel;
25 import org.springframework.integration.dsl.IntegrationFlow;
26 import org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer;
27 import org.springframework.integration.handler.advice.RequestHandlerRetryAdvice;
28 import org.springframework.integration.store.BasicMessageGroupStore;
29 import org.springframework.messaging.PollableChannel;
30 import org.springframework.retry.RetryPolicy;
31 import org.springframework.retry.backoff.BackOffPolicy;
32 import org.springframework.retry.support.RetryTemplate;
33
34 import static org.junit.jupiter.api.Assertions.assertEquals;
35 import static org.junit.jupiter.api.Assertions.assertNotNull;
36
37 public class DmaapRetryTestConfig {
38
39     @Test
40     public void errorChannelTest () throws Exception {
41         DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig();
42         QueueChannel queueChannel = dmaapRetryConfig.errorChannel();
43         assertNotNull(queueChannel);
44     }
45
46     @Test
47     public void errorMessageSendingRecovererTest () throws Exception {
48         PollableChannel pollableChannel = Mockito.mock(PollableChannel.class);
49         DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig();
50         ErrorMessageSendingRecoverer errorMessageSendingRecoverer =
51                 dmaapRetryConfig.errorMessageSendingRecoverer(pollableChannel);
52         Throwable throwable = new Throwable("test");
53         assertEquals("test", errorMessageSendingRecoverer.getErrorMessageStrategy()
54                 .buildErrorMessage(throwable, null).getPayload().getMessage());
55     }
56
57     @Test
58     public void recoveryChannelTest () throws Exception {
59         BasicMessageGroupStore basicMessageGroupStore = Mockito.mock(BasicMessageGroupStore.class);
60         DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig();
61         PollableChannel pollableChannel = dmaapRetryConfig.recoveryChannel(basicMessageGroupStore);
62         assertNotNull(pollableChannel);
63     }
64
65     @Test
66     public void requestHandlerRetryAdviceTest () throws Exception {
67         RetryTemplate retryTemplate = Mockito.mock(RetryTemplate.class);
68         ErrorMessageSendingRecoverer errorMessageSendingRecoverer = Mockito.mock(ErrorMessageSendingRecoverer.class);
69         DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig();
70         RequestHandlerRetryAdvice requestHandlerRetryAdvice = dmaapRetryConfig.requestHandlerRetryAdvice(retryTemplate,
71                 errorMessageSendingRecoverer);
72         assertNotNull(requestHandlerRetryAdvice);
73     }
74
75     @Test
76     public void retryTemplateTest () throws Exception {
77         RetryPolicy retryPolicy = Mockito.mock(RetryPolicy.class);
78         BackOffPolicy backOffPolicy = Mockito.mock(BackOffPolicy.class);
79         DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig();
80         RetryTemplate retryTemplate = dmaapRetryConfig.retryTemplate(retryPolicy, backOffPolicy);
81         assertNotNull(retryTemplate);
82     }
83
84     @Test
85     public void retryPolicyTest () throws Exception {
86         DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig();
87         RetryPolicy retryPolicy = dmaapRetryConfig.retryPolicy();
88         assertNotNull(retryPolicy);
89     }
90
91     @Test
92     public void backoffPolicyTest () throws Exception {
93         DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig();
94         BackOffPolicy backOffPolicy = dmaapRetryConfig.backOffPolicy();
95         assertNotNull(backOffPolicy);
96     }
97
98     @Test
99     public void loggingFlowTest () throws Exception {
100         DmaapRetryConfig dmaapRetryConfig = new DmaapRetryConfig();
101         IntegrationFlow integrationFlow = dmaapRetryConfig.loggingFlow();
102         assertNotNull(integrationFlow);
103     }
104 }