From 51f1fffd687e53c858685ec41fd3ab8cfd4fcdf1 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 1 Sep 2021 11:45:05 -0400 Subject: Fix sonars in apex-pdp #3 Fixed: - use "var" - use assertEquals instead of assertTrue(xxx.equals()) - separate assertions Issue-ID: POLICY-3093 Change-Id: Id4db62626948681cd267e68a56dda65fa355c6f8 Signed-off-by: Jim Hahn --- .../messaging/MessagingUtilsTest.java | 5 +- .../apex/core/protocols/SupportMessageTest.java | 102 +++++++++++++++++++++ .../apex/core/protocols/SupportMessageTester.java | 102 --------------------- 3 files changed, 105 insertions(+), 104 deletions(-) create mode 100644 core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTest.java delete mode 100644 core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java (limited to 'core') diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java index a3c7ea419..6d5915ce8 100644 --- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java +++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingUtilsTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (c) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +41,7 @@ public class MessagingUtilsTest { @Test(expected = IllegalArgumentException.class) public void testIllegalArgumentException() { - assertEquals(1, MessagingUtils.findPort(65536)); + MessagingUtils.findPort(65536); } @Test @@ -58,7 +59,7 @@ public class MessagingUtilsTest { @Test(expected = IllegalArgumentException.class) public void testInvalidAllocateAddress() { - assertEquals(1, MessagingUtils.allocateAddress(1)); + MessagingUtils.allocateAddress(1); } @Test diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTest.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTest.java new file mode 100644 index 000000000..8b19059b5 --- /dev/null +++ b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTest.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.core.protocols; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Test of the abstract Message class. + */ +public class SupportMessageTest { + + @Test + public void testMessage() { + assertNotNull(new DummyMessage(new DummyAction(null), new AxArtifactKey())); + assertNotNull(new DummyMessage(new DummyAction(null), new AxArtifactKey(), "Message Data")); + + DummyMessage dummyMessage = new DummyMessage(new DummyAction(null), new AxArtifactKey("Target:0.0.1")); + assertEquals(new DummyAction(null), dummyMessage.getAction()); + assertThat(dummyMessage.toString()) + .startsWith("Message(action=org.onap.policy.apex.core.protocols.DummyAction@") + .endsWith("targetKey=AxArtifactKey:(name=Target,version=0.0.1), messageData=null)"); + + dummyMessage.setMessageData("Message Data"); + assertEquals("Message Data", dummyMessage.getMessageData()); + dummyMessage.appendMessageData("\nMore Message Data"); + assertEquals("Message Data\nMore Message Data", dummyMessage.getMessageData()); + dummyMessage.setMessageData(null); + dummyMessage.appendMessageData("\nMore Message Data"); + assertEquals("\nMore Message Data", dummyMessage.getMessageData()); + + dummyMessage.setReplyTimeout(123); + assertEquals(123, dummyMessage.getReplyTimeout()); + assertEquals(new AxArtifactKey("Target:0.0.1"), dummyMessage.getTarget()); + assertEquals("Target", dummyMessage.getTargetName()); + + assertNotEquals(0, dummyMessage.hashCode()); + dummyMessage.setMessageData(null); + assertNotEquals(0, dummyMessage.hashCode()); + dummyMessage = new DummyMessage(null, null, null); + assertNotEquals(0, dummyMessage.hashCode()); + + // disabling sonar because this code tests the equals() method + assertEquals(dummyMessage, dummyMessage); // NOSONAR + assertNotNull(dummyMessage); + + dummyMessage = new DummyMessage(new DummyAction(null), null, null); + DummyMessage otherDummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(new DummyAction(null), null, null); + assertEquals(dummyMessage, otherDummyMessage); + dummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(null, null, null); + assertEquals(dummyMessage, otherDummyMessage); + + dummyMessage = new DummyMessage(null, new AxArtifactKey(), null); + otherDummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(null, new AxArtifactKey(), null); + assertEquals(dummyMessage, otherDummyMessage); + dummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(null, null, null); + assertEquals(dummyMessage, otherDummyMessage); + + dummyMessage = new DummyMessage(null, null, "Message"); + otherDummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(null, null, "Message"); + assertEquals(dummyMessage, otherDummyMessage); + dummyMessage = new DummyMessage(null, null, null); + assertNotEquals(dummyMessage, otherDummyMessage); + otherDummyMessage = new DummyMessage(null, null, null); + assertEquals(dummyMessage, otherDummyMessage); + } +} diff --git a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java b/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java deleted file mode 100644 index 7bc352025..000000000 --- a/core/core-protocols/src/test/java/org/onap/policy/apex/core/protocols/SupportMessageTester.java +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.core.protocols; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; - -/** - * Test of the abstract Message class. - */ -public class SupportMessageTester { - - @Test - public void testMessage() { - assertNotNull(new DummyMessage(new DummyAction(null), new AxArtifactKey())); - assertNotNull(new DummyMessage(new DummyAction(null), new AxArtifactKey(), "Message Data")); - - DummyMessage dummyMessage = new DummyMessage(new DummyAction(null), new AxArtifactKey("Target:0.0.1")); - assertEquals(new DummyAction(null), dummyMessage.getAction()); - assertThat(dummyMessage.toString()) - .startsWith("Message(action=org.onap.policy.apex.core.protocols.DummyAction@") - .endsWith("targetKey=AxArtifactKey:(name=Target,version=0.0.1), messageData=null)"); - - dummyMessage.setMessageData("Message Data"); - assertEquals("Message Data", dummyMessage.getMessageData()); - dummyMessage.appendMessageData("\nMore Message Data"); - assertEquals("Message Data\nMore Message Data", dummyMessage.getMessageData()); - dummyMessage.setMessageData(null); - dummyMessage.appendMessageData("\nMore Message Data"); - assertEquals("\nMore Message Data", dummyMessage.getMessageData()); - - dummyMessage.setReplyTimeout(123); - assertEquals(123, dummyMessage.getReplyTimeout()); - assertEquals(new AxArtifactKey("Target:0.0.1"), dummyMessage.getTarget()); - assertEquals("Target", dummyMessage.getTargetName()); - - assertNotEquals(0, dummyMessage.hashCode()); - dummyMessage.setMessageData(null); - assertNotEquals(0, dummyMessage.hashCode()); - dummyMessage = new DummyMessage(null, null, null); - assertNotEquals(0, dummyMessage.hashCode()); - - // disabling sonar because this code tests the equals() method - assertEquals(dummyMessage, dummyMessage); // NOSONAR - assertNotNull(dummyMessage); - - dummyMessage = new DummyMessage(new DummyAction(null), null, null); - DummyMessage otherDummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(new DummyAction(null), null, null); - assertEquals(dummyMessage, otherDummyMessage); - dummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(null, null, null); - assertEquals(dummyMessage, otherDummyMessage); - - dummyMessage = new DummyMessage(null, new AxArtifactKey(), null); - otherDummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(null, new AxArtifactKey(), null); - assertEquals(dummyMessage, otherDummyMessage); - dummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(null, null, null); - assertEquals(dummyMessage, otherDummyMessage); - - dummyMessage = new DummyMessage(null, null, "Message"); - otherDummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(null, null, "Message"); - assertEquals(dummyMessage, otherDummyMessage); - dummyMessage = new DummyMessage(null, null, null); - assertNotEquals(dummyMessage, otherDummyMessage); - otherDummyMessage = new DummyMessage(null, null, null); - assertEquals(dummyMessage, otherDummyMessage); - } -} -- cgit 1.2.3-korg