2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.pap.main.parameters;
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;
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;
36 public class TestRequestParams {
37 private static final int RETRIES = 1;
39 private RequestParams params;
40 private Publisher<PdpMessage> pub;
41 private RequestIdDispatcher<PdpStatus> disp;
43 private TimerManager timers;
46 * Sets up the objects and creates an empty {@link #params}.
49 @SuppressWarnings("unchecked")
51 pub = mock(Publisher.class);
52 disp = mock(RequestIdDispatcher.class);
54 timers = mock(TimerManager.class);
56 params = new RequestParams().setModifyLock(lock).setPdpPublisher(pub).setResponseDispatcher(disp)
57 .setTimers(timers).setMaxRetryCount(RETRIES);
61 public void testGettersSetters() {
62 assertSame(params, params.setModifyLock(lock).setPdpPublisher(pub).setResponseDispatcher(disp));
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());
72 public void testValidate() {
78 public void testValidate_MissingLock() {
79 assertThatIllegalArgumentException().isThrownBy(() -> params.setModifyLock(null).validate())
80 .withMessageContaining("Lock");
84 public void testValidate_MissingDispatcher() {
85 assertThatIllegalArgumentException().isThrownBy(() -> params.setResponseDispatcher(null).validate())
86 .withMessageContaining("Dispatcher");
90 public void testValidate_MissingPublisher() {
91 assertThatIllegalArgumentException().isThrownBy(() -> params.setPdpPublisher(null).validate())
92 .withMessageContaining("publisher");
96 public void testValidate_MissingTimers() {
97 assertThatIllegalArgumentException().isThrownBy(() -> params.setTimers(null).validate())
98 .withMessageContaining("timer");