Fix sonars from depeendency upgrade
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / test / java / org / onap / policy / controlloop / actorserviceprovider / parameters / HttpPollingConfigTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.actorserviceprovider.parameters;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertSame;
25 import static org.mockito.Mockito.when;
26
27 import java.util.concurrent.Executor;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.junit.MockitoJUnitRunner;
33 import org.onap.policy.common.endpoints.http.client.HttpClient;
34 import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class HttpPollingConfigTest {
38     private static final String MY_CLIENT = "my-client";
39     private static final String MY_PATH = "my-path";
40     private static final String POLL_PATH = "poll-path";
41     private static final int TIMEOUT_SEC = 10;
42     private static final int MAX_POLLS = 20;
43     private static final int WAIT_SEC = 30;
44
45     @Mock
46     private HttpClient client;
47     @Mock
48     private HttpClientFactory factory;
49     @Mock
50     private Executor executor;
51
52     private HttpPollingParams params;
53     private HttpPollingConfig config;
54
55     /**
56      * Sets up.
57      */
58     @Before
59     public void setUp() {
60         when(factory.get(MY_CLIENT)).thenReturn(client);
61
62         params = HttpPollingParams.builder().maxPolls(MAX_POLLS).pollPath(POLL_PATH).pollWaitSec(WAIT_SEC)
63                         .clientName(MY_CLIENT).path(MY_PATH).timeoutSec(TIMEOUT_SEC).build();
64         config = new HttpPollingConfig(executor, params, factory);
65     }
66
67     @Test
68     public void test() {
69         assertEquals(POLL_PATH + "/", config.getPollPath());
70         assertEquals(MAX_POLLS, config.getMaxPolls());
71         assertEquals(WAIT_SEC, config.getPollWaitSec());
72
73         // check value from superclass
74         assertSame(executor, config.getBlockingExecutor());
75         assertSame(client, config.getClient());
76
77         // path with trailing "/"
78         params = params.toBuilder().pollPath(POLL_PATH + "/").build();
79         config = new HttpPollingConfig(executor, params, factory);
80         assertEquals(POLL_PATH + "/", config.getPollPath());
81     }
82 }