From dffa54c9a27bcd9524e2aa75684ff02d70507b59 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Thu, 26 Mar 2020 10:03:11 -0400 Subject: Remove unused imports and clean logs Unused imports and marked an unused variable. Added m2e eclipse settings (other repos have this). Added some test logback.xml to clear out jetty debug messages. Replaced deprecated newInstance with getDeclaredConstructor. newInstance Either log or throw Exception - chose throw Added some assertions to JUnit test. Issue-ID: POLICY-2305 Change-Id: Ia4e9ce62dc7fb45aea247d470ca7245e694fc26e Signed-off-by: Pamela Dragosh --- .../parameters/DistributionParameterHandler.java | 2 +- ...orwarderConfigurationParametersJsonAdapter.java | 2 +- .../main/startstop/DistributionActivator.java | 10 +++--- .../policy/distribution/main/startstop/Main.java | 4 ++- .../distribution/main/startstop/TestMain.java | 10 ++++-- main/src/test/resources/logback-test.xml | 41 ++++++++++++++++++++++ 6 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 main/src/test/resources/logback-test.xml (limited to 'main') diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java index 7ef5fd75..f7314220 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java +++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -69,7 +70,6 @@ public class DistributionParameterHandler { } catch (final Exception e) { final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath() + "\"\n" + "(" + e.getClass().getSimpleName() + "):" + e.getMessage(); - LOGGER.error(errorMessage, e); throw new PolicyDistributionException(errorMessage, e); } diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParametersJsonAdapter.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParametersJsonAdapter.java index 687970dc..640353ea 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParametersJsonAdapter.java +++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParametersJsonAdapter.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,7 +75,6 @@ public class PolicyForwarderConfigurationParametersJsonAdapter } catch (final ClassNotFoundException e) { final String errorMessage = "parameter \"" + PARAMETER_CLASS_NAME + "\" value \"" + policyForwarderParameterClassName + "\", could not find class"; - LOGGER.warn(errorMessage, e); throw new IllegalArgumentException(errorMessage, e); } return policyForwarderParameterClass; diff --git a/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java index a50fa6bc..3f19baf1 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java +++ b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications 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,6 +22,7 @@ package org.onap.policy.distribution.main.startstop; +import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -82,12 +83,14 @@ public class DistributionActivator { try { final Class receptionHandlerClass = (Class) Class .forName(receptionHandlerParameters.getReceptionHandlerClassName()); - final AbstractReceptionHandler receptionHandler = receptionHandlerClass.newInstance(); + final AbstractReceptionHandler receptionHandler = + receptionHandlerClass.getDeclaredConstructor().newInstance(); receptionHandler.initialize(receptionHandlerParameters.getName()); receptionHandlersMap.put(receptionHandlerParameters.getName(), receptionHandler); DistributionActivator.setAlive(true); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException - | PluginInitializationException exp) { + | PluginInitializationException | IllegalArgumentException | InvocationTargetException + | NoSuchMethodException | SecurityException exp) { throw new PolicyDistributionException(exp.getMessage(), exp); } } @@ -126,7 +129,6 @@ public class DistributionActivator { // Stop the distribution rest server restServer.stop(); } catch (final Exception exp) { - LOGGER.error("Policy distribution service termination failed", exp); throw new PolicyDistributionException(exp.getMessage(), exp); } } diff --git a/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java b/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java index 13da2169..2c676333 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java +++ b/main/src/main/java/org/onap/policy/distribution/main/startstop/Main.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +85,8 @@ public class Main { try { activator.initialize(); } catch (final PolicyDistributionException e) { - LOGGER.error("start of policy distribution service failed, used parameters are " + Arrays.toString(args), + LOGGER.error("start of policy distribution service failed, used parameters are {}", + Arrays.toString(args), e); return; } diff --git a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java index e1c5d22b..e5d03aaf 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java +++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +21,7 @@ package org.onap.policy.distribution.main.startstop; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -62,9 +64,11 @@ public class TestMain { @Test public void testMain_Help() { - final String[] distributionConfigParameters = - { "-h" }; - Main.main(distributionConfigParameters); + assertThatCode(() -> { + final String[] distributionConfigParameters = + { "-h" }; + Main.main(distributionConfigParameters); + }).doesNotThrowAnyException(); } @Test diff --git a/main/src/test/resources/logback-test.xml b/main/src/test/resources/logback-test.xml new file mode 100644 index 00000000..f2f8acbb --- /dev/null +++ b/main/src/test/resources/logback-test.xml @@ -0,0 +1,41 @@ + + + + + + policy-api + + + + + + %d %contextName [%t] %level %logger{36} - %msg%n + + + + + + + + + + + -- cgit 1.2.3-korg