Move PAP database provider to spring boot default
[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  * ================================================================================
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.pap.main.parameters;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.assertj.core.api.Assertions.assertThatCode;
26 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
27 import static org.junit.Assert.assertSame;
28 import static org.mockito.Mockito.mock;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.policy.common.endpoints.listeners.RequestIdDispatcher;
33 import org.onap.policy.models.pdp.concepts.PdpMessage;
34 import org.onap.policy.models.pdp.concepts.PdpStatus;
35 import org.onap.policy.pap.main.comm.Publisher;
36 import org.onap.policy.pap.main.comm.TimerManager;
37 import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams.PdpModifyRequestMapParamsBuilder;
38
39 public class TestPdpModifyRequestMapParams {
40     private static final long MAX_PDP_AGE_MS = 100;
41     private PdpModifyRequestMapParamsBuilder builder;
42     private Publisher<PdpMessage> pub;
43     private RequestIdDispatcher<PdpStatus> disp;
44     private Object lock;
45     private PdpParameters pdpParams;
46     private TimerManager updTimers;
47     private TimerManager stateTimers;
48
49     /**
50      * Sets up the objects and creates an empty {@link #builder}.
51      */
52     @Before
53     @SuppressWarnings("unchecked")
54     public void setUp() {
55         pub = mock(Publisher.class);
56         disp = mock(RequestIdDispatcher.class);
57         lock = new Object();
58         pdpParams = mock(PdpParameters.class);
59         updTimers = mock(TimerManager.class);
60         stateTimers = mock(TimerManager.class);
61
62         builder = PdpModifyRequestMapParams.builder().modifyLock(lock).pdpPublisher(pub).responseDispatcher(disp)
63                         .params(pdpParams).stateChangeTimers(stateTimers).updateTimers(updTimers)
64                         .maxPdpAgeMs(MAX_PDP_AGE_MS);
65     }
66
67     @Test
68     public void testGettersSetters() {
69         PdpModifyRequestMapParams params = builder.build();
70         assertThat(params.getMaxPdpAgeMs()).isEqualTo(MAX_PDP_AGE_MS);
71         assertSame(pub, params.getPdpPublisher());
72         assertSame(disp, params.getResponseDispatcher());
73         assertSame(lock, params.getModifyLock());
74         assertSame(pdpParams, params.getParams());
75         assertSame(updTimers, params.getUpdateTimers());
76         assertSame(stateTimers, params.getStateChangeTimers());
77     }
78
79     @Test
80     public void testValidate() {
81         assertThatCode(builder.build()::validate).doesNotThrowAnyException();
82     }
83
84     @Test
85     public void testValidate_InvalidMaxPdpAge() {
86         assertThatIllegalArgumentException().isThrownBy(() -> builder.maxPdpAgeMs(0).build().validate())
87                         .withMessageContaining("maxPdpAgeMs");
88         assertThatIllegalArgumentException().isThrownBy(() -> builder.maxPdpAgeMs(-1).build().validate())
89                         .withMessageContaining("maxPdpAgeMs");
90
91         assertThatCode(builder.maxPdpAgeMs(1).build()::validate).doesNotThrowAnyException();
92     }
93
94     @Test
95     public void testValidate_MissingPublisher() {
96         assertThatIllegalArgumentException().isThrownBy(() -> builder.pdpPublisher(null).build().validate())
97                         .withMessageContaining("publisher");
98     }
99
100     @Test
101     public void testValidate_MissingDispatcher() {
102         assertThatIllegalArgumentException().isThrownBy(() -> builder.responseDispatcher(null).build().validate())
103                         .withMessageContaining("Dispatch");
104     }
105
106     @Test
107     public void testValidate_MissingLock() {
108         assertThatIllegalArgumentException().isThrownBy(() -> builder.modifyLock(null).build().validate())
109                         .withMessageContaining("Lock");
110     }
111
112     @Test
113     public void testValidate_MissingPdpParams() {
114         assertThatIllegalArgumentException().isThrownBy(() -> builder.params(null).build().validate())
115                         .withMessageContaining("PDP param");
116     }
117
118     @Test
119     public void testValidate_MissingStateChangeTimers() {
120         assertThatIllegalArgumentException().isThrownBy(() -> builder.stateChangeTimers(null).build().validate())
121                         .withMessageContaining("state");
122     }
123
124     @Test
125     public void testValidate_MissingUpdateTimers() {
126         assertThatIllegalArgumentException().isThrownBy(() -> builder.updateTimers(null).build().validate())
127                         .withMessageContaining("update");
128     }
129 }