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.comm.msgdata;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertSame;
27 import static org.junit.Assert.assertTrue;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.models.pdp.concepts.PdpStateChange;
32 import org.onap.policy.models.pdp.concepts.PdpStatus;
33 import org.onap.policy.models.pdp.concepts.PdpUpdate;
34 import org.onap.policy.models.pdp.enums.PdpState;
35 import org.onap.policy.pap.main.comm.CommonRequestBase;
37 public class StateChangeReqTest extends CommonRequestBase {
39 private StateChangeReq data;
40 private PdpStatus response;
41 private PdpStateChange msg;
46 * @throws Exception if an error occurs
49 public void setUp() throws Exception {
52 response = new PdpStatus();
54 response.setName(MY_NAME);
55 response.setState(MY_STATE);
57 msg = new PdpStateChange();
59 msg.setState(MY_STATE);
61 data = new StateChangeReq(reqParams, MY_REQ_NAME, msg);
65 public void testGetMessage() {
66 assertEquals(MY_REQ_NAME, data.getName());
67 assertSame(msg, data.getMessage());
71 public void testCheckResponse() {
72 assertNull(data.checkResponse(response));
76 public void testCheckResponse_NullName() {
77 response.setName(null);
79 assertEquals("null PDP name", data.checkResponse(response));
83 public void testCheckResponse_NullMsgName() {
86 assertEquals(null, data.checkResponse(response));
90 public void testCheckResponse_MismatchedState() {
91 response.setState(DIFF_STATE);
93 assertEquals("state is TERMINATED, but expected SAFE", data.checkResponse(response));
97 public void testReconfigure() {
98 // different message type should fail and leave message unchanged
99 assertFalse(data.reconfigure(new PdpUpdate()));
100 assertSame(msg, data.getMessage());
102 // same state - should succeed, but leave message unchanged
103 PdpStateChange msg2 = new PdpStateChange();
104 msg2.setState(msg.getState());
105 assertTrue(data.reconfigure(msg2));
106 assertSame(msg, data.getMessage());
108 // change old state to active - should fail and leave message unchanged
109 msg2.setState(PdpState.ACTIVE);
110 assertFalse(data.reconfigure(msg2));
111 assertSame(msg, data.getMessage());
113 // different, inactive state - should succeed and install NEW message
114 msg2.setState(PdpState.PASSIVE);
115 assertTrue(data.reconfigure(msg2));
116 assertSame(msg2, data.getMessage());