* ONAP PAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.pap.main.comm.msgdata;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
+import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.pap.main.comm.CommonRequestBase;
-public class StateChangeReqTest extends CommonRequestBase {
+class StateChangeReqTest extends CommonRequestBase {
private StateChangeReq data;
private PdpStatus response;
/**
* Sets up.
+ *
* @throws Exception if an error occurs
*/
- @Before
+ @BeforeEach
public void setUp() throws Exception {
super.setUp();
}
@Test
- public void testGetMessage() {
+ void testGetMessage() {
assertEquals(MY_REQ_NAME, data.getName());
assertSame(msg, data.getMessage());
}
@Test
- public void testCheckResponse() {
+ void testCheckResponse() {
assertNull(data.checkResponse(response));
}
@Test
- public void testCheckResponse_NullName() {
+ void testCheckResponse_NullName() {
response.setName(null);
assertEquals("null PDP name", data.checkResponse(response));
}
@Test
- public void testCheckResponse_NullMsgName() {
+ void testCheckResponse_NullMsgName() {
msg.setName(null);
- assertEquals(null, data.checkResponse(response));
+ assertNull(data.checkResponse(response));
}
@Test
- public void testCheckResponse_MismatchedState() {
+ void testCheckResponse_MismatchedState() {
response.setState(DIFF_STATE);
assertEquals("state is TERMINATED, but expected SAFE", data.checkResponse(response));
}
@Test
- public void isSameContent() {
- PdpStateChange msg2 = new PdpStateChange();
- msg2.setName("world");
- msg2.setState(MY_STATE);
- assertTrue(data.isSameContent(new StateChangeReq(reqParams, MY_REQ_NAME, msg2)));
+ void testReconfigure() {
+ // different message type should fail and leave message unchanged
+ assertFalse(data.reconfigure(new PdpUpdate()));
+ assertSame(msg, data.getMessage());
- // different state
- msg2.setState(DIFF_STATE);
- assertFalse(data.isSameContent(new StateChangeReq(reqParams, MY_REQ_NAME, msg2)));
+ // same state - should succeed, but leave message unchanged
+ PdpStateChange msg2 = new PdpStateChange();
+ msg2.setState(msg.getState());
+ assertTrue(data.reconfigure(msg2));
+ assertSame(msg, data.getMessage());
- // different request type
- assertFalse(data.isSameContent(new UpdateReq(reqParams, MY_REQ_NAME, new PdpUpdate())));
- }
+ // change old state to active - should fail and leave message unchanged
+ msg2.setState(PdpState.ACTIVE);
+ assertFalse(data.reconfigure(msg2));
+ assertSame(msg, data.getMessage());
- @Test
- public void testGetPriority() {
- assertTrue(data.getPriority() < new UpdateReq(reqParams, MY_REQ_NAME, new PdpUpdate()).getPriority());
+ // different, inactive state - should succeed and install NEW message
+ msg2.setState(PdpState.PASSIVE);
+ assertTrue(data.reconfigure(msg2));
+ assertSame(msg2, data.getMessage());
}
}