summaryrefslogtreecommitdiffstats
path: root/reception
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@ericsson.com>2018-08-23 13:50:31 +0100
committerramverma <ram.krishna.verma@ericsson.com>2018-08-24 10:04:31 +0100
commitef2ff6bae65870a4fccc25373c0cfae881e14a81 (patch)
tree2329de6759a3f74237b8a64dcbe63d7114f532ef /reception
parent55e6bdc93d05f1c9673a4ecbe133207722216eb0 (diff)
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 <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'reception')
-rw-r--r--reception/pom.xml9
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/decoding/PluginInitializationException.java51
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java15
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java6
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java20
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java8
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/PSSDConfigurationParametersGroup.java362
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java8
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/PssdConfigurationParametersGroup.java343
-rw-r--r--reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java10
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyInitializationExceptionTest.java50
-rw-r--r--reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java10
12 files changed, 486 insertions, 406 deletions
diff --git a/reception/pom.xml b/reception/pom.xml
index b0b07012..f8924036 100644
--- a/reception/pom.xml
+++ b/reception/pom.xml
@@ -44,13 +44,8 @@
</dependency>
<dependency>
<groupId>org.onap.policy.common</groupId>
- <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>
+ <artifactId>utils</artifactId>
+ <version>${policy.common.version}</version>
</dependency>
</dependencies>
</project>
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PluginInitializationException.java b/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PluginInitializationException.java
new file mode 100644
index 00000000..4dd36a7c
--- /dev/null
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PluginInitializationException.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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.decoding;
+
+/**
+ * This exception will be called if an error occurs while initializing distribution plugins.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class PluginInitializationException extends Exception {
+
+ private static final long serialVersionUID = 3809376274411309160L;
+
+ /**
+ * Construct an instance with the given message.
+ *
+ * @param message the error message
+ */
+ public PluginInitializationException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Construct an instance with the given message and cause.
+ *
+ * @param message the error message
+ * @param cause the cause
+ */
+ public PluginInitializationException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java b/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java
index 8306b630..2a07ec72 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/decoding/PolicyDecoder.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=========================================================
*/
@@ -21,6 +21,7 @@
package org.onap.policy.distribution.reception.decoding;
import java.util.Collection;
+
import org.onap.policy.distribution.model.Policy;
import org.onap.policy.distribution.model.PolicyInput;
@@ -34,15 +35,15 @@ public interface PolicyDecoder<S extends PolicyInput, T extends Policy> {
/**
* Can the decoder handle input of the specified type.
- *
+ *
* @param policyInput the type
- * @return <code>true</code if the decoder can handle the specified type
+ * @return <code>true</code> if the decoder can handle the specified type
*/
boolean canHandle(PolicyInput policyInput);
/**
- * Decode policies from the given input
- *
+ * Decode policies from the given input.
+ *
* @param input the input
* @return the generated policies
* @throws PolicyDecodingException if an error occurs during decoding
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java
index eeb1ead1..b189a2ab 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java
@@ -30,6 +30,7 @@ import org.onap.policy.distribution.forwarding.PolicyForwarder;
import org.onap.policy.distribution.forwarding.PolicyForwardingException;
import org.onap.policy.distribution.model.Policy;
import org.onap.policy.distribution.model.PolicyInput;
+import org.onap.policy.distribution.reception.decoding.PluginInitializationException;
import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
@@ -45,8 +46,11 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler {
private PluginHandler pluginHandler;
+ /**
+ * {@inheritDoc}
+ */
@Override
- public void initialize(final String parameterGroupName) throws PolicyDecodingException, PolicyForwardingException {
+ public void initialize(final String parameterGroupName) throws PluginInitializationException {
final ReceptionHandlerParameters receptionHandlerParameters =
(ReceptionHandlerParameters) ParameterService.get(parameterGroupName);
pluginHandler = new PluginHandler(receptionHandlerParameters.getPluginHandlerParameters().getName());
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java
index 37638b59..eb1a33a5 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java
@@ -28,12 +28,11 @@ 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;
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.PluginInitializationException;
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;
@@ -51,10 +50,9 @@ 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 exception if it occurs
- * @throws PolicyForwardingException exception if it occurs
+ * @throws PluginInitializationException exception if it occurs
*/
- public PluginHandler(final String parameterGroupName) throws PolicyDecodingException, PolicyForwardingException {
+ public PluginHandler(final String parameterGroupName) throws PluginInitializationException {
final PluginHandlerParameters params = (PluginHandlerParameters) ParameterService.get(parameterGroupName);
initializePolicyDecoders(params.getPolicyDecoders());
initializePolicyForwarders(params.getPolicyForwarders());
@@ -82,11 +80,11 @@ public class PluginHandler {
* Initialize policy decoders.
*
* @param policyDecoderParameters exception if it occurs
- * @throws PolicyDecodingException exception if it occurs
+ * @throws PluginInitializationException exception if it occurs
*/
@SuppressWarnings("unchecked")
private void initializePolicyDecoders(final Map<String, PolicyDecoderParameters> policyDecoderParameters)
- throws PolicyDecodingException {
+ throws PluginInitializationException {
policyDecoders = new ArrayList<>();
for (final PolicyDecoderParameters decoderParameters : policyDecoderParameters.values()) {
try {
@@ -97,7 +95,7 @@ public class PluginHandler {
policyDecoders.add(decoder);
} catch (final ClassNotFoundException | InstantiationException | IllegalAccessException exp) {
LOGGER.error("exception occured while initializing decoders", exp);
- throw new PolicyDecodingException(exp.getMessage(), exp.getCause());
+ throw new PluginInitializationException(exp.getMessage(), exp.getCause());
}
}
}
@@ -106,11 +104,11 @@ public class PluginHandler {
* Initialize policy forwarders.
*
* @param policyForwarderParameters exception if it occurs
- * @throws PolicyForwardingException exception if it occurs
+ * @throws PluginInitializationException exception if it occurs
*/
@SuppressWarnings("unchecked")
private void initializePolicyForwarders(final Map<String, PolicyForwarderParameters> policyForwarderParameters)
- throws PolicyForwardingException {
+ throws PluginInitializationException {
policyForwarders = new ArrayList<>();
for (final PolicyForwarderParameters forwarderParameters : policyForwarderParameters.values()) {
try {
@@ -119,7 +117,7 @@ public class PluginHandler {
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());
+ throw new PluginInitializationException(exp.getMessage(), exp.getCause());
}
}
}
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java
index 5f2e3716..5fcfb9c0 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/ReceptionHandler.java
@@ -20,8 +20,7 @@
package org.onap.policy.distribution.reception.handling;
-import org.onap.policy.distribution.forwarding.PolicyForwardingException;
-import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
+import org.onap.policy.distribution.reception.decoding.PluginInitializationException;
/**
* Handles input into Policy Distribution which may be decoded into a Policy.
@@ -32,10 +31,9 @@ public interface ReceptionHandler {
* 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 exception if it occurs
- * @throws PolicyForwardingException exception if it occurs
+ * @throws PluginInitializationException exception if it occurs
*/
- void initialize(String parameterGroupName) throws PolicyDecodingException, PolicyForwardingException;
+ void initialize(String parameterGroupName) throws PluginInitializationException;
/**
* Destroy the reception handler, removing any subscriptions and releasing all resources.
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PSSDConfigurationParametersGroup.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PSSDConfigurationParametersGroup.java
deleted file mode 100644
index 529cc9e4..00000000
--- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PSSDConfigurationParametersGroup.java
+++ /dev/null
@@ -1,362 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Intel. 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.parameters;
-
-import java.util.List;
-import java.util.UUID;
-
-import org.onap.policy.common.parameters.GroupValidationResult;
-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.
- private String name;
-
- // Interface of IConfiguration item
- private String asdcAddress;
- private List<String> messageBusAddress;
- private String user;
- private String password;
- private int pollingInterval;
- private int pollingTimeout;
- private String consumerId;
- private List<String> artifactTypes;
- private String consumerGroup;
- private String environmentName;
- private String keystorePath;
- private String keystorePassword;
- private boolean activeserverTlsAuth;
- private boolean isFilterinEmptyResources;
- private Boolean isUseHttpsWithDmaap;
-
- /**
- *Inner static class is to used as a Builder
- *
- */
- public static class PSSDConfigurationBuilder {
- private String asdcAddress;
- private List<String> messageBusAddress;
- private String user;
- private String password;
- private int pollingInterval;
- private int pollingTimeout;
- private String consumerId;
- private List<String> artifactTypes;
- private String consumerGroup;
- private String environmentName;
- private String keystorePath;
- private String keystorePassword;
- private boolean activeserverTlsAuth;
- private boolean isFilterinEmptyResources;
- private Boolean isUseHttpsWithDmaap;
-
- public PSSDConfigurationBuilder setAsdcAddress(String val) {
- asdcAddress = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setMessageBusAddress(List<String> val) {
- messageBusAddress = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setUser(String val) {
- user = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setPassword(String val) {
- password = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setPollingInterval(int val) {
- pollingInterval = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setPollingTimeout(int val) {
- pollingTimeout = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setConsumerId(String val) {
- consumerId = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setArtifactTypes(List<String> val) {
- artifactTypes = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setConsumerGroup(String val) {
- consumerGroup = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setEnvironmentName(String val) {
- environmentName = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setKeystorePath(String val) {
- keystorePath = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setKeystorePassword(String val) {
- keystorePassword = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setActiveserverTlsAuth(boolean val) {
- activeserverTlsAuth = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setIsFilterinEmptyResources(boolean val) {
- isFilterinEmptyResources = val;
- return this;
- }
-
- public PSSDConfigurationBuilder setIsUseHttpsWithDmaap(Boolean val) {
- isUseHttpsWithDmaap = val;
- return this;
- }
-
- /**
- * it is to create a new PSSDConfigurationParametersGroup instance.
- */
- public PSSDConfigurationParametersGroup build() {
- return new PSSDConfigurationParametersGroup(this);
- }
- }
-
- /**
- * The constructor for instantiating PSSDConfigurationParametersGroup it is a private
- * so that it could ONLY be instantiated by PSSDConfigurationBuilder
- *
- * @param builder stores all the values used by PSSDConfigurationParametersGroup
- */
- private PSSDConfigurationParametersGroup(PSSDConfigurationBuilder builder) {
- asdcAddress = builder.asdcAddress;
- messageBusAddress = builder.messageBusAddress;
- user = builder.user;
- password = builder.password;
- pollingInterval = builder.pollingInterval;
- pollingTimeout = builder.pollingTimeout;
- consumerId = builder.consumerId;
- artifactTypes = builder.artifactTypes;
- consumerGroup = builder.consumerGroup;
- environmentName = builder.environmentName;
- keystorePath = builder.keystorePath;
- keystorePassword = builder.keystorePassword;
- activeserverTlsAuth = builder.activeserverTlsAuth;
- isFilterinEmptyResources = builder.isFilterinEmptyResources;
- isUseHttpsWithDmaap = builder.isUseHttpsWithDmaap;
-
- }
-
- public String getAsdcAddress() {
- return asdcAddress;
- }
-
- public List<String> getMsgBusAddress() {
- return messageBusAddress;
- }
-
- public String getUser() {
- return user;
- }
-
- public String getPassword() {
- return password;
- }
-
- public int getPollingInterval() {
- return pollingInterval;
- }
-
- public int getPollingTimeout() {
- return pollingTimeout;
- }
-
- public String getConsumerID() {
- return consumerId;
- }
-
- public List<String> getArtifactTypes() {
- return artifactTypes;
- }
-
- public String getConsumerGroup() {
- return consumerGroup;
- }
-
- public String getEnvironmentName() {
- return environmentName;
- }
-
- public String getKeyStorePassword() {
- return keystorePassword;
- }
-
- public String getKeyStorePath() {
- return keystorePath;
- }
-
- public boolean activateServerTLSAuth() {
- return activeserverTlsAuth;
- }
-
- public boolean isFilterInEmptyResources() {
- return isFilterinEmptyResources;
- }
-
- public Boolean isUseHttpsWithDmaap() {
- return isUseHttpsWithDmaap;
- }
-
- /**
- * Return a string representation of the object
- *
- * @return textually represents this object
- */
- @Override
- public String toString() {
- return "name =" + name + ",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = "
- + messageBusAddress + ", user = " + user + "]";
- }
-
- /**
- * Return the name of this parameter group instance
- *
- * @return name the parameter group name
- */
- @Override
- public String getName() {
- return name ;
- }
-
- /**
- * Validate all the int Elements
- *
- */
- private void validateIntElement(final GroupValidationResult validationResult) {
- 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");
- }
- }
-
- /**
- * Validate all the String List Elements
- *
- */
- private void validateStringListElement(final GroupValidationResult validationResult) {
- 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");
- }
- }
- }
-
- 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");
- }
- }
- }
- }
-
- /**
- * Validate the parameter group
- * @return the result of the validation
- */
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult validationResult = new GroupValidationResult(this);
-
- if (asdcAddress == null || asdcAddress.trim().length() == 0) {
- validationResult.setResult("asdcAddress", ValidationStatus.INVALID,
- "asdcAddress must be a non-blank string");
- }
-
- if (user == null || user.trim().length() == 0) {
- validationResult.setResult("user", ValidationStatus.INVALID, "user must be a non-blank string");
- }
-
- if (consumerId == null || consumerId.trim().length() == 0) {
- validationResult.setResult("consumerId", ValidationStatus.INVALID, "consumerId must be a non-blank string");
- }
-
- if (consumerGroup == null || consumerGroup.trim().length() == 0) {
- 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");
- }
-
- if (keystorePassword == null || keystorePassword.trim().length() == 0) {
- validationResult.setResult("keystorePassword", ValidationStatus.INVALID,
- "keystorePassword must be a non-blank string");
- }
-
- validateIntElement(validationResult);
- validateStringListElement(validationResult);
- return validationResult;
- }
-
- /**
- * Set the name of this group.
- *
- * @param name the name to set.
- */
- public void setName(final String name) {
- this.name = name + "_" + UUID.randomUUID().toString();
- }
-}
-
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java
index 6157b8b6..2d60b85e 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java
@@ -67,14 +67,16 @@ public class PolicyDecoderParameters implements ParameterGroup {
return decoderClassName;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String getName() {
return null;
}
/**
- * Validate the policy decoder parameters.
- *
+ * {@inheritDoc}
*/
@Override
public GroupValidationResult validate() {
@@ -95,7 +97,7 @@ public class PolicyDecoderParameters implements ParameterGroup {
try {
Class.forName(decoderClassName);
} catch (final ClassNotFoundException exp) {
- LOGGER.error("policy decoder class not found in classpath", exp);
+ LOGGER.trace("policy decoder class not found in classpath", exp);
validationResult.setResult("decoderClassName", ValidationStatus.INVALID,
"policy decoder class not found in classpath");
}
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PssdConfigurationParametersGroup.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PssdConfigurationParametersGroup.java
new file mode 100644
index 00000000..93e3f628
--- /dev/null
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PssdConfigurationParametersGroup.java
@@ -0,0 +1,343 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Intel. 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.parameters;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+
+/**
+ * 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
+ private String asdcAddress;
+ private List<String> messageBusAddress;
+ private String user;
+ private String password;
+ private int pollingInterval;
+ private int pollingTimeout;
+ private String consumerId;
+ private List<String> artifactTypes;
+ private String consumerGroup;
+ private String environmentName;
+ private String keystorePath;
+ private String keystorePassword;
+ private boolean activeserverTlsAuth;
+ private boolean isFilterinEmptyResources;
+ private Boolean isUseHttpsWithDmaap;
+
+ /**
+ * Inner static class is to used as a Builder.
+ *
+ */
+ public static class PssdConfigurationBuilder {
+ private String asdcAddress;
+ private List<String> messageBusAddress;
+ private String user;
+ private String password;
+ private int pollingInterval;
+ private int pollingTimeout;
+ private String consumerId;
+ private List<String> artifactTypes;
+ private String consumerGroup;
+ private String environmentName;
+ private String keystorePath;
+ private String keystorePassword;
+ private boolean activeserverTlsAuth;
+ private boolean isFilterinEmptyResources;
+ private Boolean isUseHttpsWithDmaap;
+
+ public PssdConfigurationBuilder setAsdcAddress(final String val) {
+ asdcAddress = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setMessageBusAddress(final List<String> val) {
+ messageBusAddress = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setUser(final String val) {
+ user = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setPassword(final String val) {
+ password = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setPollingInterval(final int val) {
+ pollingInterval = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setPollingTimeout(final int val) {
+ pollingTimeout = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setConsumerId(final String val) {
+ consumerId = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setArtifactTypes(final List<String> val) {
+ artifactTypes = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setConsumerGroup(final String val) {
+ consumerGroup = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setEnvironmentName(final String val) {
+ environmentName = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setKeystorePath(final String val) {
+ keystorePath = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setKeystorePassword(final String val) {
+ keystorePassword = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setActiveserverTlsAuth(final boolean val) {
+ activeserverTlsAuth = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setIsFilterinEmptyResources(final boolean val) {
+ isFilterinEmptyResources = val;
+ return this;
+ }
+
+ public PssdConfigurationBuilder setIsUseHttpsWithDmaap(final Boolean val) {
+ isUseHttpsWithDmaap = val;
+ return this;
+ }
+
+ /**
+ * Creates a new PssdConfigurationParametersGroup instance.
+ */
+ public PssdConfigurationParametersGroup build() {
+ return new PssdConfigurationParametersGroup(this);
+ }
+ }
+
+ /**
+ * The constructor for instantiating PssdConfigurationParametersGroup. It is kept private so that it could only be
+ * called by PssdConfigurationBuilder.
+ *
+ * @param builder stores all the values used by PssdConfigurationParametersGroup
+ */
+ private PssdConfigurationParametersGroup(final PssdConfigurationBuilder builder) {
+ asdcAddress = builder.asdcAddress;
+ messageBusAddress = builder.messageBusAddress;
+ user = builder.user;
+ password = builder.password;
+ pollingInterval = builder.pollingInterval;
+ pollingTimeout = builder.pollingTimeout;
+ consumerId = builder.consumerId;
+ artifactTypes = builder.artifactTypes;
+ consumerGroup = builder.consumerGroup;
+ environmentName = builder.environmentName;
+ keystorePath = builder.keystorePath;
+ keystorePassword = builder.keystorePassword;
+ activeserverTlsAuth = builder.activeserverTlsAuth;
+ isFilterinEmptyResources = builder.isFilterinEmptyResources;
+ isUseHttpsWithDmaap = builder.isUseHttpsWithDmaap;
+
+ }
+
+ public String getAsdcAddress() {
+ return asdcAddress;
+ }
+
+ public List<String> getMsgBusAddress() {
+ return messageBusAddress;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public int getPollingInterval() {
+ return pollingInterval;
+ }
+
+ public int getPollingTimeout() {
+ return pollingTimeout;
+ }
+
+ public String getConsumerID() {
+ return consumerId;
+ }
+
+ public List<String> getArtifactTypes() {
+ return artifactTypes;
+ }
+
+ public String getConsumerGroup() {
+ return consumerGroup;
+ }
+
+ public String getEnvironmentName() {
+ return environmentName;
+ }
+
+ public String getKeyStorePassword() {
+ return keystorePassword;
+ }
+
+ public String getKeyStorePath() {
+ return keystorePath;
+ }
+
+ public boolean activateServerTLSAuth() {
+ return activeserverTlsAuth;
+ }
+
+ public boolean isFilterInEmptyResources() {
+ return isFilterinEmptyResources;
+ }
+
+ public Boolean isUseHttpsWithDmaap() {
+ return isUseHttpsWithDmaap;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ return "name =" + name + ",TestParameters:[asdcAddress = " + asdcAddress + ", messageBusAddress = "
+ + messageBusAddress + ", user = " + user + "]";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Set the name of this group.
+ *
+ * @param name the name to set.
+ */
+ public void setName(final String name) {
+ this.name = name + "_" + UUID.randomUUID().toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GroupValidationResult validate() {
+ final GroupValidationResult validationResult = new GroupValidationResult(this);
+ validateStringElement(validationResult, asdcAddress, "asdcAddress");
+ validateStringElement(validationResult, user, "user");
+ validateStringElement(validationResult, consumerId, "consumerId");
+ validateStringElement(validationResult, consumerGroup, "consumerGroup");
+ validateStringElement(validationResult, keystorePath, "keystorePath");
+ validateStringElement(validationResult, keystorePassword, "keystorePassword");
+ validateIntElement(validationResult, pollingInterval, "pollingInterval");
+ validateIntElement(validationResult, pollingTimeout, "pollingTimeout");
+ validateStringListElement(validationResult, messageBusAddress, "messageBusAddress");
+ validateStringListElement(validationResult, artifactTypes, "artifactTypes");
+ return validationResult;
+ }
+
+ /**
+ * Validate the integer Element.
+ *
+ * @param validationResult the result object
+ * @param element the element to validate
+ * @param elementName the element name for error message
+ */
+ private void validateIntElement(final GroupValidationResult validationResult, final int element,
+ final String elementName) {
+ if (!ParameterValidationUtils.validateIntParameter(element)) {
+ validationResult.setResult(elementName, ValidationStatus.INVALID,
+ elementName + " must be a positive integer");
+ }
+ }
+
+ /**
+ * Validate the String List Element.
+ *
+ * @param validationResult the result object
+ * @param element the element to validate
+ * @param elementName the element name for error message
+ */
+ private void validateStringListElement(final GroupValidationResult validationResult, final List<String> element,
+ final String elementName) {
+ if (element == null) {
+ validationResult.setResult(elementName, ValidationStatus.INVALID,
+ elementName + " must be a list of non-blank string");
+ } else {
+ for (final String temp : element) {
+ if (!ParameterValidationUtils.validateStringParameter(temp)) {
+ validationResult.setResult(elementName, ValidationStatus.INVALID,
+ "the string of " + elementName + "must be a non-blank string");
+ }
+ }
+ }
+ }
+
+ /**
+ * Validate the string element.
+ *
+ * @param validationResult the result object
+ * @param element the element to validate
+ * @param elementName the element name for error message
+ */
+ private void validateStringElement(final GroupValidationResult validationResult, final String element,
+ final String elementName) {
+ if (!ParameterValidationUtils.validateStringParameter(asdcAddress)) {
+ validationResult.setResult(elementName, ValidationStatus.INVALID,
+ elementName + " must be a non-blank string");
+ }
+ }
+}
+
diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java
index 93a02b3b..6464eeb6 100644
--- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java
+++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java
@@ -38,7 +38,7 @@ public class ReceptionHandlerParameters implements ParameterGroup {
private String name;
private String receptionHandlerType;
private String receptionHandlerClassName;
- private PSSDConfigurationParametersGroup pssdConfiguration;
+ private PssdConfigurationParametersGroup pssdConfiguration;
private PluginHandlerParameters pluginHandlerParameters;
/**
@@ -49,7 +49,7 @@ public class ReceptionHandlerParameters implements ParameterGroup {
* @param pluginHandlerParameters the plugin handler parameters
*/
public ReceptionHandlerParameters(final String receptionHandlerType, final String receptionHandlerClassName,
- final PSSDConfigurationParametersGroup pssdConfiguration,
+ final PssdConfigurationParametersGroup pssdConfiguration,
final PluginHandlerParameters pluginHandlerParameters) {
this.receptionHandlerType = receptionHandlerType;
this.receptionHandlerClassName = receptionHandlerClassName;
@@ -76,11 +76,11 @@ public class ReceptionHandlerParameters implements ParameterGroup {
}
/**
- * Return the PSSDConfigurationParametersGroup of this ReceptionHandlerParameters instance.
+ * Return the PssdConfigurationParametersGroup of this ReceptionHandlerParameters instance.
*
- * @return the PSSDConfigurationParametersGroup
+ * @return the PssdConfigurationParametersGroup
*/
- public PSSDConfigurationParametersGroup getPSSDConfigurationParametersGroup() {
+ public PssdConfigurationParametersGroup getPssdConfigurationParametersGroup() {
return pssdConfiguration;
}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyInitializationExceptionTest.java b/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyInitializationExceptionTest.java
new file mode 100644
index 00000000..bf327554
--- /dev/null
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/decoding/PolicyInitializationExceptionTest.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-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.decoding;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test of PluginInitializationException.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class PolicyInitializationExceptionTest {
+
+ @Test
+ public void testPolicyInitializationExceptionString() {
+ final PluginInitializationException policyInitializationException =
+ new PluginInitializationException("error message");
+ assertEquals("error message", policyInitializationException.getMessage());
+ }
+
+ @Test
+ public void testPolicyInitializationExceptionStringThrowable() {
+ final Exception cause = new IllegalArgumentException();
+ final PluginInitializationException policyInitializationException =
+ new PluginInitializationException("error message", cause);
+ assertEquals("error message", policyInitializationException.getMessage());
+ assertEquals(cause, policyInitializationException.getCause());
+ }
+
+}
diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java b/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java
index bb9b542a..83fe5a45 100644
--- a/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java
+++ b/reception/src/test/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandlerTest.java
@@ -33,10 +33,10 @@ 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.PluginInitializationException;
import org.onap.policy.distribution.reception.decoding.PolicyDecoder;
import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
@@ -60,7 +60,7 @@ public class AbstractReceptionHandlerTest {
@Test
public void testInputReceived() throws PolicyDecodingException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException, PolicyForwardingException {
+ IllegalArgumentException, IllegalAccessException, PluginInitializationException {
final AbstractReceptionHandler handler = new DummyReceptionHandler();
final Policy generatedPolicy1 = new DummyPolicy1();
@@ -96,7 +96,7 @@ public class AbstractReceptionHandlerTest {
@Test(expected = PolicyDecodingException.class)
public void testInputReceivedNoSupportingDecoder() throws PolicyDecodingException, NoSuchFieldException,
- SecurityException, IllegalArgumentException, IllegalAccessException, PolicyForwardingException {
+ SecurityException, IllegalArgumentException, IllegalAccessException, PluginInitializationException {
final AbstractReceptionHandler handler = new DummyReceptionHandler();
final PolicyDecoder<PolicyInput, Policy> policyDecoder = new DummyDecoder(false, Collections.emptyList());
@@ -108,7 +108,7 @@ public class AbstractReceptionHandlerTest {
@Test(expected = PolicyDecodingException.class)
public void testInputReceivedNoDecoder() throws PolicyDecodingException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException, PolicyForwardingException {
+ IllegalArgumentException, IllegalAccessException, PluginInitializationException {
final AbstractReceptionHandler handler = new DummyReceptionHandler();
final DummyPolicyForwarder policyForwarder = new DummyPolicyForwarder();
@@ -129,7 +129,7 @@ public class AbstractReceptionHandlerTest {
private void setUpPlugins(final AbstractReceptionHandler receptionHandler,
final Collection<PolicyDecoder<PolicyInput, Policy>> decoders, final Collection<PolicyForwarder> forwarders)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException,
- PolicyDecodingException, PolicyForwardingException {
+ PluginInitializationException {
final PluginHandlerParameters pluginParameters = getPluginHandlerParameters();
pluginParameters.setName(DISTRIBUTION_GROUP);
ParameterService.register(pluginParameters);