summaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java38
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java8
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParameterGroup.java43
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParametersJsonAdapter.java80
-rw-r--r--main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java17
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java29
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java39
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java90
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java1
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java35
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java7
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarder.java4
-rw-r--r--main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarderParameterGroup.java131
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters.json16
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters_EmptyPolicyDecoder.json16
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters_EmptyPolicyForwarder.json13
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandler.json13
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json22
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters_InvalidForwarderConfigurationClassName.json67
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters_InvalidName.json16
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json16
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters_InvalidRestServerParameters.json16
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters_NoPolicyDecoder.json16
-rw-r--r--main/src/test/resources/parameters/DistributionConfigParameters_UnknownForwarderConfigurationClassName.json67
-rw-r--r--main/src/test/resources/parameters/MinimumParameters.json16
25 files changed, 733 insertions, 83 deletions
diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java
index a188fb04..27291255 100644
--- a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java
+++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java
@@ -20,9 +20,9 @@
package org.onap.policy.distribution.main.parameters;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
-
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.parameters.ValidationStatus;
@@ -38,6 +38,9 @@ public class DistributionParameterGroup implements ParameterGroup {
private String name;
private RestServerParameters restServerParameters;
private Map<String, ReceptionHandlerParameters> receptionHandlerParameters;
+ private Map<String, PolicyForwarderConfigurationParameterGroup> policyForwarderConfigurationParameters =
+ new LinkedHashMap<>();
+
/**
* Create the distribution parameter group.
@@ -45,10 +48,12 @@ public class DistributionParameterGroup implements ParameterGroup {
* @param name the parameter group name
*/
public DistributionParameterGroup(final String name, final RestServerParameters restServerParameters,
- final Map<String, ReceptionHandlerParameters> receptionHandlerParameters) {
+ final Map<String, ReceptionHandlerParameters> receptionHandlerParameters,
+ final Map<String, PolicyForwarderConfigurationParameterGroup> policyForwarderConfigurationParameters) {
this.name = name;
this.restServerParameters = restServerParameters;
this.receptionHandlerParameters = receptionHandlerParameters;
+ this.policyForwarderConfigurationParameters = policyForwarderConfigurationParameters;
}
/**
@@ -89,6 +94,26 @@ public class DistributionParameterGroup implements ParameterGroup {
return restServerParameters;
}
+
+ /**
+ * Gets the policy forwarder configuration parameter map.
+ *
+ * @return the policy forwarder configuration parameter map
+ */
+ public Map<String, PolicyForwarderConfigurationParameterGroup> getPolicyForwarderConfigurationParameters() {
+ return policyForwarderConfigurationParameters;
+ }
+
+ /**
+ * Sets the policy forwarder configuration parameter map.
+ *
+ * @param eventInputParameters the policy forwarder configuration parameters
+ */
+ public void setPolicyForwarderConfigurationParameters(
+ final Map<String, PolicyForwarderConfigurationParameterGroup> policyForwarderConfigurationParameters) {
+ this.policyForwarderConfigurationParameters = policyForwarderConfigurationParameters;
+ }
+
/**
* Validate the parameter group.
*
@@ -107,6 +132,7 @@ public class DistributionParameterGroup implements ParameterGroup {
validationResult.setResult("restServerParameters", restServerParameters.validate());
}
validateReceptionHandlers(validationResult);
+ validateForwarderConfigurations(validationResult);
return validationResult;
}
@@ -126,4 +152,12 @@ public class DistributionParameterGroup implements ParameterGroup {
}
}
}
+
+ private void validateForwarderConfigurations(final GroupValidationResult validationResult) {
+ for (final Entry<String, PolicyForwarderConfigurationParameterGroup> configurationParameters : policyForwarderConfigurationParameters
+ .entrySet()) {
+ validationResult.setResult("policyForwarderConfigurationParameters", configurationParameters.getKey(),
+ configurationParameters.getValue().validate());
+ }
+ }
}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java
index 3174b8c6..5cc507e6 100644
--- a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java
+++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java
@@ -22,9 +22,7 @@ package org.onap.policy.distribution.main.parameters;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-
import java.io.FileReader;
-
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.common.parameters.GroupValidationResult;
@@ -32,7 +30,8 @@ import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments;
/**
- * This class handles reading, parsing and validating of policy distribution parameters from JSON files.
+ * This class handles reading, parsing and validating of policy distribution parameters from JSON
+ * files.
*/
public class DistributionParameterHandler {
private static final Logger LOGGER = FlexLogger.getLogger(DistributionParameterHandler.class);
@@ -51,7 +50,8 @@ public class DistributionParameterHandler {
// Read the parameters
try {
// Read the parameters from JSON using Gson
- final Gson gson = new GsonBuilder().create();
+ final Gson gson = new GsonBuilder().registerTypeAdapter(PolicyForwarderConfigurationParameterGroup.class,
+ new PolicyForwarderConfigurationParametersJsonAdapter()).create();
distributionParameterGroup = gson.fromJson(new FileReader(arguments.getFullConfigurationFilePath()),
DistributionParameterGroup.class);
} catch (final Exception e) {
diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParameterGroup.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParameterGroup.java
new file mode 100644
index 00000000..f2c496d4
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParameterGroup.java
@@ -0,0 +1,43 @@
+/*-
+ * ============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.main.parameters;
+
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.distribution.forwarding.PolicyForwarder;
+
+/**
+ * Base class of all {@link ParameterGroup} classes for configuration parameters for
+ * {@link PolicyForwarder} classes
+ */
+public abstract class PolicyForwarderConfigurationParameterGroup implements ParameterGroup {
+
+ private String name;
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParametersJsonAdapter.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParametersJsonAdapter.java
new file mode 100644
index 00000000..5ce15a28
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/PolicyForwarderConfigurationParametersJsonAdapter.java
@@ -0,0 +1,80 @@
+/*-
+ * ============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.main.parameters;
+
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import java.lang.reflect.Type;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class deserialises policy forwarder parameters from JSON.
+ */
+public class PolicyForwarderConfigurationParametersJsonAdapter
+ implements JsonDeserializer<PolicyForwarderConfigurationParameterGroup> {
+ private static final XLogger LOGGER =
+ XLoggerFactory.getXLogger(PolicyForwarderConfigurationParametersJsonAdapter.class);
+
+ private static final String PARAMETER_CLASS_NAME = "parameterClassName";
+ private static final String POLICY_FORWARDER_PARAMETERS = "parameters";
+
+ @Override
+ public PolicyForwarderConfigurationParameterGroup deserialize(final JsonElement json, final Type typeOfT,
+ final JsonDeserializationContext context) {
+ final JsonObject jsonObject = json.getAsJsonObject();
+
+ final String policyForwarderParameterClassName = getParameterGroupClassName(jsonObject);
+ Class<?> policyForwarderParameterClass = getParameterGroupClass(policyForwarderParameterClassName);
+
+ return context.deserialize(jsonObject.get(POLICY_FORWARDER_PARAMETERS), policyForwarderParameterClass);
+ }
+
+ private String getParameterGroupClassName(final JsonObject jsonObject) {
+ final JsonPrimitive classNameJsonPrimitive = ((JsonPrimitive) jsonObject.get(PARAMETER_CLASS_NAME));
+
+ if (classNameJsonPrimitive == null || classNameJsonPrimitive.getAsString().length() == 0) {
+ final String errorMessage = "parameter \"" + PARAMETER_CLASS_NAME + "\" value \""
+ + (classNameJsonPrimitive != null ? classNameJsonPrimitive.getAsString() : "null")
+ + "\" invalid in JSON file";
+ LOGGER.warn(errorMessage);
+ throw new IllegalArgumentException(errorMessage);
+ }
+ return classNameJsonPrimitive.getAsString().replaceAll("\\s+", "");
+ }
+
+ private Class<?> getParameterGroupClass(final String policyForwarderParameterClassName) {
+ Class<?> policyForwarderParameterClass = null;
+ try {
+ policyForwarderParameterClass = Class.forName(policyForwarderParameterClassName);
+ } catch (final ClassNotFoundException e) {
+ final String errorMessage = "parameter \"" + PARAMETER_CLASS_NAME + "\" value \""
+ + policyForwarderParameterClassName + "\", could not find class";
+ LOGGER.warn(errorMessage, e);
+ throw new IllegalArgumentException(errorMessage, e);
+ }
+ return policyForwarderParameterClass;
+ }
+
+}
diff --git a/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java b/main/src/main/java/org/onap/policy/distribution/main/startstop/DistributionActivator.java
index 70724a12..792c4726 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
@@ -22,20 +22,21 @@ package org.onap.policy.distribution.main.startstop;
import java.util.HashMap;
import java.util.Map;
-
+import java.util.Map.Entry;
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.main.PolicyDistributionException;
import org.onap.policy.distribution.main.parameters.DistributionParameterGroup;
+import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup;
import org.onap.policy.distribution.main.rest.DistributionRestServer;
import org.onap.policy.distribution.reception.decoding.PluginInitializationException;
import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler;
import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
/**
- * This class wraps a distributor so that it can be activated as a complete service together with all its distribution
- * and forwarding handlers.
+ * This class wraps a distributor so that it can be activated as a complete service together with
+ * all its distribution and forwarding handlers.
*/
public class DistributionActivator {
// The logger for this class
@@ -148,6 +149,11 @@ public class DistributionActivator {
ParameterService.register(params.getPssdConfigurationParametersGroup());
ParameterService.register(params.getPluginHandlerParameters());
}
+ for (final Entry<String, PolicyForwarderConfigurationParameterGroup> forwarderConfiguration : distributionParameterGroup
+ .getPolicyForwarderConfigurationParameters().entrySet()) {
+ forwarderConfiguration.getValue().setName(forwarderConfiguration.getKey());
+ ParameterService.register(forwarderConfiguration.getValue());
+ }
}
/**
@@ -163,6 +169,11 @@ public class DistributionActivator {
ParameterService.deregister((params.getPssdConfigurationParametersGroup().getName()));
ParameterService.deregister((params.getPluginHandlerParameters().getName()));
}
+ for (final Entry<String, PolicyForwarderConfigurationParameterGroup> forwarderConfiguration : distributionParameterGroup
+ .getPolicyForwarderConfigurationParameters().entrySet()) {
+ forwarderConfiguration.getValue().setName(forwarderConfiguration.getKey());
+ ParameterService.deregister(forwarderConfiguration.getKey());
+ }
}
/**
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 ac58b830..186aa821 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
@@ -24,8 +24,9 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
+import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup;
+import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup.DummyPolicyForwarderParameterGroupBuilder;
import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters;
import org.onap.policy.distribution.reception.parameters.PssdConfigurationParametersGroup;
@@ -48,6 +49,8 @@ public class CommonTestData {
public static final String FORWARDER_TYPE = "DummyForwarder";
public static final String FORWARDER_CLASS_NAME =
"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder";
+ public static final String FORWARDER_CONFIGURATION_PARAMETERS = "dummyConfiguration";
+ public static final String FORWARDER_HOST = "192.168.99.100";
public static final String RECEPTION_HANDLER_TYPE = "DummyReceptionHandler";
public static final String RECEPTION_HANDLER_CLASS_NAME =
"org.onap.policy.distribution.main.testclasses.DummyReceptionHandler";
@@ -142,8 +145,8 @@ public class CommonTestData {
final Map<String, PolicyForwarderParameters> policyForwarders =
new HashMap<String, PolicyForwarderParameters>();
if (!isEmpty) {
- final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME);
+ final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(FORWARDER_TYPE,
+ FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
policyForwarders.put(DUMMY_ENGINE_FORWARDER_KEY, pFParameters);
}
return policyForwarders;
@@ -163,4 +166,24 @@ public class CommonTestData {
}
return policyDecoders;
}
+
+ /**
+ * Returns PolicyForwarderConfigurationParameterGroups for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the PolicyForwarderConfigurationParameterGroups
+ */
+ public Map<String, PolicyForwarderConfigurationParameterGroup> getPolicyForwarderConfigurationParameters(
+ final boolean isEmpty) {
+ final Map<String, PolicyForwarderConfigurationParameterGroup> policyForwarderConfigurationParameters =
+ new HashMap<String, PolicyForwarderConfigurationParameterGroup>();
+ if (!isEmpty) {
+ DummyPolicyForwarderParameterGroup dummyPolicyForwarderParameterGroup =
+ new DummyPolicyForwarderParameterGroupBuilder().setUseHttps(true).setHostname(FORWARDER_HOST)
+ .setPort(1234).setUserName("myUser").setPassword("myPassword").setIsManaged(true).build();
+ policyForwarderConfigurationParameters.put(FORWARDER_CONFIGURATION_PARAMETERS,
+ dummyPolicyForwarderParameterGroup);
+ }
+ return policyForwarderConfigurationParameters;
+ }
}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
index a2d72585..0c8c80d6 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
@@ -26,9 +26,9 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Map;
-
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup;
import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
/**
@@ -44,9 +44,12 @@ public class TestDistributionParameterGroup {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData
.getReceptionHandlerParameters(false);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
- final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
- CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters);
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters,
+ receptionHandlerParameters, forwarderConfigurations);
final GroupValidationResult validationResult = distributionParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(restServerParameters.getHost(), distributionParameters.getRestServerParameters().getHost());
@@ -69,6 +72,9 @@ public class TestDistributionParameterGroup {
.getPluginHandlerParameters(),
distributionParameters.getReceptionHandlerParameters()
.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters());
+ assertEquals(CommonTestData.FORWARDER_HOST,
+ ((DummyPolicyForwarderParameterGroup) distributionParameters.getPolicyForwarderConfigurationParameters()
+ .get(CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS)).getHostname());
}
@Test
@@ -76,9 +82,11 @@ public class TestDistributionParameterGroup {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData
.getReceptionHandlerParameters(false);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(null,
- restServerParameters, receptionHandlerParameters);
+ restServerParameters, receptionHandlerParameters, forwarderConfigurations);
final GroupValidationResult validationResult = distributionParameters.validate();
assertFalse(validationResult.isValid());
assertEquals(null, distributionParameters.getName());
@@ -105,9 +113,11 @@ public class TestDistributionParameterGroup {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData
.getReceptionHandlerParameters(false);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
final DistributionParameterGroup distributionParameters = new DistributionParameterGroup("",
- restServerParameters, receptionHandlerParameters);
+ restServerParameters, receptionHandlerParameters, forwarderConfigurations);
final GroupValidationResult validationResult = distributionParameters.validate();
assertFalse(validationResult.isValid());
assertEquals("", distributionParameters.getName());
@@ -131,9 +141,11 @@ public class TestDistributionParameterGroup {
@Test
public void testDistributionParameterGroup_NullReceptionHandlerParameters() {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
try {
final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
- CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, null);
+ CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, null, forwarderConfigurations);
distributionParameters.validate();
fail("test should throw an exception here");
} catch (final Exception e) {
@@ -147,9 +159,11 @@ public class TestDistributionParameterGroup {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData
.getReceptionHandlerParameters(true);
-
- final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
- CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters,
+ receptionHandlerParameters, forwarderConfigurations);
distributionParameters.validate();
GroupValidationResult result = distributionParameters.validate();
assertFalse(result.isValid());
@@ -161,9 +175,12 @@ public class TestDistributionParameterGroup {
final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true);
final Map<String, ReceptionHandlerParameters> receptionHandlerParameters = commonTestData
.getReceptionHandlerParameters(false);
+ final Map<String, PolicyForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getPolicyForwarderConfigurationParameters(false);
- final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
- CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters);
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters,
+ receptionHandlerParameters, forwarderConfigurations);
final GroupValidationResult validationResult = distributionParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
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 8b474984..14d1a105 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
@@ -27,10 +27,10 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-
import org.junit.Test;
import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments;
+import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup;
/**
* Class to perform unit test of DistributionParameterHandler.
@@ -40,8 +40,7 @@ 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);
@@ -56,8 +55,7 @@ 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);
@@ -72,8 +70,7 @@ 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);
@@ -90,8 +87,7 @@ 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);
@@ -108,8 +104,7 @@ 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);
@@ -124,8 +119,7 @@ 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);
@@ -136,8 +130,7 @@ 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);
@@ -155,12 +148,50 @@ public class TestDistributionParameterHandler {
parGroup.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
.getPluginHandlerParameters().getPolicyForwarders()
.get(CommonTestData.DUMMY_ENGINE_FORWARDER_KEY).getForwarderType());
+ assertEquals(CommonTestData.FORWARDER_HOST,
+ ((DummyPolicyForwarderParameterGroup) parGroup.getPolicyForwarderConfigurationParameters()
+ .get(CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS)).getHostname());
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidForwarderConfigurationClassName()
+ throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ {"-c", "parameters/DistributionConfigParameters_InvalidForwarderConfigurationClassName.json"};
+
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ arguments.parse(distributionConfigParameters);
+
+ try {
+ new DistributionParameterHandler().getParameters(arguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("parameter \"parameterClassName\" value \"\" invalid in JSON file"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_UnknownForwarderConfigurationClassName()
+ throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ {"-c", "parameters/DistributionConfigParameters_UnknownForwarderConfigurationClassName.json"};
+
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ arguments.parse(distributionConfigParameters);
+
+ try {
+ new DistributionParameterHandler().getParameters(arguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains(
+ "parameter \"parameterClassName\" value \"org.onap.policy.Unknown\", could not find class"));
+ }
}
@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);
@@ -177,7 +208,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);
@@ -193,7 +224,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);
@@ -209,7 +240,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);
@@ -225,7 +256,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);
@@ -241,7 +272,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);
@@ -257,7 +288,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);
@@ -274,7 +305,7 @@ public class TestDistributionParameterHandler {
public void testDistributionParameterGroup_InvalidReceptionHandlerParameters()
throws PolicyDistributionException, IOException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json" };
+ {"-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -294,7 +325,7 @@ public class TestDistributionParameterHandler {
public void testDistributionParameterGroup_InvalidDecoderAndForwarderParameters()
throws PolicyDistributionException, IOException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json" };
+ {"-c", "parameters/DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -314,7 +345,7 @@ public class TestDistributionParameterHandler {
public void testDistributionParameterGroup_InvalidRestServerParameters()
throws PolicyDistributionException, IOException {
final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters_InvalidRestServerParameters.json" };
+ {"-c", "parameters/DistributionConfigParameters_InvalidRestServerParameters.json"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
arguments.parse(distributionConfigParameters);
@@ -332,8 +363,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionVersion() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-v" };
+ final String[] distributionConfigParameters = {"-v"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
final String version = arguments.parse(distributionConfigParameters);
assertTrue(version.startsWith("ONAP Policy Framework Distribution Service"));
@@ -341,8 +371,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionHelp() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-h" };
+ final String[] distributionConfigParameters = {"-h"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
final String help = arguments.parse(distributionConfigParameters);
assertTrue(help.startsWith("usage:"));
@@ -350,8 +379,7 @@ public class TestDistributionParameterHandler {
@Test
public void testDistributionInvalidOption() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-d" };
+ final String[] distributionConfigParameters = {"-d"};
final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
try {
arguments.parse(distributionConfigParameters);
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
index 552ee50c..9eeae354 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
@@ -26,7 +26,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Map;
-
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters;
diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java
index d64df1b3..9907bfb8 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java
@@ -23,6 +23,9 @@ package org.onap.policy.distribution.main.parameters;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.onap.policy.distribution.main.parameters.CommonTestData.FORWARDER_CLASS_NAME;
+import static org.onap.policy.distribution.main.parameters.CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS;
+import static org.onap.policy.distribution.main.parameters.CommonTestData.FORWARDER_TYPE;
import org.junit.Test;
import org.onap.policy.common.parameters.GroupValidationResult;
@@ -38,20 +41,20 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE, CommonTestData.FORWARDER_CLASS_NAME);
+ new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
- assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
- assertEquals(CommonTestData.FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
+ assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
assertTrue(validationResult.isValid());
}
@Test
public void testPolicyForwarderParameters_InvalidForwarderType() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters("", CommonTestData.FORWARDER_CLASS_NAME);
+ new PolicyForwarderParameters("", FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
assertEquals("", pFParameters.getForwarderType());
- assertEquals(CommonTestData.FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
+ assertEquals(FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult().contains(
"field \"forwarderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"));
@@ -59,7 +62,8 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_InvalidForwarderClassName() {
- final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE, "");
+ final PolicyForwarderParameters pFParameters =
+ new PolicyForwarderParameters(FORWARDER_TYPE, "", FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
assertEquals("", pFParameters.getForwarderClassName());
@@ -71,7 +75,8 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_InvalidForwarderTypeAndClassName() {
- final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters("", "");
+ final PolicyForwarderParameters pFParameters =
+ new PolicyForwarderParameters("", "", FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
assertEquals("", pFParameters.getForwarderType());
assertEquals("", pFParameters.getForwarderClassName());
@@ -86,10 +91,10 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_NullForwarderType() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(null, CommonTestData.FORWARDER_CLASS_NAME);
+ new PolicyForwarderParameters(null, FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
assertEquals(null, pFParameters.getForwarderType());
- assertEquals(CommonTestData.FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
+ assertEquals(FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
.contains("field \"forwarderType\" type \"java.lang.String\" value \"null\" INVALID, "
@@ -99,9 +104,9 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_NullForwarderClassName() {
final PolicyForwarderParameters pFParameters =
- new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE, null);
+ new PolicyForwarderParameters(FORWARDER_TYPE, null, FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
- assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType());
assertEquals(null, pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
@@ -111,11 +116,11 @@ public class TestPolicyForwarderParameters {
@Test
public void testPolicyForwarderParameters_InvalidForwarderClass() {
- final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(CommonTestData.FORWARDER_TYPE,
- CommonTestData.FORWARDER_CLASS_NAME + "Invalid");
+ final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(FORWARDER_TYPE,
+ FORWARDER_CLASS_NAME + "Invalid", FORWARDER_CONFIGURATION_PARAMETERS);
final GroupValidationResult validationResult = pFParameters.validate();
- assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
- assertEquals(CommonTestData.FORWARDER_CLASS_NAME + "Invalid", pFParameters.getForwarderClassName());
+ assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(FORWARDER_CLASS_NAME + "Invalid", pFParameters.getForwarderClassName());
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult().contains("policy forwarder class not found in classpath"));
}
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 c901b5d9..47ac82b1 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
@@ -28,6 +28,7 @@ import org.onap.policy.distribution.main.PolicyDistributionException;
import org.onap.policy.distribution.main.parameters.CommonTestData;
import org.onap.policy.distribution.main.parameters.DistributionParameterGroup;
import org.onap.policy.distribution.main.parameters.DistributionParameterHandler;
+import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup;
/**
* Class to perform unit test of DistributionActivator.
@@ -38,8 +39,7 @@ public class TestDistributionActivator {
@Test
public void testDistributionActivator() throws PolicyDistributionException {
- final String[] distributionConfigParameters =
- { "-c", "parameters/DistributionConfigParameters.json" };
+ final String[] distributionConfigParameters = {"-c", "parameters/DistributionConfigParameters.json"};
final DistributionCommandLineArguments arguments =
new DistributionCommandLineArguments(distributionConfigParameters);
@@ -61,6 +61,9 @@ public class TestDistributionActivator {
activator.getParameterGroup().getReceptionHandlerParameters()
.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters()
.getPolicyForwarders().get(CommonTestData.DUMMY_ENGINE_FORWARDER_KEY).getForwarderType());
+ assertEquals(DummyPolicyForwarderParameterGroup.class,
+ activator.getParameterGroup().getPolicyForwarderConfigurationParameters()
+ .get(CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS).getClass());
activator.terminate();
}
}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarder.java b/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarder.java
index 5cae0c6a..c9c7fef2 100644
--- a/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarder.java
+++ b/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarder.java
@@ -22,7 +22,6 @@ package org.onap.policy.distribution.main.testclasses;
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;
@@ -49,4 +48,7 @@ public class DummyPolicyForwarder implements PolicyForwarder {
public boolean receivedPolicy(final Policy policy) {
return policiesReceived.contains(policy);
}
+
+ @Override
+ public void configure(String parameterGroupName) {}
}
diff --git a/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarderParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarderParameterGroup.java
new file mode 100644
index 00000000..66217d18
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/distribution/main/testclasses/DummyPolicyForwarderParameterGroup.java
@@ -0,0 +1,131 @@
+/*-
+ * ============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.main.testclasses;
+
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup;
+
+/**
+ * Dummy policy forwarder parameter group.
+ */
+public class DummyPolicyForwarderParameterGroup extends PolicyForwarderConfigurationParameterGroup {
+
+ private boolean useHttps;
+ private String hostname;
+ private int port;
+ private String userName;
+ private String password;
+ private boolean isManaged;
+
+ public boolean isUseHttps() {
+ return useHttps;
+ }
+
+ public String getHostname() {
+ return hostname;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public boolean isManaged() {
+ return isManaged;
+ }
+
+ /**
+ * Builder for DummyPolicyForwarderParameterGroup.
+ */
+ public static class DummyPolicyForwarderParameterGroupBuilder {
+ private boolean useHttps;
+ private String hostname;
+ private int port;
+ private String userName;
+ private String password;
+ private boolean isManaged;
+
+ public DummyPolicyForwarderParameterGroupBuilder setUseHttps(final boolean useHttps) {
+ this.useHttps = useHttps;
+ return this;
+ }
+
+ public DummyPolicyForwarderParameterGroupBuilder setHostname(final String hostname) {
+ this.hostname = hostname;
+ return this;
+ }
+
+ public DummyPolicyForwarderParameterGroupBuilder setPort(final int port) {
+ this.port = port;
+ return this;
+ }
+
+ public DummyPolicyForwarderParameterGroupBuilder setUserName(final String userName) {
+ this.userName = userName;
+ return this;
+ }
+
+ public DummyPolicyForwarderParameterGroupBuilder setPassword(final String password) {
+ this.password = password;
+ return this;
+ }
+
+ public DummyPolicyForwarderParameterGroupBuilder setIsManaged(final boolean isManaged) {
+ this.isManaged = isManaged;
+ return this;
+ }
+
+ /**
+ * Creates a new DummyPolicyForwarderParameterGroup instance.
+ */
+ public DummyPolicyForwarderParameterGroup build() {
+ return new DummyPolicyForwarderParameterGroup(this);
+ }
+ }
+
+ /**
+ * Construct an instance.
+ *
+ * @param builder the builder create the instance from
+ */
+ private DummyPolicyForwarderParameterGroup(final DummyPolicyForwarderParameterGroupBuilder builder) {
+ this.useHttps = builder.useHttps;
+ this.hostname = builder.hostname;
+ this.port = builder.port;
+ this.userName = builder.userName;
+ this.password = builder.password;
+ this.isManaged = builder.isManaged;
+ }
+
+ @Override
+ public GroupValidationResult validate() {
+ final GroupValidationResult validationResult = new GroupValidationResult(this);
+ return validationResult;
+ }
+
+}
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters.json b/main/src/test/resources/parameters/DistributionConfigParameters.json
index 29e3e467..7a557624 100644
--- a/main/src/test/resources/parameters/DistributionConfigParameters.json
+++ b/main/src/test/resources/parameters/DistributionConfigParameters.json
@@ -44,10 +44,24 @@
"policyForwarders":{
"DummyForwarder":{
"forwarderType":"DummyForwarder",
- "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder"
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder",
+ "forwarderConfigurationParameters": "dummyConfiguration"
}
}
}
}
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
}
}
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters_EmptyPolicyDecoder.json b/main/src/test/resources/parameters/DistributionConfigParameters_EmptyPolicyDecoder.json
index ce667771..d11ac9ea 100644
--- a/main/src/test/resources/parameters/DistributionConfigParameters_EmptyPolicyDecoder.json
+++ b/main/src/test/resources/parameters/DistributionConfigParameters_EmptyPolicyDecoder.json
@@ -40,10 +40,24 @@
"policyForwarders":{
"DummyForwarder":{
"forwarderType":"DummyForwarder",
- "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder"
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
}
}
}
}
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
}
}
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters_EmptyPolicyForwarder.json b/main/src/test/resources/parameters/DistributionConfigParameters_EmptyPolicyForwarder.json
index 3eceef2d..c534154c 100644
--- a/main/src/test/resources/parameters/DistributionConfigParameters_EmptyPolicyForwarder.json
+++ b/main/src/test/resources/parameters/DistributionConfigParameters_EmptyPolicyForwarder.json
@@ -45,5 +45,18 @@
}
}
}
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
}
}
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandler.json b/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandler.json
index 74733007..b8010f8d 100644
--- a/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandler.json
+++ b/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandler.json
@@ -7,5 +7,18 @@
"password":"zb!XztG34"
},
"receptionHandlerParameters":{
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
}
} \ No newline at end of file
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json b/main/src/test/resources/parameters/DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json
index 4d1c4090..0c9caa6c 100644
--- a/main/src/test/resources/parameters/DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json
+++ b/main/src/test/resources/parameters/DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json
@@ -52,19 +52,35 @@
"policyForwarders":{
"DummyForwarder":{
"forwarderType":"DummyForwarder",
- "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder"
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
},
"PAPStandaloneForwarder":{
"forwarderType":"",
- "forwarderClassName":"org.onap.policy.distribution.main.testclasses.PapStandalonePolicyForwarder"
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.PapStandalonePolicyForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
},
"PAPEngineForwarder":{
"forwarderType":"PAPEngineForwarder",
- "forwarderClassName":""
+ "forwarderClassName":"",
+ "forwarderConfigurationName": "dummyConfiguration"
}
}
}
}
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
}
}
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters_InvalidForwarderConfigurationClassName.json b/main/src/test/resources/parameters/DistributionConfigParameters_InvalidForwarderConfigurationClassName.json
new file mode 100644
index 00000000..ba895a67
--- /dev/null
+++ b/main/src/test/resources/parameters/DistributionConfigParameters_InvalidForwarderConfigurationClassName.json
@@ -0,0 +1,67 @@
+{
+ "name":"SDCDistributionGroup",
+ "restServerParameters":{
+ "host":"0.0.0.0",
+ "port":6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34"
+ },
+ "receptionHandlerParameters":{
+ "DummyReceptionHandler":{
+ "receptionHandlerType":"DummyReceptionHandler",
+ "receptionHandlerClassName":"org.onap.policy.distribution.main.testclasses.DummyReceptionHandler",
+ "pssdConfiguration":{
+ "asdcAddress": "localhost",
+ "messageBusAddress": [
+ "a.com",
+ "b.com",
+ "c.com"
+ ],
+ "user": "tbdsdc-1480",
+ "password": "tbdsdc-1480",
+ "pollingInterval":20,
+ "pollingTimeout":30,
+ "consumerId": "policy-id",
+ "artifactTypes": [
+ "TOSCA_CSAR",
+ "HEAT"
+ ],
+ "consumerGroup": "policy-group",
+ "environmentName": "environmentName",
+ "keystorePath": "null",
+ "keystorePassword": "null",
+ "activeserverTlsAuth": false,
+ "isFilterinEmptyResources": true,
+ "isUseHttpsWithDmaap": false
+ },
+ "pluginHandlerParameters":{
+ "policyDecoders":{
+ "DummyDecoder":{
+ "decoderType":"DummyDecoder",
+ "decoderClassName":"org.onap.policy.distribution.main.testclasses.DummyDecoder"
+ }
+ },
+ "policyForwarders":{
+ "DummyForwarder":{
+ "forwarderType":"DummyForwarder",
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder",
+ "forwarderConfigurationParameters": "dummyConfiguration"
+ }
+ }
+ }
+ }
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
+ }
+}
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters_InvalidName.json b/main/src/test/resources/parameters/DistributionConfigParameters_InvalidName.json
index 377c70ec..7cafc266 100644
--- a/main/src/test/resources/parameters/DistributionConfigParameters_InvalidName.json
+++ b/main/src/test/resources/parameters/DistributionConfigParameters_InvalidName.json
@@ -44,10 +44,24 @@
"policyForwarders":{
"DummyForwarder":{
"forwarderType":"DummyForwarder",
- "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder"
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
}
}
}
}
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
}
}
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json b/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json
index 0ea171e8..793702fb 100644
--- a/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json
+++ b/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json
@@ -44,10 +44,24 @@
"policyForwarders":{
"DummyForwarder":{
"forwarderType":"DummyForwarder",
- "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder"
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
}
}
}
}
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
}
}
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters_InvalidRestServerParameters.json b/main/src/test/resources/parameters/DistributionConfigParameters_InvalidRestServerParameters.json
index 85d450e6..0d650331 100644
--- a/main/src/test/resources/parameters/DistributionConfigParameters_InvalidRestServerParameters.json
+++ b/main/src/test/resources/parameters/DistributionConfigParameters_InvalidRestServerParameters.json
@@ -44,10 +44,24 @@
"policyForwarders":{
"DummyForwarder":{
"forwarderType":"DummyForwarder",
- "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder"
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
}
}
}
}
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
}
}
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters_NoPolicyDecoder.json b/main/src/test/resources/parameters/DistributionConfigParameters_NoPolicyDecoder.json
index ffb4c728..f9392db5 100644
--- a/main/src/test/resources/parameters/DistributionConfigParameters_NoPolicyDecoder.json
+++ b/main/src/test/resources/parameters/DistributionConfigParameters_NoPolicyDecoder.json
@@ -38,10 +38,24 @@
"policyForwarders":{
"DummyForwarder":{
"forwarderType":"DummyForwarder",
- "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder"
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
}
}
}
}
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
}
}
diff --git a/main/src/test/resources/parameters/DistributionConfigParameters_UnknownForwarderConfigurationClassName.json b/main/src/test/resources/parameters/DistributionConfigParameters_UnknownForwarderConfigurationClassName.json
new file mode 100644
index 00000000..c189671d
--- /dev/null
+++ b/main/src/test/resources/parameters/DistributionConfigParameters_UnknownForwarderConfigurationClassName.json
@@ -0,0 +1,67 @@
+{
+ "name":"SDCDistributionGroup",
+ "restServerParameters":{
+ "host":"0.0.0.0",
+ "port":6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34"
+ },
+ "receptionHandlerParameters":{
+ "DummyReceptionHandler":{
+ "receptionHandlerType":"DummyReceptionHandler",
+ "receptionHandlerClassName":"org.onap.policy.distribution.main.testclasses.DummyReceptionHandler",
+ "pssdConfiguration":{
+ "asdcAddress": "localhost",
+ "messageBusAddress": [
+ "a.com",
+ "b.com",
+ "c.com"
+ ],
+ "user": "tbdsdc-1480",
+ "password": "tbdsdc-1480",
+ "pollingInterval":20,
+ "pollingTimeout":30,
+ "consumerId": "policy-id",
+ "artifactTypes": [
+ "TOSCA_CSAR",
+ "HEAT"
+ ],
+ "consumerGroup": "policy-group",
+ "environmentName": "environmentName",
+ "keystorePath": "null",
+ "keystorePassword": "null",
+ "activeserverTlsAuth": false,
+ "isFilterinEmptyResources": true,
+ "isUseHttpsWithDmaap": false
+ },
+ "pluginHandlerParameters":{
+ "policyDecoders":{
+ "DummyDecoder":{
+ "decoderType":"DummyDecoder",
+ "decoderClassName":"org.onap.policy.distribution.main.testclasses.DummyDecoder"
+ }
+ },
+ "policyForwarders":{
+ "DummyForwarder":{
+ "forwarderType":"DummyForwarder",
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder",
+ "forwarderConfigurationParameters": "dummyConfiguration"
+ }
+ }
+ }
+ }
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.Unknown",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
+ }
+}
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
index c113d2ce..1b797def 100644
--- a/main/src/test/resources/parameters/MinimumParameters.json
+++ b/main/src/test/resources/parameters/MinimumParameters.json
@@ -44,10 +44,24 @@
"policyForwarders":{
"DummyForwarder":{
"forwarderType":"DummyForwarder",
- "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder"
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
}
}
}
}
+ },
+ "policyForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
}
}