2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
7 * Modifications Copyright (C) 2023 Nordix Foundation.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pap.main.parameters;
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.assertj.core.api.Assertions.assertThatCode;
27 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
28 import static org.junit.jupiter.api.Assertions.assertSame;
29 import static org.mockito.Mockito.mock;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.onap.policy.common.endpoints.listeners.RequestIdDispatcher;
34 import org.onap.policy.models.pdp.concepts.PdpMessage;
35 import org.onap.policy.models.pdp.concepts.PdpStatus;
36 import org.onap.policy.pap.main.comm.Publisher;
37 import org.onap.policy.pap.main.comm.TimerManager;
38 import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams.PdpModifyRequestMapParamsBuilder;
40 class TestPdpModifyRequestMapParams {
41 private static final long MAX_PDP_AGE_MS = 100;
42 private PdpModifyRequestMapParamsBuilder builder;
43 private Publisher<PdpMessage> pub;
44 private RequestIdDispatcher<PdpStatus> disp;
46 private PdpParameters pdpParams;
47 private TimerManager updTimers;
48 private TimerManager stateTimers;
51 * Sets up the objects and creates an empty {@link #builder}.
54 @SuppressWarnings("unchecked")
56 pub = mock(Publisher.class);
57 disp = mock(RequestIdDispatcher.class);
59 pdpParams = mock(PdpParameters.class);
60 updTimers = mock(TimerManager.class);
61 stateTimers = mock(TimerManager.class);
63 builder = PdpModifyRequestMapParams.builder().modifyLock(lock).pdpPublisher(pub).responseDispatcher(disp)
64 .params(pdpParams).stateChangeTimers(stateTimers).updateTimers(updTimers)
65 .maxPdpAgeMs(MAX_PDP_AGE_MS);
69 void testGettersSetters() {
70 PdpModifyRequestMapParams params = builder.build();
71 assertThat(params.getMaxPdpAgeMs()).isEqualTo(MAX_PDP_AGE_MS);
72 assertSame(pub, params.getPdpPublisher());
73 assertSame(disp, params.getResponseDispatcher());
74 assertSame(lock, params.getModifyLock());
75 assertSame(pdpParams, params.getParams());
76 assertSame(updTimers, params.getUpdateTimers());
77 assertSame(stateTimers, params.getStateChangeTimers());
82 assertThatCode(builder.build()::validate).doesNotThrowAnyException();
86 void testValidate_InvalidMaxPdpAge() {
87 assertThatIllegalArgumentException().isThrownBy(() -> builder.maxPdpAgeMs(0).build().validate())
88 .withMessageContaining("maxPdpAgeMs");
89 assertThatIllegalArgumentException().isThrownBy(() -> builder.maxPdpAgeMs(-1).build().validate())
90 .withMessageContaining("maxPdpAgeMs");
92 assertThatCode(builder.maxPdpAgeMs(1).build()::validate).doesNotThrowAnyException();
96 void testValidate_MissingPublisher() {
97 assertThatIllegalArgumentException().isThrownBy(() -> builder.pdpPublisher(null).build().validate())
98 .withMessageContaining("publisher");
102 void testValidate_MissingDispatcher() {
103 assertThatIllegalArgumentException().isThrownBy(() -> builder.responseDispatcher(null).build().validate())
104 .withMessageContaining("Dispatch");
108 void testValidate_MissingLock() {
109 assertThatIllegalArgumentException().isThrownBy(() -> builder.modifyLock(null).build().validate())
110 .withMessageContaining("Lock");
114 void testValidate_MissingPdpParams() {
115 assertThatIllegalArgumentException().isThrownBy(() -> builder.params(null).build().validate())
116 .withMessageContaining("PDP param");
120 void testValidate_MissingStateChangeTimers() {
121 assertThatIllegalArgumentException().isThrownBy(() -> builder.stateChangeTimers(null).build().validate())
122 .withMessageContaining("state");
126 void testValidate_MissingUpdateTimers() {
127 assertThatIllegalArgumentException().isThrownBy(() -> builder.updateTimers(null).build().validate())
128 .withMessageContaining("update");