Java 17 / Spring 6 / Spring Boot 3 Upgrade
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / parameters / TestPdpModifyRequestMapParams.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP PAP
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22
23 package org.onap.policy.pap.main.parameters;
24
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;
30
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;
39
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;
45     private Object lock;
46     private PdpParameters pdpParams;
47     private TimerManager updTimers;
48     private TimerManager stateTimers;
49
50     /**
51      * Sets up the objects and creates an empty {@link #builder}.
52      */
53     @BeforeEach
54     @SuppressWarnings("unchecked")
55     public void setUp() {
56         pub = mock(Publisher.class);
57         disp = mock(RequestIdDispatcher.class);
58         lock = new Object();
59         pdpParams = mock(PdpParameters.class);
60         updTimers = mock(TimerManager.class);
61         stateTimers = mock(TimerManager.class);
62
63         builder = PdpModifyRequestMapParams.builder().modifyLock(lock).pdpPublisher(pub).responseDispatcher(disp)
64                         .params(pdpParams).stateChangeTimers(stateTimers).updateTimers(updTimers)
65                         .maxPdpAgeMs(MAX_PDP_AGE_MS);
66     }
67
68     @Test
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());
78     }
79
80     @Test
81     void testValidate() {
82         assertThatCode(builder.build()::validate).doesNotThrowAnyException();
83     }
84
85     @Test
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");
91
92         assertThatCode(builder.maxPdpAgeMs(1).build()::validate).doesNotThrowAnyException();
93     }
94
95     @Test
96     void testValidate_MissingPublisher() {
97         assertThatIllegalArgumentException().isThrownBy(() -> builder.pdpPublisher(null).build().validate())
98                         .withMessageContaining("publisher");
99     }
100
101     @Test
102     void testValidate_MissingDispatcher() {
103         assertThatIllegalArgumentException().isThrownBy(() -> builder.responseDispatcher(null).build().validate())
104                         .withMessageContaining("Dispatch");
105     }
106
107     @Test
108     void testValidate_MissingLock() {
109         assertThatIllegalArgumentException().isThrownBy(() -> builder.modifyLock(null).build().validate())
110                         .withMessageContaining("Lock");
111     }
112
113     @Test
114     void testValidate_MissingPdpParams() {
115         assertThatIllegalArgumentException().isThrownBy(() -> builder.params(null).build().validate())
116                         .withMessageContaining("PDP param");
117     }
118
119     @Test
120     void testValidate_MissingStateChangeTimers() {
121         assertThatIllegalArgumentException().isThrownBy(() -> builder.stateChangeTimers(null).build().validate())
122                         .withMessageContaining("state");
123     }
124
125     @Test
126     void testValidate_MissingUpdateTimers() {
127         assertThatIllegalArgumentException().isThrownBy(() -> builder.updateTimers(null).build().validate())
128                         .withMessageContaining("update");
129     }
130 }