From aa987aab348f13d477c6cf32e61689d396ebfba5 Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Wed, 8 Jul 2020 13:21:57 +0100 Subject: Fix assertTrue SONAR issues in apex-pdp/examples and apex-pdp/model Replace assertTrue with assertEquals and assertFalse with assertNotEquals in apex-pdp/examples and apex-pdp/model Issue-ID: POLICY-2690 Change-Id: Ie863dd95ccead62268689a4a8388f9b6e8821649 Signed-off-by: JvD_Ericsson --- .../policy/apex/examples/aadm/AadmModelTest.java | 5 +++-- .../policy/apex/examples/aadm/AadmUseCaseTest.java | 25 +++++++++++---------- .../adaptive/AnomalyDetectionConceptTest.java | 26 ++++++++++++---------- .../adaptive/AnomalyDetectionModelTest.java | 5 +++-- .../apex/examples/adaptive/AutoLearnModelTest.java | 5 +++-- .../examples/myfirstpolicy/MfpUseCaseTest.java | 16 ++++++------- 6 files changed, 44 insertions(+), 38 deletions(-) (limited to 'examples') diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java index a44a4cc1a..fe9914061 100644 --- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.apex.examples.aadm; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; @@ -44,7 +45,7 @@ public class AadmModelTest { @Test public void testModelValid() throws Exception { final AxValidationResult result = testApexModel.testApexModelValid(); - assertTrue(result.toString().equals(VALID_MODEL_STRING)); + assertEquals(VALID_MODEL_STRING, result.toString()); } @Test diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java index 8e05aff51..430074ea8 100644 --- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java @@ -22,6 +22,7 @@ package org.onap.policy.apex.examples.aadm; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -157,7 +158,7 @@ public class AadmUseCaseTest { assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT")); assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId()); // no DOS_IN_eNodeB set so return probe action - assertTrue(result.get("ACTTASK").equals("probe")); + assertEquals("probe", result.get("ACTTASK")); assertTrue((boolean) result.get("TCP_ON")); assertTrue((boolean) result.get("PROBE_ON")); logger.info("Receiving action event with {} action", result.get("ACTTASK")); @@ -195,7 +196,7 @@ public class AadmUseCaseTest { assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT")); assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId()); // DOS_IN_eNodeB set to be more than throughput so return act action - assertTrue(result.get("ACTTASK").equals("act")); + assertEquals("act", result.get("ACTTASK")); // only one imsi was sent to process, so stop probe and tcp assertTrue(!(boolean) result.get("TCP_ON")); assertTrue(!(boolean) result.get("PROBE_ON")); @@ -232,7 +233,7 @@ public class AadmUseCaseTest { result = listener.getResult(); assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT")); assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId()); - assertTrue(result.get("ACTTASK").equals("probe")); + assertEquals("probe", result.get("ACTTASK")); assertTrue((boolean) result.get("TCP_ON")); assertTrue((boolean) result.get("PROBE_ON")); assertEquals(99, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDosCount()); @@ -267,7 +268,7 @@ public class AadmUseCaseTest { result = listener.getResult(); assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT")); assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId()); - assertTrue(result.get("ACTTASK").equals("act")); + assertEquals("act", result.get("ACTTASK")); assertTrue(!(boolean) result.get("TCP_ON")); assertTrue(!(boolean) result.get("PROBE_ON")); assertEquals(98, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDosCount()); @@ -304,7 +305,7 @@ public class AadmUseCaseTest { result = listener.getResult(); assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT")); assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId()); - assertTrue(result.get("ACTTASK").equals("act")); + assertEquals("act", result.get("ACTTASK")); assertTrue(!(boolean) result.get("TCP_ON")); assertTrue(!(boolean) result.get("PROBE_ON")); assertEquals(100, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDosCount()); @@ -337,7 +338,7 @@ public class AadmUseCaseTest { result = listener.getResult(); assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT")); assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId()); - assertTrue(result.get("ACTTASK").equals("probe")); + assertEquals("probe", result.get("ACTTASK")); assertTrue((boolean) result.get("TCP_ON")); assertTrue((boolean) result.get("PROBE_ON")); assertEquals(99, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDosCount()); @@ -375,7 +376,7 @@ public class AadmUseCaseTest { result = listener.getResult(); assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT")); assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId()); - assertTrue(result.get("ACTTASK").equals("probe")); + assertEquals("probe", result.get("ACTTASK")); assertTrue((boolean) result.get("TCP_ON")); assertTrue((boolean) result.get("PROBE_ON")); assertEquals(102, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDosCount()); @@ -408,7 +409,7 @@ public class AadmUseCaseTest { result = listener.getResult(); assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT")); assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId()); - assertTrue(result.get("ACTTASK").equals("probe")); + assertEquals("probe", result.get("ACTTASK")); assertTrue((boolean) result.get("TCP_ON")); assertTrue((boolean) result.get("PROBE_ON")); assertEquals(102, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDosCount()); @@ -417,8 +418,8 @@ public class AadmUseCaseTest { apexEngine.handleEvent(result); result = listener.getResult(); assertTrue(result.getName().startsWith("SAPCBlacklistSubscriberEvent")); - assertTrue(result.get("PROFILE").equals("ServiceA")); - assertTrue(result.get("BLACKLIST_ON").equals(true)); + assertEquals("ServiceA", result.get("PROFILE")); + assertTrue((boolean) result.get("BLACKLIST_ON")); event = apexEngine.createEvent(new AxArtifactKey("PeriodicEvent", "0.0.1")); event.put("PERIODIC_EVENT_COUNT", (long) 100); @@ -431,8 +432,8 @@ public class AadmUseCaseTest { assertTrue(result.getName().startsWith("SAPCBlacklistSubscriberEvent")); assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId()); assertEquals(0L, result.get("IMSI")); - assertTrue(result.get("PROFILE").equals("ServiceA")); - assertTrue(result.get("BLACKLIST_ON").equals(false)); + assertEquals("ServiceA", result.get("PROFILE")); + assertFalse((boolean) result.get("BLACKLIST_ON")); apexEngine.stop(); } diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java index f1c8d7dca..d24733224 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (c) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +24,7 @@ package org.onap.policy.apex.examples.adaptive; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.LinkedList; @@ -65,40 +67,40 @@ public class AnomalyDetectionConceptTest { public void testEquals() { AnomalyDetection anomalyDetection = new AnomalyDetection(); AnomalyDetection comparisonDetection = new AnomalyDetection(); - assertTrue(anomalyDetection.equals(comparisonDetection)); + assertEquals(anomalyDetection, comparisonDetection); //Compare object to itself - assertTrue(anomalyDetection.equals(anomalyDetection)); + assertEquals(anomalyDetection, anomalyDetection); //Compare object to null - assertFalse(anomalyDetection.equals(null)); + assertNotNull(anomalyDetection); //compare object to string - assertFalse(anomalyDetection.equals("test")); + assertNotEquals(anomalyDetection, "test"); // Anomaly Scores comparison anomalyDetection.setAnomalyScores(null); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); comparisonDetection.setAnomalyScores(null); - assertTrue(anomalyDetection.equals(comparisonDetection)); + assertEquals(anomalyDetection, comparisonDetection); List anomalyScores = new LinkedList<>(); anomalyScores.add((double) 20); anomalyDetection.setAnomalyScores(anomalyScores); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); comparisonDetection.setAnomalyScores(anomalyScores); assertTrue(anomalyDetection.checkSetAnomalyScores()); //First Round Checks anomalyDetection.setFirstRound(false); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); anomalyDetection.setFirstRound(true); //Frequency Checks anomalyDetection.setFrequency(55); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); anomalyDetection.setFrequency(0); //FrequencyForecasted Checks List comparisonFrequency = new LinkedList<>(); comparisonDetection.setFrequencyForecasted(comparisonFrequency); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); anomalyDetection.setFrequencyForecasted(anomalyScores); - assertFalse(anomalyDetection.equals(comparisonDetection)); + assertNotEquals(anomalyDetection, comparisonDetection); anomalyDetection.setFrequencyForecasted(comparisonFrequency); - assertTrue(anomalyDetection.equals(comparisonDetection)); + assertEquals(anomalyDetection, comparisonDetection); } @Test diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java index 5a36d4070..85cecbe8b 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.apex.examples.adaptive; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; @@ -44,7 +45,7 @@ public class AnomalyDetectionModelTest { @Test public void testModelValid() throws Exception { final AxValidationResult result = testApexModel.testApexModelValid(); - assertTrue(result.toString().equals(VALID_MODEL_STRING)); + assertEquals(VALID_MODEL_STRING, result.toString()); } @Test diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java index 1823f9871..3479ccc9e 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.apex.examples.adaptive; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; @@ -44,7 +45,7 @@ public class AutoLearnModelTest { @Test public void testModelValid() throws Exception { final AxValidationResult result = testApexModel.testApexModelValid(); - assertTrue(result.toString().equals(VALID_MODEL_STRING)); + assertEquals(VALID_MODEL_STRING, result.toString()); } @Test diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java index c495bd32b..8afe7d7cd 100644 --- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java @@ -308,12 +308,12 @@ public class MfpUseCaseTest { gb.create().fromJson(ResourceUtils.getResourceAsString(inputFile), JsonObject.class); assertNotNull(jsonObject); assertTrue(jsonObject.has("name")); - assertTrue(ret.getName().equals(jsonObject.get("name").getAsString())); - assertTrue(ret.getAxEvent().getKey().getName().equals(jsonObject.get("name").getAsString())); + assertEquals(ret.getName(), jsonObject.get("name").getAsString()); + assertEquals(ret.getAxEvent().getKey().getName(), jsonObject.get("name").getAsString()); assertTrue(jsonObject.has("nameSpace")); - assertTrue(ret.getAxEvent().getNameSpace().equals(jsonObject.get("nameSpace").getAsString())); + assertEquals(ret.getAxEvent().getNameSpace(), jsonObject.get("nameSpace").getAsString()); assertTrue(jsonObject.has("version")); - assertTrue(ret.getAxEvent().getKey().getVersion().equals(jsonObject.get("version").getAsString())); + assertEquals(ret.getAxEvent().getKey().getVersion(), jsonObject.get("version").getAsString()); final List reserved = Arrays.asList("name", "nameSpace", "version", "source", "target"); for (final Map.Entry e : jsonObject.entrySet()) { if (reserved.contains(e.getKey())) { @@ -375,12 +375,12 @@ public class MfpUseCaseTest { gb.create().fromJson(ResourceUtils.getResourceAsString(inputFile), JsonObject.class); assertNotNull(jsonObject); assertTrue(jsonObject.has("name")); - assertTrue(ret.getName().equals(jsonObject.get("name").getAsString())); - assertTrue(ret.getAxEvent().getKey().getName().equals(jsonObject.get("name").getAsString())); + assertEquals(ret.getName(), jsonObject.get("name").getAsString()); + assertEquals(ret.getAxEvent().getKey().getName(), jsonObject.get("name").getAsString()); assertTrue(jsonObject.has("nameSpace")); - assertTrue(ret.getAxEvent().getNameSpace().equals(jsonObject.get("nameSpace").getAsString())); + assertEquals(ret.getAxEvent().getNameSpace(), jsonObject.get("nameSpace").getAsString()); assertTrue(jsonObject.has("version")); - assertTrue(ret.getAxEvent().getKey().getVersion().equals(jsonObject.get("version").getAsString())); + assertEquals(ret.getAxEvent().getKey().getVersion(), jsonObject.get("version").getAsString()); final List reserved = Arrays.asList("name", "nameSpace", "version", "source", "target"); for (final Map.Entry e : jsonObject.entrySet()) { if (reserved.contains(e.getKey())) { -- cgit 1.2.3-korg