2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.pap.main.parameters;
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;
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;
37 class TestRequestParams {
38 private static final int RETRIES = 1;
40 private RequestParams params;
41 private Publisher<PdpMessage> pub;
42 private RequestIdDispatcher<PdpStatus> disp;
44 private TimerManager timers;
47 * Sets up the objects and creates an empty {@link #params}.
50 @SuppressWarnings("unchecked")
52 pub = mock(Publisher.class);
53 disp = mock(RequestIdDispatcher.class);
55 timers = mock(TimerManager.class);
57 params = new RequestParams().setModifyLock(lock).setPdpPublisher(pub).setResponseDispatcher(disp)
58 .setTimers(timers).setMaxRetryCount(RETRIES);
62 void testGettersSetters() {
63 assertSame(params, params.setModifyLock(lock).setPdpPublisher(pub).setResponseDispatcher(disp));
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());
79 void testValidate_MissingLock() {
80 assertThatIllegalArgumentException().isThrownBy(() -> params.setModifyLock(null).validate())
81 .withMessageContaining("Lock");
85 void testValidate_MissingDispatcher() {
86 assertThatIllegalArgumentException().isThrownBy(() -> params.setResponseDispatcher(null).validate())
87 .withMessageContaining("Dispatcher");
91 void testValidate_MissingPublisher() {
92 assertThatIllegalArgumentException().isThrownBy(() -> params.setPdpPublisher(null).validate())
93 .withMessageContaining("publisher");
97 void testValidate_MissingTimers() {
98 assertThatIllegalArgumentException().isThrownBy(() -> params.setTimers(null).validate())
99 .withMessageContaining("timer");