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 * ================================================================================
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.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;
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;
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;
45 private PdpParameters pdpParams;
46 private TimerManager updTimers;
47 private TimerManager stateTimers;
50 * Sets up the objects and creates an empty {@link #builder}.
53 @SuppressWarnings("unchecked")
55 pub = mock(Publisher.class);
56 disp = mock(RequestIdDispatcher.class);
58 pdpParams = mock(PdpParameters.class);
59 updTimers = mock(TimerManager.class);
60 stateTimers = mock(TimerManager.class);
62 builder = PdpModifyRequestMapParams.builder().modifyLock(lock).pdpPublisher(pub).responseDispatcher(disp)
63 .params(pdpParams).stateChangeTimers(stateTimers).updateTimers(updTimers)
64 .maxPdpAgeMs(MAX_PDP_AGE_MS);
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());
80 public void testValidate() {
81 assertThatCode(builder.build()::validate).doesNotThrowAnyException();
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");
91 assertThatCode(builder.maxPdpAgeMs(1).build()::validate).doesNotThrowAnyException();
95 public void testValidate_MissingPublisher() {
96 assertThatIllegalArgumentException().isThrownBy(() -> builder.pdpPublisher(null).build().validate())
97 .withMessageContaining("publisher");
101 public void testValidate_MissingDispatcher() {
102 assertThatIllegalArgumentException().isThrownBy(() -> builder.responseDispatcher(null).build().validate())
103 .withMessageContaining("Dispatch");
107 public void testValidate_MissingLock() {
108 assertThatIllegalArgumentException().isThrownBy(() -> builder.modifyLock(null).build().validate())
109 .withMessageContaining("Lock");
113 public void testValidate_MissingPdpParams() {
114 assertThatIllegalArgumentException().isThrownBy(() -> builder.params(null).build().validate())
115 .withMessageContaining("PDP param");
119 public void testValidate_MissingStateChangeTimers() {
120 assertThatIllegalArgumentException().isThrownBy(() -> builder.stateChangeTimers(null).build().validate())
121 .withMessageContaining("state");
125 public void testValidate_MissingUpdateTimers() {
126 assertThatIllegalArgumentException().isThrownBy(() -> builder.updateTimers(null).build().validate())
127 .withMessageContaining("update");