From 7da3ddfa40de2f683a2d423d62b78a8d001108eb Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Fri, 27 Mar 2020 08:03:24 -0400 Subject: More sonar issues cleanup Either log or rethrow Use boolean expression Add at least one test Remove commented out code Issue-ID: POLICY-2204 Change-Id: I4fdf31aea75303e4f49d25198eb3b12341995bfe Signed-off-by: Pamela Dragosh --- .../common/gson/internal/FieldDeserializerTest.java | 10 +++++----- .../main/java/org/onap/policy/common/ia/DbAudit.java | 19 ++++++------------- .../org/onap/policy/common/im/IntegrityMonitor.java | 12 ++++++------ .../org/onap/policy/common/im/StateManagement.java | 2 -- .../bus/internal/SingleThreadedBusTopicSource.java | 10 ++++------ .../bus/internal/SingleThreadedDmaapTopicSource.java | 6 ++---- .../onap/policy/common/utils/time/TestTimeMulti.java | 5 ++--- .../org/onap/policy/common/utils/time/WorkItem.java | 5 ++--- .../onap/policy/common/utils/time/WorkItemTest.java | 5 +++-- 9 files changed, 30 insertions(+), 44 deletions(-) diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java index 509ddb79..acb241e6 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java @@ -1,8 +1,8 @@ -/* +/*- * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -61,18 +61,18 @@ public class FieldDeserializerTest { // no value in tree - text remains unchanged text = INITIAL_VALUE; deser.getFromTree(json, this); - assertEquals(text, INITIAL_VALUE); + assertEquals(INITIAL_VALUE, text); // null value in tree - text remains unchanged json.add(TEXT_FIELD_NAME, JsonNull.INSTANCE); deser.getFromTree(json, this); - assertEquals(text, INITIAL_VALUE); + assertEquals(INITIAL_VALUE, text); // now assign a value - text should be changed now json.addProperty(TEXT_FIELD_NAME, NEW_VALUE); deser.getFromTree(json, this); - assertEquals(text, NEW_VALUE); + assertEquals(NEW_VALUE, text); /* * check list field diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java index 4e718a60..a7b7fd89 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java @@ -1,8 +1,8 @@ -/* +/*-- * ============LICENSE_START======================================================= * Integrity Audit * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 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. @@ -60,16 +60,11 @@ public class DbAudit { */ public DbAudit(DbDao dbDao) { - if (logger.isDebugEnabled()) { - logger.debug("Constructor: Entering"); - } + logger.debug("Constructor: Entering"); this.dbDao = dbDao; - if (logger.isDebugEnabled()) { - logger.debug("Constructor: Exiting"); - } - + logger.debug("Constructor: Exiting"); } /** @@ -153,8 +148,6 @@ public class DbAudit { if (logger.isDebugEnabled()) { logger.debug("dbAudit: Exiting"); } - - return; // all done } private void compareList(String persistenceUnit, List iaeList, IntegrityAuditEntity myIae, @@ -246,7 +239,7 @@ public class DbAudit { * again for all nodes later. */ compareMineWithTheirs(myEntries, theirEntries, clazzName, misMatchedMap); - } // end for (IntegrityAuditEntity iae : iaeList) + } } private void compareMineWithTheirs(Map myEntries, Map theirEntries, @@ -332,7 +325,7 @@ public class DbAudit { logger.debug("dbAudit: Second comparison; waking from sleep"); } } - } // end: for(String clazzName: classNameList) + } if (errorCount != 0) { String msg = " DB Audit: " + errorCount diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java index 1372b4fc..d96aa44a 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/IntegrityMonitor.java @@ -925,7 +925,7 @@ public class IntegrityMonitor { } // check the next group - } // end for (String group : depGroups) + } return dependencyOk; } @@ -963,7 +963,7 @@ public class IntegrityMonitor { appendSeparator(errorMsg); errorMsg.append(failMsg); } - } // end for (String dep : dependencies) + } // if all dependencies in a group are failed, set this // resource's state to disable dependency @@ -1206,7 +1206,7 @@ public class IntegrityMonitor { } catch (Exception e1) { logger.error(EXCEPTION_STRING, e1); } - logger.error("writeFpc DB table commit failed with exception", e); + logger.error("writeFpc DB table commit failed with exception"); throw e; } } @@ -1500,8 +1500,8 @@ public class IntegrityMonitor { if (sme != null && !sme.getOpState().equals(StateManagement.DISABLED)) { disableFailed(sme); } - } // end if(diffMs > staleMs) - } // end for(ForwardProgressEntity fpe : fpList) + } + } logger.debug("IntegrityMonitor.executeStateAudit(): exit"); } @@ -1817,7 +1817,7 @@ public class IntegrityMonitor { allNotWellMap = new HashMap<>(); } - if (asw) { + if (Boolean.TRUE.equals(asw)) { logger.info("allSeemsWell: ALL SEEMS WELL: key = {}, msg = {}", key, msg); allSeemsWellMap.put(key, msg); allNotWellMap.remove(key); diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java index 7a018ef9..65ebf2d2 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java @@ -174,7 +174,6 @@ public class StateManagement { logger.debug("StateManagement: {}() operation completed, resourceName = {}", methodName, resourceName); } catch (final Exception ex) { - logger.error("StateManagement.{}() caught unexpected exception: ", methodName, ex); throw new StateManagementException("StateManagement." + methodName + "() Exception: " + ex); } } @@ -476,7 +475,6 @@ public class StateManagement { } } catch (final Exception ex) { final String message = "findStateManagementEntity exception"; - logger.error("{}: {}", message, ex.toString(), ex); throw new EntityRetrievalException(message, ex); } } diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSource.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSource.java index 164f2b16..510ddaaa 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSource.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSource.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2018-2019 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -47,7 +47,7 @@ public abstract class SingleThreadedBusTopicSource extends BusTopicBase * Not to be converted to PolicyLogger. This will contain all instract /out traffic and only * that in a single file in a concise format. */ - private static Logger logger = LoggerFactory.getLogger(InlineBusTopicSink.class); + private static Logger logger = LoggerFactory.getLogger(SingleThreadedBusTopicSource.class); /** * Bus consumer group. @@ -134,8 +134,7 @@ public abstract class SingleThreadedBusTopicSource extends BusTopicBase logger.info("{}: register: start not attempted", this); } } catch (Exception e) { - logger.warn("{}: cannot start after registration of because of: {}", this, topicListener, e.getMessage(), - e); + logger.warn("{}: cannot start after registration of because of: {}", this, topicListener, e); } } @@ -176,8 +175,7 @@ public abstract class SingleThreadedBusTopicSource extends BusTopicBase busPollerThread.start(); return true; } catch (Exception e) { - logger.warn("{}: cannot start because of {}", this, e.getMessage(), e); - throw new IllegalStateException(e); + throw new IllegalStateException(this + ": cannot start", e); } } } diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java index e5d08a2a..6ed2e31e 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2018-2019 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -75,9 +75,7 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource try { this.init(); } catch (Exception e) { - logger.error("ERROR during init in dmaap-source: cannot create topic {} because of {}", - topic, e.getMessage(), e); - throw new IllegalArgumentException(e); + throw new IllegalArgumentException("ERROR during init in dmaap-source: cannot create topic " + topic, e); } } diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java b/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java index f52105ed..5002edfa 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2020 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. @@ -29,7 +29,6 @@ import java.util.PriorityQueue; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import lombok.Getter; -import org.onap.policy.common.utils.time.TestTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -180,7 +179,7 @@ public class TestTimeMulti extends TestTime { long realEnd = System.currentTimeMillis() + maxWaitMs; while (System.currentTimeMillis() < realEnd) { - if (condition.call()) { + if (Boolean.TRUE.equals(condition.call())) { return; } diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/time/WorkItem.java b/utils-test/src/main/java/org/onap/policy/common/utils/time/WorkItem.java index af3d5d7e..cd690602 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/time/WorkItem.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/time/WorkItem.java @@ -1,8 +1,8 @@ -/* +/*-- * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -22,7 +22,6 @@ package org.onap.policy.common.utils.time; import lombok.AccessLevel; import lombok.Getter; -import org.onap.policy.common.utils.time.TestTime; /** * Work item to be executed at some time. diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java index 4e6f92b5..d2fc8d58 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -20,6 +20,7 @@ package org.onap.policy.common.utils.time; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -88,7 +89,7 @@ public class WorkItemTest { @Test public void testFire() { // ensure no exception is thrown - item.fire(); + assertThatCode(() -> item.fire()).doesNotThrowAnyException(); } @Test -- cgit 1.2.3-korg