Generate notifications when policies change
[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 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.pap.main.parameters;
22
23 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
24 import static org.junit.Assert.assertSame;
25 import static org.mockito.Mockito.mock;
26
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;
36
37 public class TestPdpModifyRequestMapParams {
38     private PdpModifyRequestMapParams params;
39     private Publisher<PdpMessage> pub;
40     private RequestIdDispatcher<PdpStatus> disp;
41     private Object lock;
42     private PdpParameters pdpParams;
43     private TimerManager updTimers;
44     private TimerManager stateTimers;
45     private PolicyModelsProviderFactoryWrapper dao;
46     private PolicyNotifier notifier;
47
48     /**
49      * Sets up the objects and creates an empty {@link #params}.
50      */
51     @Before
52     @SuppressWarnings("unchecked")
53     public void setUp() {
54         pub = mock(Publisher.class);
55         disp = mock(RequestIdDispatcher.class);
56         lock = new Object();
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);
62
63         params = new PdpModifyRequestMapParams().setModifyLock(lock).setPdpPublisher(pub).setResponseDispatcher(disp)
64                         .setParams(pdpParams).setStateChangeTimers(stateTimers).setUpdateTimers(updTimers)
65                         .setDaoFactory(dao).setPolicyNotifier(notifier);
66     }
67
68     @Test
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());
78     }
79
80     @Test
81     public void testValidate() {
82         // no exception
83         params.validate();
84     }
85
86     @Test
87     public void testValidate_MissingPublisher() {
88         assertThatIllegalArgumentException().isThrownBy(() -> params.setPdpPublisher(null).validate())
89                         .withMessageContaining("publisher");
90     }
91
92     @Test
93     public void testValidate_MissingDispatcher() {
94         assertThatIllegalArgumentException().isThrownBy(() -> params.setResponseDispatcher(null).validate())
95                         .withMessageContaining("Dispatch");
96     }
97
98     @Test
99     public void testValidate_MissingLock() {
100         assertThatIllegalArgumentException().isThrownBy(() -> params.setModifyLock(null).validate())
101                         .withMessageContaining("Lock");
102     }
103
104     @Test
105     public void testValidate_MissingPdpParams() {
106         assertThatIllegalArgumentException().isThrownBy(() -> params.setParams(null).validate())
107                         .withMessageContaining("PDP param");
108     }
109
110     @Test
111     public void testValidate_MissingStateChangeTimers() {
112         assertThatIllegalArgumentException().isThrownBy(() -> params.setStateChangeTimers(null).validate())
113                         .withMessageContaining("state");
114     }
115
116     @Test
117     public void testValidate_MissingUpdateTimers() {
118         assertThatIllegalArgumentException().isThrownBy(() -> params.setUpdateTimers(null).validate())
119                         .withMessageContaining("update");
120     }
121
122     @Test
123     public void testValidate_MissingDaoFactory() {
124         assertThatIllegalArgumentException().isThrownBy(() -> params.setDaoFactory(null).validate())
125                         .withMessageContaining("DAO");
126     }
127
128     @Test
129     public void testValidate_MissingNotifier() {
130         assertThatIllegalArgumentException().isThrownBy(() -> params.setPolicyNotifier(null).validate())
131                         .withMessageContaining("notifier");
132     }
133 }