From ef2ff6bae65870a4fccc25373c0cfae881e14a81 Mon Sep 17 00:00:00 2001 From: ramverma Date: Thu, 23 Aug 2018 13:50:31 +0100 Subject: Fix sonar and checkstyle issues in distribution * Fixing all check style issues. * Fixing all sonar issues. * Adding maven check style plugin to fail at warning level. Change-Id: I791b8feef39a3a0c3e1e250efea7b6e78208bf07 Issue-ID: POLICY-1035 Signed-off-by: ramverma --- main/pom.xml | 14 +---- .../main/PolicyDistributionException.java | 12 ++-- .../main/PolicyDistributionRuntimeException.java | 12 ++-- .../main/startstop/DistributionActivator.java | 24 +++++--- .../DistributionCommandLineArguments.java | 29 +++++---- .../main/parameters/CommonTestData.java | 16 ++--- .../TestDistributionParameterHandler.java | 55 +++++++++-------- .../parameters/TestReceptionHandlerParameters.java | 71 +++++++++++----------- .../main/rest/TestDistributionRestServer.java | 18 +++--- .../main/startstop/TestDistributionActivator.java | 4 +- .../distribution/main/startstop/TestMain.java | 14 +++-- 11 files changed, 140 insertions(+), 129 deletions(-) (limited to 'main') diff --git a/main/pom.xml b/main/pom.xml index e027e44c..2b00e323 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -42,25 +42,15 @@ forwarding-plugins ${project.version} - - org.onap.policy.common - utils - 1.3.0-SNAPSHOT - - - org.onap.policy.common - common-parameters - 1.3.0-SNAPSHOT - org.onap.policy.common capabilities - 1.3.0-SNAPSHOT + ${policy.common.version} org.onap.policy.common policy-endpoints - 1.3.0-SNAPSHOT + ${policy.common.version} commons-cli diff --git a/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionException.java b/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionException.java index 807fd936..041f87cb 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionException.java +++ b/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionException.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -39,9 +39,9 @@ public class PolicyDistributionException extends Exception { * Instantiates a new policy distribution exception with a message and a caused by exception. * * @param message the message - * @param e the exception that caused this exception to be thrown + * @param exp the exception that caused this exception to be thrown */ - public PolicyDistributionException(final String message, final Exception e) { - super(message, e); + public PolicyDistributionException(final String message, final Exception exp) { + super(message, exp); } } diff --git a/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionRuntimeException.java b/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionRuntimeException.java index 5999e680..385505a0 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionRuntimeException.java +++ b/main/src/main/java/org/onap/policy/distribution/main/PolicyDistributionRuntimeException.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -39,9 +39,9 @@ public class PolicyDistributionRuntimeException extends RuntimeException { * Instantiates a new policy distribution runtime exception with a message and a caused by exception. * * @param message the message - * @param e the exception that caused this exception to be thrown + * @param exp the exception that caused this exception to be thrown */ - public PolicyDistributionRuntimeException(final String message, final Exception e) { - super(message, e); + public PolicyDistributionRuntimeException(final String message, final Exception exp) { + super(message, exp); } } 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 62314bdf..70724a12 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 @@ -26,11 +26,10 @@ import java.util.Map; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.common.parameters.ParameterService; -import org.onap.policy.distribution.forwarding.PolicyForwardingException; import org.onap.policy.distribution.main.PolicyDistributionException; import org.onap.policy.distribution.main.parameters.DistributionParameterGroup; import org.onap.policy.distribution.main.rest.DistributionRestServer; -import org.onap.policy.distribution.reception.decoding.PolicyDecodingException; +import org.onap.policy.distribution.reception.decoding.PluginInitializationException; import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler; import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters; @@ -79,9 +78,9 @@ public class DistributionActivator { final AbstractReceptionHandler receptionHandler = receptionHandlerClass.newInstance(); receptionHandler.initialize(receptionHandlerParameters.getName()); receptionHandlersMap.put(receptionHandlerParameters.getName(), receptionHandler); - alive = true; + DistributionActivator.setAlive(true); } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException - | PolicyDecodingException | PolicyForwardingException exp) { + | PluginInitializationException exp) { throw new PolicyDistributionException(exp.getMessage(), exp); } } @@ -114,7 +113,7 @@ public class DistributionActivator { } receptionHandlersMap.clear(); deregisterToParameterService(distributionParameterGroup); - alive = false; + DistributionActivator.setAlive(true); // Stop the distribution rest server restServer.stop(); @@ -143,10 +142,10 @@ public class DistributionActivator { for (final ReceptionHandlerParameters params : distributionParameterGroup.getReceptionHandlerParameters() .values()) { params.setName(distributionParameterGroup.getName()); - params.getPSSDConfigurationParametersGroup().setName(distributionParameterGroup.getName()); + params.getPssdConfigurationParametersGroup().setName(distributionParameterGroup.getName()); params.getPluginHandlerParameters().setName(distributionParameterGroup.getName()); ParameterService.register(params); - ParameterService.register(params.getPSSDConfigurationParametersGroup()); + ParameterService.register(params.getPssdConfigurationParametersGroup()); ParameterService.register(params.getPluginHandlerParameters()); } } @@ -161,7 +160,7 @@ public class DistributionActivator { for (final ReceptionHandlerParameters params : distributionParameterGroup.getReceptionHandlerParameters() .values()) { ParameterService.deregister((params.getName())); - ParameterService.deregister((params.getPSSDConfigurationParametersGroup().getName())); + ParameterService.deregister((params.getPssdConfigurationParametersGroup().getName())); ParameterService.deregister((params.getPluginHandlerParameters().getName())); } } @@ -174,4 +173,13 @@ public class DistributionActivator { public static boolean isAlive() { return alive; } + + /** + * Change the alive status of distribution service. + * + * @param status the status + */ + public static void setAlive(final boolean status) { + alive = status; + } } diff --git a/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionCommandLineArguments.java b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionCommandLineArguments.java index 7bd1d06d..b805456e 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionCommandLineArguments.java +++ b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionCommandLineArguments.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -69,7 +69,8 @@ public class DistributionCommandLineArguments { .build()); options.addOption(Option.builder("c") .longOpt("config-file") - .desc("the full path to the configuration file to use, the configuration file must be a Json file containing the policy distribution parameters") + .desc("the full path to the configuration file to use, " + + "the configuration file must be a Json file containing the policy distribution parameters") .hasArg() .argName("CONFIG_FILE") .required(false) @@ -117,7 +118,8 @@ public class DistributionCommandLineArguments { final String[] remainingArgs = commandLine.getArgs(); if (remainingArgs.length > 0 && commandLine.hasOption('c') || remainingArgs.length > 0) { - throw new PolicyDistributionException("too many command line arguments specified : " + Arrays.toString(args)); + throw new PolicyDistributionException( + "too many command line arguments specified : " + Arrays.toString(args)); } if (remainingArgs.length == 1) { @@ -150,7 +152,7 @@ public class DistributionCommandLineArguments { /** * Print version information for policy distribution. - * + * * @return the version string */ public String version() { @@ -166,10 +168,10 @@ public class DistributionCommandLineArguments { public String help(final String mainClassName) { final HelpFormatter helpFormatter = new HelpFormatter(); final StringWriter stringWriter = new StringWriter(); - final PrintWriter stringPW = new PrintWriter(stringWriter); + final PrintWriter printWriter = new PrintWriter(stringWriter); - helpFormatter.printHelp(stringPW, HELP_LINE_LENGTH, mainClassName + " [options...]", "options", options, 0, 0, - ""); + helpFormatter.printHelp(printWriter, HELP_LINE_LENGTH, mainClassName + " [options...]", "options", options, 0, + 0, ""); return stringWriter.toString(); } @@ -224,17 +226,18 @@ public class DistributionCommandLineArguments { } // The file name refers to a resource on the local file system - final URL fileURL = ResourceUtils.getUrl4Resource(fileName); - if (fileURL == null) { + final URL fileUrl = ResourceUtils.getUrl4Resource(fileName); + if (fileUrl == null) { throw new PolicyDistributionException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" does not exist"); } - final File theFile = new File(fileURL.getPath()); + final File theFile = new File(fileUrl.getPath()); if (!theFile.exists()) { throw new PolicyDistributionException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" does not exist"); } if (!theFile.isFile()) { - throw new PolicyDistributionException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is not a normal file"); + throw new PolicyDistributionException( + fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is not a normal file"); } if (!theFile.canRead()) { throw new PolicyDistributionException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is ureadable"); diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java index 59f551cf..62ad0674 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java @@ -26,9 +26,9 @@ import java.util.List; import java.util.Map; import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters; -import org.onap.policy.distribution.reception.parameters.PSSDConfigurationParametersGroup; import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters; import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters; +import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup; import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters; /** @@ -85,7 +85,7 @@ public class CommonTestData { if (!isEmpty) { final Map policyDecoders = getPolicyDecoders(isEmpty); final Map policyForwarders = getPolicyForwarders(isEmpty); - final PSSDConfigurationParametersGroup pssdConfiguration = getPSSDConfigurationParametersGroup(isEmpty);; + final PssdConfigurationParametersGroup pssdConfiguration = getPssdConfigurationParametersGroup(isEmpty);; final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders); final ReceptionHandlerParameters rhParameters = new ReceptionHandlerParameters(RECEPTION_HANDLER_TYPE, RECEPTION_HANDLER_CLASS_NAME, pssdConfiguration, pHParameters); @@ -95,26 +95,26 @@ public class CommonTestData { } /** - * Returns an instance of PSSDConfigurationParametersGroup for test cases. + * Returns an instance of PssdConfigurationParametersGroup for test cases. * * @param isEmpty boolean value to represent that object created should be empty or not - * @return the PSSDConfigurationParametersGroup object + * @return the PssdConfigurationParametersGroup object */ - public PSSDConfigurationParametersGroup getPSSDConfigurationParametersGroup(final boolean isEmpty) { - final PSSDConfigurationParametersGroup pssdConfiguration; + public PssdConfigurationParametersGroup getPssdConfigurationParametersGroup(final boolean isEmpty) { + final PssdConfigurationParametersGroup pssdConfiguration; if (!isEmpty) { final List messageBusAddress = new ArrayList<>(); messageBusAddress.add("localhost"); final List artifactTypes = new ArrayList<>(); artifactTypes.add("TOSCA_CSAR"); - pssdConfiguration = new PSSDConfigurationParametersGroup.PSSDConfigurationBuilder() + pssdConfiguration = new PssdConfigurationParametersGroup.PssdConfigurationBuilder() .setAsdcAddress("localhost").setMessageBusAddress(messageBusAddress).setUser("policy") .setPassword("policy").setPollingInterval(20).setPollingTimeout(30).setConsumerId("policy-id") .setArtifactTypes(artifactTypes).setConsumerGroup("policy-group").setEnvironmentName("TEST") .setKeystorePath("").setKeystorePassword("").setActiveserverTlsAuth(false) .setIsFilterinEmptyResources(true).setIsUseHttpsWithDmaap(false).build(); } else { - pssdConfiguration = new PSSDConfigurationParametersGroup.PSSDConfigurationBuilder().build(); + pssdConfiguration = new PssdConfigurationParametersGroup.PssdConfigurationBuilder().build(); } return pssdConfiguration; } diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java index 69ff0f14..a324e3da 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java @@ -36,7 +36,8 @@ import org.onap.policy.distribution.main.startstop.DistributionCommandLineArgume public class TestDistributionParameterHandler { @Test public void testParameterHandlerNoParameterFile() throws PolicyDistributionException { - final String[] noArgumentString = { "-c", "parameters/NoParameterFile.json" }; + final String[] noArgumentString = + { "-c", "parameters/NoParameterFile.json" }; final DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments(); noArguments.parse(noArgumentString); @@ -51,7 +52,8 @@ public class TestDistributionParameterHandler { @Test public void testParameterHandlerEmptyParameters() throws PolicyDistributionException { - final String[] emptyArgumentString = { "-c", "parameters/EmptyParameters.json" }; + final String[] emptyArgumentString = + { "-c", "parameters/EmptyParameters.json" }; final DistributionCommandLineArguments emptyArguments = new DistributionCommandLineArguments(); emptyArguments.parse(emptyArgumentString); @@ -66,7 +68,8 @@ public class TestDistributionParameterHandler { @Test public void testParameterHandlerBadParameters() throws PolicyDistributionException { - final String[] badArgumentString = { "-c", "parameters/BadParameters.json" }; + final String[] badArgumentString = + { "-c", "parameters/BadParameters.json" }; final DistributionCommandLineArguments badArguments = new DistributionCommandLineArguments(); badArguments.parse(badArgumentString); @@ -83,7 +86,8 @@ public class TestDistributionParameterHandler { @Test public void testParameterHandlerInvalidParameters() throws PolicyDistributionException { - final String[] invalidArgumentString = { "-c", "parameters/InvalidParameters.json" }; + final String[] invalidArgumentString = + { "-c", "parameters/InvalidParameters.json" }; final DistributionCommandLineArguments invalidArguments = new DistributionCommandLineArguments(); invalidArguments.parse(invalidArgumentString); @@ -100,7 +104,8 @@ public class TestDistributionParameterHandler { @Test public void testParameterHandlerNoParameters() throws PolicyDistributionException { - final String[] noArgumentString = { "-c", "parameters/NoParameters.json" }; + final String[] noArgumentString = + { "-c", "parameters/NoParameters.json" }; final DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments(); noArguments.parse(noArgumentString); @@ -115,7 +120,8 @@ public class TestDistributionParameterHandler { @Test public void testParameterHandlerMinumumParameters() throws PolicyDistributionException { - final String[] minArgumentString = { "-c", "parameters/MinimumParameters.json" }; + final String[] minArgumentString = + { "-c", "parameters/MinimumParameters.json" }; final DistributionCommandLineArguments minArguments = new DistributionCommandLineArguments(); minArguments.parse(minArgumentString); @@ -126,7 +132,8 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup() throws PolicyDistributionException { - final String[] distributionConfigParameters = { "-c", "parameters/DistributionConfigParameters.json" }; + final String[] distributionConfigParameters = + { "-c", "parameters/DistributionConfigParameters.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -148,7 +155,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidName() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidName.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidName.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -165,7 +172,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidReceptionHandlerType() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerType.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerType.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -183,7 +190,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidPolicyDecoderType() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidPolicyDecoderType.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidPolicyDecoderType.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -200,7 +207,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidPolicyForwarderType() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidPolicyForwarderType.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidPolicyForwarderType.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -217,7 +224,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_NoReceptionHandler() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_NoReceptionHandler.json" }; + { "-c", "parameters/DistributionConfigParameters_NoReceptionHandler.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -233,7 +240,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_EmptyReceptionHandler() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_EmptyReceptionHandler.json" }; + { "-c", "parameters/DistributionConfigParameters_EmptyReceptionHandler.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -249,7 +256,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_NoPolicyDecoder() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_NoPolicyDecoder.json" }; + { "-c", "parameters/DistributionConfigParameters_NoPolicyDecoder.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -265,7 +272,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_NoPolicyForwarder() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_NoPolicyForwarder.json" }; + { "-c", "parameters/DistributionConfigParameters_NoPolicyForwarder.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -281,7 +288,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_EmptyPolicyDecoder() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_EmptyPolicyDecoder.json" }; + { "-c", "parameters/DistributionConfigParameters_EmptyPolicyDecoder.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -297,7 +304,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_EmptyPolicyForwarder() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_EmptyPolicyForwarder.json" }; + { "-c", "parameters/DistributionConfigParameters_EmptyPolicyForwarder.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -313,7 +320,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidReceptionHandlerClass() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerClass.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerClass.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -329,7 +336,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidPolicyDecoderClass() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidPolicyDecoderClass.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidPolicyDecoderClass.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -345,7 +352,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidPolicyForwarderClass() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidPolicyForwarderClass.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidPolicyForwarderClass.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -361,7 +368,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidRestServerHost() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidRestServerHost.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidRestServerHost.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -378,7 +385,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidRestServerPort() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidRestServerPort.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidRestServerPort.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -395,7 +402,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidRestServerUser() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidRestServerUser.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidRestServerUser.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); @@ -412,7 +419,7 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidRestServerPassword() throws PolicyDistributionException { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidRestServerPassword.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidRestServerPassword.json" }; final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); arguments.parse(distributionConfigParameters); diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java index c902c9b5..960629e4 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java @@ -27,8 +27,8 @@ import static org.junit.Assert.fail; import org.junit.Test; import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.distribution.reception.parameters.PSSDConfigurationParametersGroup; import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters; +import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup; import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters; /** @@ -42,15 +42,15 @@ public class TestReceptionHandlerParameters { @Test public void testReceptionHandlerParameters() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PSSDConfigurationParametersGroup pssdConfiguration = - commonTestData.getPSSDConfigurationParametersGroup(false); - final ReceptionHandlerParameters rHParameters = - new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, - CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pssdConfiguration, pHParameters); + final PssdConfigurationParametersGroup pssdConfiguration = + commonTestData.getPssdConfigurationParametersGroup(false); + final ReceptionHandlerParameters rHParameters = + new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, + CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pssdConfiguration, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType()); assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName()); - assertEquals(pssdConfiguration, rHParameters.getPSSDConfigurationParametersGroup()); + assertEquals(pssdConfiguration, rHParameters.getPssdConfigurationParametersGroup()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertTrue(validationResult.isValid()); } @@ -58,15 +58,14 @@ public class TestReceptionHandlerParameters { @Test public void testReceptionHandlerParameters_NullReceptionHandlerType() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PSSDConfigurationParametersGroup pssdConfiguration = - commonTestData.getPSSDConfigurationParametersGroup(false); - final ReceptionHandlerParameters rHParameters = - new ReceptionHandlerParameters(null, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, - pssdConfiguration, pHParameters); + final PssdConfigurationParametersGroup pssdConfiguration = + commonTestData.getPssdConfigurationParametersGroup(false); + final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(null, + CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pssdConfiguration, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals(null, rHParameters.getReceptionHandlerType()); assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName()); - assertEquals(pssdConfiguration, rHParameters.getPSSDConfigurationParametersGroup()); + assertEquals(pssdConfiguration, rHParameters.getPssdConfigurationParametersGroup()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() @@ -77,15 +76,14 @@ public class TestReceptionHandlerParameters { @Test public void testReceptionHandlerParameters_NullReceptionHandlerClassName() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PSSDConfigurationParametersGroup pssdConfiguration = - commonTestData.getPSSDConfigurationParametersGroup(false); - final ReceptionHandlerParameters rHParameters = - new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, null, - pssdConfiguration, pHParameters); + final PssdConfigurationParametersGroup pssdConfiguration = + commonTestData.getPssdConfigurationParametersGroup(false); + final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters( + CommonTestData.RECEPTION_HANDLER_TYPE, null, pssdConfiguration, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType()); assertEquals(null, rHParameters.getReceptionHandlerClassName()); - assertEquals(pssdConfiguration, rHParameters.getPSSDConfigurationParametersGroup()); + assertEquals(pssdConfiguration, rHParameters.getPssdConfigurationParametersGroup()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() @@ -96,11 +94,10 @@ public class TestReceptionHandlerParameters { @Test public void testReceptionHandlerParameters_EmptyReceptionHandlerType() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PSSDConfigurationParametersGroup pssdConfiguration = - commonTestData.getPSSDConfigurationParametersGroup(false); - final ReceptionHandlerParameters rHParameters = - new ReceptionHandlerParameters("", CommonTestData.RECEPTION_HANDLER_CLASS_NAME, - pssdConfiguration, pHParameters); + final PssdConfigurationParametersGroup pssdConfiguration = + commonTestData.getPssdConfigurationParametersGroup(false); + final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters("", + CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pssdConfiguration, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals("", rHParameters.getReceptionHandlerType()); assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName()); @@ -114,14 +111,14 @@ public class TestReceptionHandlerParameters { @Test public void testReceptionHandlerParameters_EmptyReceptionHandlerClassName() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PSSDConfigurationParametersGroup pssdConfiguration = - commonTestData.getPSSDConfigurationParametersGroup(false); + final PssdConfigurationParametersGroup pssdConfiguration = + commonTestData.getPssdConfigurationParametersGroup(false); final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters( CommonTestData.RECEPTION_HANDLER_TYPE, "", pssdConfiguration, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType()); assertEquals("", rHParameters.getReceptionHandlerClassName()); - assertEquals(pssdConfiguration, rHParameters.getPSSDConfigurationParametersGroup()); + assertEquals(pssdConfiguration, rHParameters.getPssdConfigurationParametersGroup()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult() @@ -133,11 +130,11 @@ public class TestReceptionHandlerParameters { public void testReceptionHandlerParameters_EmptyPluginHandler() { try { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(true); - final PSSDConfigurationParametersGroup pssdConfiguration = - commonTestData.getPSSDConfigurationParametersGroup(false); - final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters( - CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, - pssdConfiguration, pHParameters); + final PssdConfigurationParametersGroup pssdConfiguration = + commonTestData.getPssdConfigurationParametersGroup(false); + final ReceptionHandlerParameters rHParameters = + new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, + CommonTestData.RECEPTION_HANDLER_CLASS_NAME, pssdConfiguration, pHParameters); rHParameters.validate(); fail("test should throw an exception here"); } catch (final Exception e) { @@ -148,16 +145,16 @@ public class TestReceptionHandlerParameters { @Test public void testReceptionHandlerParameters_InvalidReceptionHandlerClass() { final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false); - final PSSDConfigurationParametersGroup pssdConfiguration = - commonTestData.getPSSDConfigurationParametersGroup(false); + final PssdConfigurationParametersGroup pssdConfiguration = + commonTestData.getPssdConfigurationParametersGroup(false); final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid", pssdConfiguration, pHParameters); final GroupValidationResult validationResult = rHParameters.validate(); assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType()); - assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid", - rHParameters.getReceptionHandlerClassName()); - assertEquals(pssdConfiguration, rHParameters.getPSSDConfigurationParametersGroup()); + assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid", + rHParameters.getReceptionHandlerClassName()); + assertEquals(pssdConfiguration, rHParameters.getPssdConfigurationParametersGroup()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertFalse(validationResult.isValid()); assertTrue(validationResult.getResult().contains("reception handler class not found in classpath")); diff --git a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java index df585574..d02139f2 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java +++ b/main/src/test/java/org/onap/policy/distribution/main/rest/TestDistributionRestServer.java @@ -33,6 +33,8 @@ import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.junit.Test; import org.onap.policy.common.endpoints.report.HealthCheckReport; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.distribution.main.PolicyDistributionException; import org.onap.policy.distribution.main.parameters.CommonTestData; import org.onap.policy.distribution.main.parameters.RestServerParameters; @@ -45,6 +47,7 @@ import org.onap.policy.distribution.main.startstop.Main; */ public class TestDistributionRestServer { + private static final Logger LOGGER = FlexLogger.getLogger(TestDistributionRestServer.class); private static final String NOT_ALIVE = "not alive"; private static final String ALIVE = "alive"; private static final String SELF = "self"; @@ -83,7 +86,7 @@ public class TestDistributionRestServer { } private HealthCheckReport performHealthCheck() throws InterruptedException { - HealthCheckReport response; + HealthCheckReport response = null; final ClientConfig clientConfig = new ClientConfig(); final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34"); @@ -93,14 +96,13 @@ public class TestDistributionRestServer { final WebTarget webTarget = client.target("http://localhost:6969/healthcheck"); final Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON); - try { - response = invocationBuilder.get(HealthCheckReport.class); - } catch (final Exception exp) { - // may be the server is not started yet. Wait for couple of seconds and retry. - Thread.sleep(2000); - response = invocationBuilder.get(HealthCheckReport.class); + while (response == null) { + try { + response = invocationBuilder.get(HealthCheckReport.class); + } catch (final Exception exp) { + LOGGER.info("the server is not started yet. We will retry again"); + } } - return response; } diff --git a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java index 25133cfe..7cfb5ef3 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java +++ b/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java @@ -40,8 +40,8 @@ public class TestDistributionActivator { public void testDistributionActivator() throws PolicyDistributionException { final String[] distributionConfigParameters = { "-c", "parameters/DistributionConfigParameters.json" }; - final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments(); - arguments.parse(distributionConfigParameters); + final DistributionCommandLineArguments arguments = + new DistributionCommandLineArguments(distributionConfigParameters); final DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(arguments); 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 124f49a6..e1c5d22b 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 @@ -36,7 +36,8 @@ public class TestMain { @Test public void testMain() throws PolicyDistributionException { - final String[] distributionConfigParameters = { "-c", "parameters/DistributionConfigParameters.json" }; + final String[] distributionConfigParameters = + { "-c", "parameters/DistributionConfigParameters.json" }; final Main main = new Main(distributionConfigParameters); assertTrue(main.getParameters().isValid()); assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, main.getParameters().getName()); @@ -45,28 +46,31 @@ public class TestMain { @Test public void testMain_NoArguments() { - final String[] distributionConfigParameters = {}; + final String[] distributionConfigParameters = + {}; final Main main = new Main(distributionConfigParameters); assertTrue(main.getParameters() == null); } @Test public void testMain_InvalidArguments() { - final String[] distributionConfigParameters = { "parameters/DistributionConfigParameters.json" }; + final String[] distributionConfigParameters = + { "parameters/DistributionConfigParameters.json" }; final Main main = new Main(distributionConfigParameters); assertTrue(main.getParameters() == null); } @Test public void testMain_Help() { - final String[] distributionConfigParameters = { "-h" }; + final String[] distributionConfigParameters = + { "-h" }; Main.main(distributionConfigParameters); } @Test public void testMain_InvalidParameters() { final String[] distributionConfigParameters = - { "-c", "parameters/DistributionConfigParameters_InvalidName.json" }; + { "-c", "parameters/DistributionConfigParameters_InvalidName.json" }; final Main main = new Main(distributionConfigParameters); assertTrue(main.getParameters() == null); } -- cgit 1.2.3-korg