Java 17 / Spring 6 / Spring Boot 3 Upgrade
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / parameters / TestRequestParams.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP PAP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2023 Nordix Foundation.
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 package org.onap.policy.pap.main.parameters;
23
24 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertSame;
27 import static org.mockito.Mockito.mock;
28
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Test;
31 import org.onap.policy.common.endpoints.listeners.RequestIdDispatcher;
32 import org.onap.policy.models.pdp.concepts.PdpMessage;
33 import org.onap.policy.models.pdp.concepts.PdpStatus;
34 import org.onap.policy.pap.main.comm.Publisher;
35 import org.onap.policy.pap.main.comm.TimerManager;
36
37 class TestRequestParams {
38     private static final int RETRIES = 1;
39
40     private RequestParams params;
41     private Publisher<PdpMessage> pub;
42     private RequestIdDispatcher<PdpStatus> disp;
43     private Object lock;
44     private TimerManager timers;
45
46     /**
47      * Sets up the objects and creates an empty {@link #params}.
48      */
49     @BeforeEach
50     @SuppressWarnings("unchecked")
51     public void setUp() {
52         pub = mock(Publisher.class);
53         disp = mock(RequestIdDispatcher.class);
54         lock = new Object();
55         timers = mock(TimerManager.class);
56
57         params = new RequestParams().setModifyLock(lock).setPdpPublisher(pub).setResponseDispatcher(disp)
58                         .setTimers(timers).setMaxRetryCount(RETRIES);
59     }
60
61     @Test
62     void testGettersSetters() {
63         assertSame(params, params.setModifyLock(lock).setPdpPublisher(pub).setResponseDispatcher(disp));
64
65         assertSame(pub, params.getPdpPublisher());
66         assertSame(disp, params.getResponseDispatcher());
67         assertSame(lock, params.getModifyLock());
68         assertSame(timers, params.getTimers());
69         assertEquals(RETRIES, params.getMaxRetryCount());
70     }
71
72     @Test
73     void testValidate() {
74         // no exception
75         params.validate();
76     }
77
78     @Test
79     void testValidate_MissingLock() {
80         assertThatIllegalArgumentException().isThrownBy(() -> params.setModifyLock(null).validate())
81                         .withMessageContaining("Lock");
82     }
83
84     @Test
85     void testValidate_MissingDispatcher() {
86         assertThatIllegalArgumentException().isThrownBy(() -> params.setResponseDispatcher(null).validate())
87                         .withMessageContaining("Dispatcher");
88     }
89
90     @Test
91     void testValidate_MissingPublisher() {
92         assertThatIllegalArgumentException().isThrownBy(() -> params.setPdpPublisher(null).validate())
93                         .withMessageContaining("publisher");
94     }
95
96     @Test
97     void testValidate_MissingTimers() {
98         assertThatIllegalArgumentException().isThrownBy(() -> params.setTimers(null).validate())
99                         .withMessageContaining("timer");
100     }
101 }