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