Adding termination code changes for distribution 35/60935/1
authorramverma <ram.krishna.verma@ericsson.com>
Thu, 16 Aug 2018 15:43:20 +0000 (16:43 +0100)
committerramverma <ram.krishna.verma@ericsson.com>
Thu, 16 Aug 2018 15:43:58 +0000 (16:43 +0100)
* Code changes for terminating the handlers started by
distribution activator.
* More test cases to increase coverage.
* Fixes for checkstyle issues.
* Fixes for sonar issues.

Change-Id: I3299317c83fa643ac1d0ba1105ac1a932c0a83f6
Issue-ID: POLICY-1035
Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
18 files changed:
.gitignore
forwarding/pom.xml
forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java
main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java
plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/pap/engine/XacmlPapServletPolicyForwarder.java
plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/PSSDConfiguration.java
plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/PSSDConfigurationParametersGroup.java
reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java
reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java
reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java
reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java
reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java
reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java
reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyDecodingExceptionTest.java
reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java
reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyDecoder.java [new file with mode: 0644]
reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyPolicyForwarder.java [new file with mode: 0644]
reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyReceptionHandler.java [new file with mode: 0644]

index f628051..7368565 100644 (file)
@@ -9,3 +9,5 @@ target
 .metadata/
 /bin/
 .log
+logs
+debug-logs
index 6a7b123..830f372 100644 (file)
             <artifactId>common-parameters</artifactId>
             <version>1.3.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.common</groupId>
+            <artifactId>ONAP-Logging</artifactId>
+            <version>1.3.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 </project>
index 3bde500..57d0424 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.onap.policy.distribution.forwarding.parameters;
 
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.common.parameters.GroupValidationResult;
 import org.onap.policy.common.parameters.ParameterGroup;
 import org.onap.policy.common.parameters.ValidationStatus;
@@ -30,6 +32,9 @@ import org.onap.policy.common.parameters.ValidationStatus;
  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
  */
 public class PolicyForwarderParameters implements ParameterGroup {
+
+    private static final Logger LOGGER = FlexLogger.getLogger(PolicyForwarderParameters.class);
+
     private String forwarderType;
     private String forwarderClassName;
 
@@ -89,7 +94,8 @@ public class PolicyForwarderParameters implements ParameterGroup {
     private void validatePolicyForwarderClass(final GroupValidationResult validationResult) {
         try {
             Class.forName(forwarderClassName);
-        } catch (final ClassNotFoundException e) {
+        } catch (final ClassNotFoundException exp) {
+            LOGGER.error("policy forwarder class not found in classpath", exp);
             validationResult.setResult("forwarderClassName", ValidationStatus.INVALID,
                     "policy forwarder class not found in classpath");
         }
index 43eb4f8..d360b5d 100644 (file)
@@ -20,6 +20,9 @@
 
 package org.onap.policy.distribution.main.startstop;
 
+import java.util.HashMap;
+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;
@@ -41,6 +44,9 @@ public class DistributionActivator {
     // The parameters of this policy distribution activator
     private final DistributionParameterGroup distributionParameterGroup;
 
+    // The map of reception handlers initialized by this distribution activator
+    private final Map<String, AbstractReceptionHandler> receptionHandlersMap = new HashMap<>();
+
     /**
      * Instantiate the activator for policy distribution as a complete service.
      *
@@ -66,6 +72,7 @@ public class DistributionActivator {
                         (Class<AbstractReceptionHandler>) Class.forName(rHParameters.getReceptionHandlerClassName());
                 final AbstractReceptionHandler receptionHandler = receptionHandlerClass.newInstance();
                 receptionHandler.initialize(rHParameters.getName());
+                receptionHandlersMap.put(rHParameters.getName(), receptionHandler);
             } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException
                     | PolicyDecodingException | PolicyForwardingException exp) {
                 throw new PolicyDistributionException(exp.getMessage(), exp);
@@ -80,8 +87,16 @@ public class DistributionActivator {
      * @throws PolicyDistributionException on termination errors
      */
     public void terminate() throws PolicyDistributionException {
-        // Shut down all handlers
-        deregisterToParameterService(distributionParameterGroup);
+        try {
+            for (final AbstractReceptionHandler handler : receptionHandlersMap.values()) {
+                handler.destroy();
+            }
+            receptionHandlersMap.clear();
+            deregisterToParameterService(distributionParameterGroup);
+        } catch (final Exception exp) {
+            LOGGER.error("Policy distribution service termination failed", exp);
+            throw new PolicyDistributionException(exp.getMessage(), exp);
+        }
     }
 
     /**
index 8691a3a..eb33a85 100644 (file)
@@ -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=========================================================
  */
 package org.onap.policy.distribution.forwarding.pap.engine;
 
 import java.util.Collection;
+
 import org.onap.policy.distribution.forwarding.PolicyForwarder;
 import org.onap.policy.distribution.model.Policy;
 
 /**
- * Forwards policies to the XACML PAP Servlet
+ * Forwards policies to the XACML PAP Servlet.
  */
 public class XacmlPapServletPolicyForwarder implements PolicyForwarder {
 
     @Override
-    public void forward(Collection<Policy> policies) {
+    public void forward(final Collection<Policy> policies) {
         // Send policies to PAP using common/policy-endpoints
     }
 
index 5f74e2b..86d2a55 100644 (file)
@@ -5,25 +5,23 @@
  * 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.distribution.reception.handling.sdc;
 
-import java.io.File;
-import java.util.ArrayList;
 import java.util.List;
-import java.util.Properties;
+
 import org.onap.sdc.api.consumer.IConfiguration;
 
 /**
@@ -35,14 +33,14 @@ public class PSSDConfiguration implements IConfiguration {
     // Configuration file structure
 
     // Configuration file properties
-    private PSSDConfigurationParametersGroup configParameters=null;
+    private PSSDConfigurationParametersGroup configParameters = null;
 
     /**
      * Original constructor
      *
      * @param configParameters properties needed to be configured for the model loader
      */
-    public PSSDConfiguration(PSSDConfigurationParametersGroup configParameters) {
+    public PSSDConfiguration(final PSSDConfigurationParametersGroup configParameters) {
         this.configParameters = configParameters;
 
     }
index da60335..7fa8114 100644 (file)
@@ -5,40 +5,36 @@
  * 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.distribution.reception.handling.sdc;
-import java.util.List;
-import java.io.FileReader;
-import java.io.IOException;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
+import java.util.List;
 
 import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterConstants;
 import org.onap.policy.common.parameters.ParameterGroup;
 import org.onap.policy.common.parameters.ValidationStatus;
 
 /**
-* This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json 
-* format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
-*/
-public class  PSSDConfigurationParametersGroup implements ParameterGroup {
-    //Policy SDC Service Distribution specified field.
+ * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json
+ * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
+ */
+public class PSSDConfigurationParametersGroup implements ParameterGroup {
+    // Policy SDC Service Distribution specified field.
     private String name;
-    
-    //Interface of IConfiguration item
+
+    // Interface of IConfiguration item
     private String asdcAddress;
     private List<String> messageBusAddress;
     private String user;
@@ -55,11 +51,11 @@ public class  PSSDConfigurationParametersGroup implements ParameterGroup {
     private boolean isFilterinEmptyResources;
     private Boolean isUseHttpsWithDmaap;
 
-    public String getAsdcAddress(){
+    public String getAsdcAddress() {
         return asdcAddress;
     }
 
-    public List<String> getMsgBusAddress(){
+    public List<String> getMsgBusAddress() {
         return messageBusAddress;
     }
 
@@ -74,7 +70,7 @@ public class  PSSDConfigurationParametersGroup implements ParameterGroup {
     public int getPollingInterval() {
         return pollingInterval;
     }
-    
+
     public int getPollingTimeout() {
         return pollingTimeout;
     }
@@ -83,7 +79,7 @@ public class  PSSDConfigurationParametersGroup implements ParameterGroup {
         return consumerId;
     }
 
-    public List<String> getArtifactTypes(){
+    public List<String> getArtifactTypes() {
         return artifactTypes;
     }
 
@@ -117,8 +113,8 @@ public class  PSSDConfigurationParametersGroup implements ParameterGroup {
 
     @Override
     public String toString() {
-        return "name =" + name +",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = " + messageBusAddress + 
-                ", user = "+ user + "]";
+        return "name =" + name + ",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = "
+                + messageBusAddress + ", user = " + user + "]";
     }
 
     @Override
@@ -128,14 +124,15 @@ public class  PSSDConfigurationParametersGroup implements ParameterGroup {
 
     @Override
     public GroupValidationResult validate() {
-        GroupValidationResult validationResult = new GroupValidationResult(this);
+        final GroupValidationResult validationResult = new GroupValidationResult(this);
 
         if (name == null || name.trim().length() == 0) {
             validationResult.setResult("name", ValidationStatus.INVALID, "name must be a non-blank string");
         }
 
         if (asdcAddress == null || asdcAddress.trim().length() == 0) {
-            validationResult.setResult("asdcAddress", ValidationStatus.INVALID, "asdcAddress must be a non-blank string");
+            validationResult.setResult("asdcAddress", ValidationStatus.INVALID,
+                    "asdcAddress must be a non-blank string");
         }
 
         if (user == null || user.trim().length() == 0) {
@@ -147,49 +144,52 @@ public class  PSSDConfigurationParametersGroup implements ParameterGroup {
         }
 
         if (consumerGroup == null || consumerGroup.trim().length() == 0) {
-            validationResult.setResult("consumerGroup", ValidationStatus.INVALID, "consumerGroup must be a non-blank string");
+            validationResult.setResult("consumerGroup", ValidationStatus.INVALID,
+                    "consumerGroup must be a non-blank string");
         }
 
         if (keystorePath == null || keystorePath.trim().length() == 0) {
-            validationResult.setResult("keystorePath", ValidationStatus.INVALID, "keystorePath must be a non-blank string");
+            validationResult.setResult("keystorePath", ValidationStatus.INVALID,
+                    "keystorePath must be a non-blank string");
         }
 
         if (keystorePassword == null || keystorePassword.trim().length() == 0) {
-            validationResult.setResult("keystorePassword", ValidationStatus.INVALID, "keystorePassword must be a non-blank string");
+            validationResult.setResult("keystorePassword", ValidationStatus.INVALID,
+                    "keystorePassword must be a non-blank string");
         }
 
-        if(messageBusAddress == null){
-            validationResult.setResult("messageBusAddress", ValidationStatus.INVALID, 
-                "messageBusAddress must be a list of non-blank string");
-        }else {
-            for(String temp:messageBusAddress){
-                if(temp.trim().length() == 0){
+        if (messageBusAddress == null) {
+            validationResult.setResult("messageBusAddress", ValidationStatus.INVALID,
+                    "messageBusAddress must be a list of non-blank string");
+        } else {
+            for (final String temp : messageBusAddress) {
+                if (temp.trim().length() == 0) {
                     validationResult.setResult("messageBusAddress", ValidationStatus.INVALID,
-                        "the string of messageBusAddress must be a non-blank string");
+                            "the string of messageBusAddress must be a non-blank string");
                 }
             }
         }
 
-        if(artifactTypes == null){
-            validationResult.setResult("artifactTypes", ValidationStatus.INVALID, 
-                "artifactTypes must be a list of non-blank string");
-        }else {
-            for(String temp:artifactTypes){
-                if(temp.trim().length() == 0){
+        if (artifactTypes == null) {
+            validationResult.setResult("artifactTypes", ValidationStatus.INVALID,
+                    "artifactTypes must be a list of non-blank string");
+        } else {
+            for (final String temp : artifactTypes) {
+                if (temp.trim().length() == 0) {
                     validationResult.setResult("artifactTypes", ValidationStatus.INVALID,
-                        "the string of artifactTypes must be a non-blank string");
+                            "the string of artifactTypes must be a non-blank string");
                 }
             }
         }
 
-        if (pollingInterval <= 0){
-            validationResult.setResult("pollingInterval", ValidationStatus.INVALID, 
-                "pollingInterval must be a positive integer");
+        if (pollingInterval <= 0) {
+            validationResult.setResult("pollingInterval", ValidationStatus.INVALID,
+                    "pollingInterval must be a positive integer");
         }
 
-        if (pollingTimeout <= 0){
-            validationResult.setResult("pollingTimeout", ValidationStatus.INVALID, 
-                "pollingTimeout must be a positive integer");
+        if (pollingTimeout <= 0) {
+            validationResult.setResult("pollingTimeout", ValidationStatus.INVALID,
+                    "pollingTimeout must be a positive integer");
         }
 
         return validationResult;
index 94bcc65..eeb1ead 100644 (file)
@@ -34,10 +34,10 @@ import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
 import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
 
-/***
+/**
  * Base implementation of {@link ReceptionHandler}. All reception handlers should extend this base class by implementing
  * the {@link #initializeReception(String)} method to perform the specific initialization required to receive inputs and
- * by invoking {@link #inputReceived(PolicyInput)} when the reception handler receives input
+ * by invoking {@link #inputReceived(PolicyInput)} when the reception handler receives input.
  */
 public abstract class AbstractReceptionHandler implements ReceptionHandler {
 
@@ -55,7 +55,7 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler {
 
     /**
      * Sub classes must implement this method to perform the specific initialization required to receive inputs, for
-     * example setting up subscriptions
+     * example setting up subscriptions.
      *
      * @param parameterGroupName the parameter group name
      */
index 7afc581..37638b5 100644 (file)
@@ -24,6 +24,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 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.PolicyForwarder;
 import org.onap.policy.distribution.forwarding.PolicyForwardingException;
@@ -40,6 +42,8 @@ import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters
  */
 public class PluginHandler {
 
+    private static final Logger LOGGER = FlexLogger.getLogger(PluginHandler.class);
+
     private Collection<PolicyDecoder<PolicyInput, Policy>> policyDecoders;
     private Collection<PolicyForwarder> policyForwarders;
 
@@ -47,8 +51,8 @@ public class PluginHandler {
      * Create an instance to instantiate plugins based on the given parameter group.
      *
      * @param parameterGroupName the name of the parameter group
-     * @throws PolicyDecodingException
-     * @throws PolicyForwardingException
+     * @throws PolicyDecodingException exception if it occurs
+     * @throws PolicyForwardingException exception if it occurs
      */
     public PluginHandler(final String parameterGroupName) throws PolicyDecodingException, PolicyForwardingException {
         final PluginHandlerParameters params = (PluginHandlerParameters) ParameterService.get(parameterGroupName);
@@ -77,41 +81,44 @@ public class PluginHandler {
     /**
      * Initialize policy decoders.
      *
-     * @param policyDecoderParameters
-     * @throws PolicyDecodingException
+     * @param policyDecoderParameters exception if it occurs
+     * @throws PolicyDecodingException exception if it occurs
      */
     @SuppressWarnings("unchecked")
     private void initializePolicyDecoders(final Map<String, PolicyDecoderParameters> policyDecoderParameters)
             throws PolicyDecodingException {
-        policyDecoders = new ArrayList<PolicyDecoder<PolicyInput, Policy>>();
-        for (final PolicyDecoderParameters pDParameters : policyDecoderParameters.values()) {
+        policyDecoders = new ArrayList<>();
+        for (final PolicyDecoderParameters decoderParameters : policyDecoderParameters.values()) {
             try {
                 final Class<PolicyDecoder<PolicyInput, Policy>> policyDecoderClass =
-                        (Class<PolicyDecoder<PolicyInput, Policy>>) Class.forName(pDParameters.getDecoderClassName());
+                        (Class<PolicyDecoder<PolicyInput, Policy>>) Class
+                                .forName(decoderParameters.getDecoderClassName());
                 final PolicyDecoder<PolicyInput, Policy> decoder = policyDecoderClass.newInstance();
                 policyDecoders.add(decoder);
             } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException exp) {
-                throw new PolicyDecodingException(exp.getMessage());
+                LOGGER.error("exception occured while initializing decoders", exp);
+                throw new PolicyDecodingException(exp.getMessage(), exp.getCause());
             }
         }
     }
 
     /**
-     * Initialize policy forwarders
+     * Initialize policy forwarders.
      *
-     * @param policyForwarderParameters
-     * @throws PolicyForwardingException
+     * @param policyForwarderParameters exception if it occurs
+     * @throws PolicyForwardingException exception if it occurs
      */
     @SuppressWarnings("unchecked")
     private void initializePolicyForwarders(final Map<String, PolicyForwarderParameters> policyForwarderParameters)
             throws PolicyForwardingException {
-        policyForwarders = new ArrayList<PolicyForwarder>();
-        for (final PolicyForwarderParameters pFParameters : policyForwarderParameters.values()) {
+        policyForwarders = new ArrayList<>();
+        for (final PolicyForwarderParameters forwarderParameters : policyForwarderParameters.values()) {
             try {
                 final Class<PolicyForwarder> policyForwarderClass =
-                        (Class<PolicyForwarder>) Class.forName(pFParameters.getForwarderClassName());
+                        (Class<PolicyForwarder>) Class.forName(forwarderParameters.getForwarderClassName());
                 policyForwarders.add(policyForwarderClass.newInstance());
             } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException exp) {
+                LOGGER.error("exception occured while initializing forwarders", exp);
                 throw new PolicyForwardingException(exp.getMessage(), exp.getCause());
             }
         }
index c3a7544..5f2e371 100644 (file)
@@ -29,16 +29,16 @@ import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
 public interface ReceptionHandler {
 
     /**
-     * Initialize the reception handler with the given parameters
+     * Initialize the reception handler with the given parameters.
      *
      * @param parameterGroupName the name of the parameter group containing the configuration for the reception handler
-     * @throws PolicyDecodingException
-     * @throws PolicyForwardingException
+     * @throws PolicyDecodingException exception if it occurs
+     * @throws PolicyForwardingException exception if it occurs
      */
     void initialize(String parameterGroupName) throws PolicyDecodingException, PolicyForwardingException;
 
     /**
-     * Destroy the reception handler, removing any subscriptions and releasing all resources
+     * Destroy the reception handler, removing any subscriptions and releasing all resources.
      */
     void destroy();
 
index 7e16518..c752020 100644 (file)
@@ -105,7 +105,9 @@ public class PluginHandlerParameters implements ParameterGroup {
     }
 
     /**
-     * @param name the name to set
+     * Set the name of this group.
+     *
+     * @param name the name to set.
      */
     public void setName(final String name) {
         this.name = name;
index 59c59e1..6157b8b 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.onap.policy.distribution.reception.parameters;
 
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.common.parameters.GroupValidationResult;
 import org.onap.policy.common.parameters.ParameterGroup;
 import org.onap.policy.common.parameters.ValidationStatus;
@@ -30,6 +32,9 @@ import org.onap.policy.common.parameters.ValidationStatus;
  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
  */
 public class PolicyDecoderParameters implements ParameterGroup {
+
+    private static final Logger LOGGER = FlexLogger.getLogger(PolicyDecoderParameters.class);
+
     private String decoderType;
     private String decoderClassName;
 
@@ -89,7 +94,8 @@ public class PolicyDecoderParameters implements ParameterGroup {
     private void validatePolicyDecoderClass(final GroupValidationResult validationResult) {
         try {
             Class.forName(decoderClassName);
-        } catch (final ClassNotFoundException e) {
+        } catch (final ClassNotFoundException exp) {
+            LOGGER.error("policy decoder class not found in classpath", exp);
             validationResult.setResult("decoderClassName", ValidationStatus.INVALID,
                     "policy decoder class not found in classpath");
         }
index 54979ab..974436a 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.onap.policy.distribution.reception.parameters;
 
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.common.parameters.GroupValidationResult;
 import org.onap.policy.common.parameters.ParameterGroup;
 import org.onap.policy.common.parameters.ValidationStatus;
@@ -30,6 +32,9 @@ import org.onap.policy.common.parameters.ValidationStatus;
  * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
  */
 public class ReceptionHandlerParameters implements ParameterGroup {
+
+    private static final Logger LOGGER = FlexLogger.getLogger(ReceptionHandlerParameters.class);
+
     private String name;
     private String receptionHandlerType;
     private String receptionHandlerClassName;
@@ -109,13 +114,16 @@ public class ReceptionHandlerParameters implements ParameterGroup {
     private void validateReceptionHandlerClass(final GroupValidationResult validationResult) {
         try {
             Class.forName(receptionHandlerClassName);
-        } catch (final ClassNotFoundException e) {
+        } catch (final ClassNotFoundException exp) {
+            LOGGER.error("reception handler class not found in classpath", exp);
             validationResult.setResult("receptionHandlerClassName", ValidationStatus.INVALID,
                     "reception handler class not found in classpath");
         }
     }
 
     /**
+     * Set the name of this group.
+     *
      * @param name the name to set
      */
     public void setName(final String name) {
index eba1950..a5bc072 100644 (file)
@@ -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=========================================================
  */
 package org.onap.policy.distribution.reception.decoding;
 
 import static org.junit.Assert.assertEquals;
+
 import org.junit.Test;
 
 public class PolicyDecodingExceptionTest {
 
     @Test
     public void testPolicyDecodingExceptionString() {
-        PolicyDecodingException policyDecodingException = new PolicyDecodingException("error message");
+        final PolicyDecodingException policyDecodingException = new PolicyDecodingException("error message");
         assertEquals("error message", policyDecodingException.getMessage());
     }
 
     @Test
     public void testPolicyDecodingExceptionStringThrowable() {
-        Exception cause = new IllegalArgumentException();
-        PolicyDecodingException policyDecodingException = new PolicyDecodingException("error message", cause);
+        final Exception cause = new IllegalArgumentException();
+        final PolicyDecodingException policyDecodingException = new PolicyDecodingException("error message", cause);
         assertEquals("error message", policyDecodingException.getMessage());
         assertEquals(cause, policyDecodingException.getCause());
     }
index 7f9bb40..bb9b542 100644 (file)
@@ -27,19 +27,38 @@ import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
+import org.junit.Test;
+import org.onap.policy.common.parameters.ParameterService;
 import org.onap.policy.distribution.forwarding.PolicyForwarder;
 import org.onap.policy.distribution.forwarding.PolicyForwardingException;
+import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
 import org.onap.policy.distribution.model.Policy;
 import org.onap.policy.distribution.model.PolicyInput;
 import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
 import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
+import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
+import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters;
 
+/**
+ * Class to perform unit test of AbstractReceptionHandler.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
 public class AbstractReceptionHandlerTest {
 
-    // These tests won't work any more because we use Parameter Service for starting the plugins.
-    // Will rewrite them while implementing AbstractReceptionHandler.inputRecieved() method.
-    // @Test
+    private static final String DISTRIBUTION_GROUP = "DummyDistributionGroup";
+    private static final String DECODER_TYPE = "DummyDecoder";
+    private static final String DECODER_CLASS_NAME = "org.onap.policy.distribution.reception.handling.DummyDecoder";
+    private static final String DECODER_KEY = "DummyDecoderKey";
+    private static final String FORWARDER_KEY = "DummyForwarderKey";
+    private static final String FORWARDER_TYPE = "DummyForwarder";
+    private static final String FORWARDER_CLASS_NAME =
+            "org.onap.policy.distribution.reception.handling.DummyPolicyForwarder";
+
+    @Test
     public void testInputReceived() throws PolicyDecodingException, NoSuchFieldException, SecurityException,
             IllegalArgumentException, IllegalAccessException, PolicyForwardingException {
         final AbstractReceptionHandler handler = new DummyReceptionHandler();
@@ -75,7 +94,7 @@ public class AbstractReceptionHandlerTest {
         assertTrue(policyForwarder2.receivedPolicy(generatedPolicy2));
     }
 
-    // @Test(expected = PolicyDecodingException.class)
+    @Test(expected = PolicyDecodingException.class)
     public void testInputReceivedNoSupportingDecoder() throws PolicyDecodingException, NoSuchFieldException,
             SecurityException, IllegalArgumentException, IllegalAccessException, PolicyForwardingException {
         final AbstractReceptionHandler handler = new DummyReceptionHandler();
@@ -87,7 +106,7 @@ public class AbstractReceptionHandlerTest {
         handler.inputReceived(new DummyPolicyInput());
     }
 
-    // @Test(expected = PolicyDecodingException.class)
+    @Test(expected = PolicyDecodingException.class)
     public void testInputReceivedNoDecoder() throws PolicyDecodingException, NoSuchFieldException, SecurityException,
             IllegalArgumentException, IllegalAccessException, PolicyForwardingException {
         final AbstractReceptionHandler handler = new DummyReceptionHandler();
@@ -98,72 +117,23 @@ public class AbstractReceptionHandlerTest {
         handler.inputReceived(new DummyPolicyInput());
     }
 
-    class DummyReceptionHandler extends AbstractReceptionHandler {
-        @Override
-        protected void initializeReception(final String parameterGroupName) {}
-
-        @Override
-        public void destroy() {}
-    }
-
     class DummyPolicyInput implements PolicyInput {
     }
-    class DummyPolicy1 implements Policy {
-    }
-    class DummyPolicy2 implements Policy {
-    }
-
-    public class DummyDecoder implements PolicyDecoder<PolicyInput, Policy> {
-
-        private boolean canHandleValue;
-        private Collection<Policy> policesToReturn;
-
-        public DummyDecoder(final boolean canHandleValue, final Collection<Policy> policesToReturn) {
-            this.canHandleValue = canHandleValue;
-            this.policesToReturn = policesToReturn;
-        }
 
-        @Override
-        public boolean canHandle(final PolicyInput policyInput) {
-            return canHandleValue;
-        }
-
-        @Override
-        public Collection<Policy> decode(final PolicyInput input) throws PolicyDecodingException {
-            return policesToReturn;
-        }
+    class DummyPolicy1 implements Policy {
     }
 
-    public class DummyPolicyForwarder implements PolicyForwarder {
-        private int numberOfPoliciesReceived = 0;
-        private Collection<Policy> policiesReceived = new ArrayList<>();
-
-        @Override
-        public void forward(final Collection<Policy> policies) throws PolicyForwardingException {
-            numberOfPoliciesReceived += policies.size();
-            policiesReceived.addAll(policies);
-        }
-
-        public int getNumberOfPoliciesReceived() {
-            return numberOfPoliciesReceived;
-        }
-
-        public boolean receivedPolicy(final Policy policy) {
-            return policiesReceived.contains(policy);
-        }
+    class DummyPolicy2 implements Policy {
     }
 
-    /**
-     * Only needed until code is added for instantiating plugins from paramater file
-     *
-     * @throws PolicyForwardingException
-     * @throws PolicyDecodingException
-     */
     private void setUpPlugins(final AbstractReceptionHandler receptionHandler,
             final Collection<PolicyDecoder<PolicyInput, Policy>> decoders, final Collection<PolicyForwarder> forwarders)
             throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException,
             PolicyDecodingException, PolicyForwardingException {
-        final PluginHandler pluginHandler = new PluginHandler("");
+        final PluginHandlerParameters pluginParameters = getPluginHandlerParameters();
+        pluginParameters.setName(DISTRIBUTION_GROUP);
+        ParameterService.register(pluginParameters);
+        final PluginHandler pluginHandler = new PluginHandler(pluginParameters.getName());
 
         final Field decodersField = pluginHandler.getClass().getDeclaredField("policyDecoders");
         decodersField.setAccessible(true);
@@ -176,6 +146,31 @@ public class AbstractReceptionHandlerTest {
         final Field pluginHandlerField = AbstractReceptionHandler.class.getDeclaredField("pluginHandler");
         pluginHandlerField.setAccessible(true);
         pluginHandlerField.set(receptionHandler, pluginHandler);
+        ParameterService.deregister(pluginParameters.getName());
+    }
+
+    private Map<String, PolicyDecoderParameters> getPolicyDecoders() {
+        final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<String, PolicyDecoderParameters>();
+        final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(DECODER_TYPE, DECODER_CLASS_NAME);
+        policyDecoders.put(DECODER_KEY, pDParameters);
+        return policyDecoders;
+    }
+
+    private Map<String, PolicyForwarderParameters> getPolicyForwarders() {
+        final Map<String, PolicyForwarderParameters> policyForwarders =
+                new HashMap<String, PolicyForwarderParameters>();
+        final PolicyForwarderParameters pFParameters =
+                new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME);
+        policyForwarders.put(FORWARDER_KEY, pFParameters);
+        return policyForwarders;
+    }
+
+    private PluginHandlerParameters getPluginHandlerParameters() {
+        final Map<String, PolicyDecoderParameters> policyDecoders = getPolicyDecoders();
+        final Map<String, PolicyForwarderParameters> policyForwarders = getPolicyForwarders();
+        final PluginHandlerParameters pluginHandlerParameters =
+                new PluginHandlerParameters(policyDecoders, policyForwarders);
+        return pluginHandlerParameters;
     }
 
 }
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyDecoder.java b/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyDecoder.java
new file mode 100644 (file)
index 0000000..2de1737
--- /dev/null
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2018 Ericsson. 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.distribution.reception.handling;
+
+import java.util.Collection;
+
+import org.onap.policy.distribution.model.Policy;
+import org.onap.policy.distribution.model.PolicyInput;
+import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
+import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
+
+/**
+ * Class to create a dummy decoder for test cases in AbstractReceptionHandlerTest.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class DummyDecoder implements PolicyDecoder<PolicyInput, Policy> {
+
+    private boolean canHandleValue;
+    private Collection<Policy> policesToReturn;
+
+    public DummyDecoder() {
+        this.canHandleValue = false;
+        this.policesToReturn = null;
+    }
+
+    public DummyDecoder(final boolean canHandleValue, final Collection<Policy> policesToReturn) {
+        this.canHandleValue = canHandleValue;
+        this.policesToReturn = policesToReturn;
+    }
+
+    @Override
+    public boolean canHandle(final PolicyInput policyInput) {
+        return canHandleValue;
+    }
+
+    @Override
+    public Collection<Policy> decode(final PolicyInput input) throws PolicyDecodingException {
+        return policesToReturn;
+    }
+}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyPolicyForwarder.java b/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyPolicyForwarder.java
new file mode 100644 (file)
index 0000000..acee469
--- /dev/null
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2018 Ericsson. 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.distribution.reception.handling;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.onap.policy.distribution.forwarding.PolicyForwarder;
+import org.onap.policy.distribution.forwarding.PolicyForwardingException;
+import org.onap.policy.distribution.model.Policy;
+
+/**
+ * Class to create a dummy forwarder for test cases in AbstractReceptionHandlerTest.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class DummyPolicyForwarder implements PolicyForwarder {
+    private int numberOfPoliciesReceived = 0;
+    private Collection<Policy> policiesReceived = new ArrayList<>();
+
+    @Override
+    public void forward(final Collection<Policy> policies) throws PolicyForwardingException {
+        numberOfPoliciesReceived += policies.size();
+        policiesReceived.addAll(policies);
+    }
+
+    public int getNumberOfPoliciesReceived() {
+        return numberOfPoliciesReceived;
+    }
+
+    public boolean receivedPolicy(final Policy policy) {
+        return policiesReceived.contains(policy);
+    }
+}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyReceptionHandler.java b/reception/src/test/java/org/onap/policy/distribution/reception/handling/DummyReceptionHandler.java
new file mode 100644 (file)
index 0000000..43596ff
--- /dev/null
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2018 Ericsson. 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.distribution.reception.handling;
+
+/**
+ * Class to create a dummy reception handler for test cases in AbstractReceptionHandlerTest.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+class DummyReceptionHandler extends AbstractReceptionHandler {
+
+    @Override
+    protected void initializeReception(final String parameterGroupName) {}
+
+    @Override
+    public void destroy() {}
+}