2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.main.parameters;
23 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
24 import static org.junit.Assert.assertSame;
25 import static org.mockito.Mockito.mock;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.common.endpoints.listeners.RequestIdDispatcher;
30 import org.onap.policy.models.pdp.concepts.PdpMessage;
31 import org.onap.policy.models.pdp.concepts.PdpStatus;
32 import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
33 import org.onap.policy.pap.main.comm.Publisher;
34 import org.onap.policy.pap.main.comm.TimerManager;
35 import org.onap.policy.pap.main.notification.PolicyNotifier;
37 public class TestPdpModifyRequestMapParams {
38 private PdpModifyRequestMapParams params;
39 private Publisher<PdpMessage> pub;
40 private RequestIdDispatcher<PdpStatus> disp;
42 private PdpParameters pdpParams;
43 private TimerManager updTimers;
44 private TimerManager stateTimers;
45 private PolicyModelsProviderFactoryWrapper dao;
46 private PolicyNotifier notifier;
49 * Sets up the objects and creates an empty {@link #params}.
52 @SuppressWarnings("unchecked")
54 pub = mock(Publisher.class);
55 disp = mock(RequestIdDispatcher.class);
57 pdpParams = mock(PdpParameters.class);
58 updTimers = mock(TimerManager.class);
59 stateTimers = mock(TimerManager.class);
60 dao = mock(PolicyModelsProviderFactoryWrapper.class);
61 notifier = mock(PolicyNotifier.class);
63 params = new PdpModifyRequestMapParams().setModifyLock(lock).setPdpPublisher(pub).setResponseDispatcher(disp)
64 .setParams(pdpParams).setStateChangeTimers(stateTimers).setUpdateTimers(updTimers)
65 .setDaoFactory(dao).setPolicyNotifier(notifier);
69 public void testGettersSetters() {
70 assertSame(pub, params.getPdpPublisher());
71 assertSame(disp, params.getResponseDispatcher());
72 assertSame(lock, params.getModifyLock());
73 assertSame(pdpParams, params.getParams());
74 assertSame(updTimers, params.getUpdateTimers());
75 assertSame(stateTimers, params.getStateChangeTimers());
76 assertSame(dao, params.getDaoFactory());
77 assertSame(notifier, params.getPolicyNotifier());
81 public void testValidate() {
87 public void testValidate_MissingPublisher() {
88 assertThatIllegalArgumentException().isThrownBy(() -> params.setPdpPublisher(null).validate())
89 .withMessageContaining("publisher");
93 public void testValidate_MissingDispatcher() {
94 assertThatIllegalArgumentException().isThrownBy(() -> params.setResponseDispatcher(null).validate())
95 .withMessageContaining("Dispatch");
99 public void testValidate_MissingLock() {
100 assertThatIllegalArgumentException().isThrownBy(() -> params.setModifyLock(null).validate())
101 .withMessageContaining("Lock");
105 public void testValidate_MissingPdpParams() {
106 assertThatIllegalArgumentException().isThrownBy(() -> params.setParams(null).validate())
107 .withMessageContaining("PDP param");
111 public void testValidate_MissingStateChangeTimers() {
112 assertThatIllegalArgumentException().isThrownBy(() -> params.setStateChangeTimers(null).validate())
113 .withMessageContaining("state");
117 public void testValidate_MissingUpdateTimers() {
118 assertThatIllegalArgumentException().isThrownBy(() -> params.setUpdateTimers(null).validate())
119 .withMessageContaining("update");
123 public void testValidate_MissingDaoFactory() {
124 assertThatIllegalArgumentException().isThrownBy(() -> params.setDaoFactory(null).validate())
125 .withMessageContaining("DAO");
129 public void testValidate_MissingNotifier() {
130 assertThatIllegalArgumentException().isThrownBy(() -> params.setPolicyNotifier(null).validate())
131 .withMessageContaining("notifier");