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.pap.main.comm.CommonRequestBase;
36 public class StateChangeReqTest extends CommonRequestBase {
38 private StateChangeReq data;
39 private PdpStatus response;
40 private PdpStateChange msg;
44 * @throws Exception if an error occurs
47 public void setUp() throws Exception {
50 response = new PdpStatus();
52 response.setName(MY_NAME);
53 response.setState(MY_STATE);
55 msg = new PdpStateChange();
57 msg.setState(MY_STATE);
59 data = new StateChangeReq(reqParams, MY_REQ_NAME, msg);
63 public void testGetMessage() {
64 assertEquals(MY_REQ_NAME, data.getName());
65 assertSame(msg, data.getMessage());
69 public void testCheckResponse() {
70 assertNull(data.checkResponse(response));
74 public void testCheckResponse_NullName() {
75 response.setName(null);
77 assertEquals("null PDP name", data.checkResponse(response));
81 public void testCheckResponse_NullMsgName() {
84 assertEquals(null, data.checkResponse(response));
88 public void testCheckResponse_MismatchedState() {
89 response.setState(DIFF_STATE);
91 assertEquals("state is TERMINATED, but expected SAFE", data.checkResponse(response));
95 public void isSameContent() {
96 PdpStateChange msg2 = new PdpStateChange();
97 msg2.setName("world");
98 msg2.setState(MY_STATE);
99 assertTrue(data.isSameContent(new StateChangeReq(reqParams, MY_REQ_NAME, msg2)));
102 msg2.setState(DIFF_STATE);
103 assertFalse(data.isSameContent(new StateChangeReq(reqParams, MY_REQ_NAME, msg2)));
105 // different request type
106 assertFalse(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, new PdpUpdate())));
110 public void testGetPriority() {
111 assertTrue(data.getPriority() < new UpdateReq(reqParams, MY_REQ_NAME, new PdpUpdate()).getPriority());