summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2019-04-15 08:43:41 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-15 08:43:41 +0000
commite3e4aaf2140c94fe0811c40186df2f860a2346d7 (patch)
tree8e6c3c0f5e4e8b61147d726f41f457e933354e3b
parent2faa774836fc4e2bc7a85091a8c832c2bc5415d2 (diff)
parentdc1321b4c135242c67e94f5af57d0e39866ce2d8 (diff)
Merge "add testcase to improve test coverage"
-rw-r--r--artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java180
-rw-r--r--artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestArtifactForwarderParameters.java126
-rw-r--r--artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java219
-rw-r--r--artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java377
-rw-r--r--artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java60
-rw-r--r--artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java153
-rw-r--r--artifactbroker/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java68
-rw-r--r--artifactbroker/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java77
-rw-r--r--artifactbroker/main/src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt17
-rw-r--r--artifactbroker/main/src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt6
-rw-r--r--artifactbroker/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt7
-rw-r--r--artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyArtifactForwarder.json43
-rw-r--r--artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandler.json4
-rw-r--r--artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandlerClass.json48
-rw-r--r--artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidForwarderConfigurationClassName.json48
-rw-r--r--artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidName.json48
-rw-r--r--artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerClass.json48
-rw-r--r--artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json48
-rw-r--r--artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidRestServerParameters.json48
-rw-r--r--artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_NoArtifactForwarder.json (renamed from artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_NoPolicyForwarder.json)0
-rw-r--r--artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_UnknownForwarderConfigurationClassName.json48
-rw-r--r--artifactbroker/packages/pom.xml5
-rw-r--r--artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java120
-rw-r--r--artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java52
-rw-r--r--artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java84
25 files changed, 1676 insertions, 258 deletions
diff --git a/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java
new file mode 100644
index 0000000..7793873
--- /dev/null
+++ b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/CommonTestData.java
@@ -0,0 +1,180 @@
+/*-
+ * ============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 java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.onap.policy.distribution.forwarding.parameters.ArtifactForwarderParameters;
+import org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup;
+import org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup.DummyArtifactForwarderParameterGroupBuilder;
+import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup;
+import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup.DummyReceptionHandlerParameterGroupBuilder;
+import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
+import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
+import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
+
+/**
+ * Class to hold/create all parameters for test cases.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class CommonTestData {
+
+ private static final String REST_SERVER_PASSWORD = "zb!XztG34";
+ private static final String REST_SERVER_USER = "healthcheck";
+ private static final int REST_SERVER_PORT = 6969;
+ private static final String REST_SERVER_HOST = "0.0.0.0";
+ private static final boolean REST_SERVER_HTTPS = false;
+ public static final String DISTRIBUTION_GROUP_NAME = "SDCDistributionGroup";
+ public static final String FORWARDER_TYPE = "DummyForwarder";
+ public static final String FORWARDER_CLASS_NAME =
+ "org.onap.policy.distribution.main.testclasses.DummyArtifactForwarder";
+ 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";
+ public static final String RECEPTION_CONFIGURATION_PARAMETERS = "dummyReceptionHandlerConfiguration";
+ public static final String MY_STRING_PARAMETER_VALUE = "aStringValue";
+ public static final Boolean MY_BOOLEAN_PARAMETER_VALUE = true;
+ public static final int MY_INTEGER_PARAMETER_VALUE = 1234;
+
+ public static final String DUMMY_RECEPTION_HANDLER_KEY = "DummyReceptionHandler";
+ public static final String DUMMY_ENGINE_FORWARDER_KEY = "DummyForwarder";
+
+ public static final String POLICY_TYPE = "DUMMY";
+ public static final String POLICY_NAME = "SamplePolicy";
+
+ /**
+ * Returns an instance of ReceptionHandlerParameters for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the restServerParameters object
+ */
+ public RestServerParameters getRestServerParameters(final boolean isEmpty) {
+ final RestServerParameters restServerParameters;
+ if (!isEmpty) {
+ restServerParameters = new RestServerParameters(REST_SERVER_HOST, REST_SERVER_PORT, REST_SERVER_USER,
+ REST_SERVER_PASSWORD, REST_SERVER_HTTPS);
+ } else {
+ restServerParameters = new RestServerParameters(null, 0, null, null, REST_SERVER_HTTPS);
+ }
+ return restServerParameters;
+ }
+
+ /**
+ * Returns an instance of ReceptionHandlerParameters for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the receptionHandlerParameters object
+ */
+ public Map<String, ReceptionHandlerParameters> getReceptionHandlerParameters(final boolean isEmpty) {
+ final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
+ new HashMap<String, ReceptionHandlerParameters>();
+ if (!isEmpty) {
+ final Map<String, ArtifactForwarderParameters> policyForwarders = getArtifactForwarders(isEmpty);
+ final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyForwarders);
+ final ReceptionHandlerParameters rhParameters = new ReceptionHandlerParameters(RECEPTION_HANDLER_TYPE,
+ RECEPTION_HANDLER_CLASS_NAME, RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
+ receptionHandlerParameters.put(DUMMY_RECEPTION_HANDLER_KEY, rhParameters);
+ }
+ return receptionHandlerParameters;
+ }
+
+ /**
+ * Returns ReceptionHandlerConfigurationParameterGroups for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the ReceptionHandlerConfigurationParameterGroups
+ */
+ public Map<String, ReceptionHandlerConfigurationParameterGroup> getReceptionHandlerConfigurationParameters(
+ final boolean isEmpty) {
+ final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurationParameters =
+ new HashMap<String, ReceptionHandlerConfigurationParameterGroup>();
+ if (!isEmpty) {
+ final List<String> messageBusAddress = new ArrayList<>();
+ messageBusAddress.add("localhost");
+ final List<String> artifactTypes = new ArrayList<>();
+ artifactTypes.add("TOSCA_CSAR");
+ final DummyReceptionHandlerParameterGroup dummyReceptionHandlerParameterGroup =
+ new DummyReceptionHandlerParameterGroupBuilder().setMyStringParameter(MY_STRING_PARAMETER_VALUE)
+ .setMyIntegerParameter(MY_INTEGER_PARAMETER_VALUE)
+ .setMyBooleanParameter(MY_BOOLEAN_PARAMETER_VALUE).build();
+ receptionHandlerConfigurationParameters.put(RECEPTION_CONFIGURATION_PARAMETERS,
+ dummyReceptionHandlerParameterGroup);
+ }
+ return receptionHandlerConfigurationParameters;
+ }
+
+ /**
+ * Returns an instance of PluginHandlerParameters for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the pluginHandlerParameters object
+ */
+ public PluginHandlerParameters getPluginHandlerParameters(final boolean isEmpty) {
+ final Map<String, ArtifactForwarderParameters> policyForwarders = getArtifactForwarders(isEmpty);
+ final PluginHandlerParameters pluginHandlerParameters =
+ new PluginHandlerParameters(policyForwarders);
+ return pluginHandlerParameters;
+ }
+
+ /**
+ * Returns an instance of ArtifactForwarderParameters for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the policyForwarders object
+ */
+ public Map<String, ArtifactForwarderParameters> getArtifactForwarders(final boolean isEmpty) {
+ final Map<String, ArtifactForwarderParameters> policyForwarders =
+ new HashMap<String, ArtifactForwarderParameters>();
+ if (!isEmpty) {
+ final ArtifactForwarderParameters pFParameters = new ArtifactForwarderParameters(FORWARDER_TYPE,
+ FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
+ policyForwarders.put(DUMMY_ENGINE_FORWARDER_KEY, pFParameters);
+ }
+ return policyForwarders;
+ }
+
+ /**
+ * Returns ArtifactForwarderConfigurationParameterGroups for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return the ArtifactForwarderConfigurationParameterGroups
+ */
+ public Map<String, ArtifactForwarderConfigurationParameterGroup> getArtifactForwarderConfigurationParameters(
+ final boolean isEmpty) {
+ final Map<String, ArtifactForwarderConfigurationParameterGroup> policyForwarderConfigurationParameters =
+ new HashMap<String, ArtifactForwarderConfigurationParameterGroup>();
+ if (!isEmpty) {
+ final DummyArtifactForwarderParameterGroup dummyArtifactForwarderParameterGroup =
+ new DummyArtifactForwarderParameterGroupBuilder().setUseHttps(true).setHostname(FORWARDER_HOST)
+ .setPort(1234).setUserName("myUser").setPassword("myPassword").setIsManaged(true).build();
+ policyForwarderConfigurationParameters.put(FORWARDER_CONFIGURATION_PARAMETERS,
+ dummyArtifactForwarderParameterGroup);
+ }
+ return policyForwarderConfigurationParameters;
+ }
+
+}
diff --git a/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestArtifactForwarderParameters.java b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestArtifactForwarderParameters.java
new file mode 100644
index 0000000..633ff44
--- /dev/null
+++ b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestArtifactForwarderParameters.java
@@ -0,0 +1,126 @@
+/*-
+ * ============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 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;
+import org.onap.policy.distribution.forwarding.parameters.ArtifactForwarderParameters;
+
+/**
+ * Class to perform unit test of ArtifactForwarderParameters.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestArtifactForwarderParameters {
+
+ @Test
+ public void testArtifactForwarderParameters() {
+ final ArtifactForwarderParameters pFParameters =
+ new ArtifactForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
+ assertTrue(validationResult.isValid());
+ }
+
+ @Test
+ public void testArtifactForwarderParameters_InvalidForwarderType() {
+ final ArtifactForwarderParameters pFParameters =
+ new ArtifactForwarderParameters("", FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals("", pFParameters.getForwarderType());
+ 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"));
+ }
+
+ @Test
+ public void testArtifactForwarderParameters_InvalidForwarderClassName() {
+ final ArtifactForwarderParameters pFParameters =
+ new ArtifactForwarderParameters(FORWARDER_TYPE, "", FORWARDER_CONFIGURATION_PARAMETERS);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals(CommonTestData.FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals("", pFParameters.getForwarderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"forwarderClassName\" type \"java.lang.String\" value \"\" INVALID, "
+ + "must be a non-blank string containing full class name of the forwarder"));
+ }
+
+ @Test
+ public void testArtifactForwarderParameters_InvalidForwarderTypeAndClassName() {
+ final ArtifactForwarderParameters pFParameters =
+ new ArtifactForwarderParameters("", "", FORWARDER_CONFIGURATION_PARAMETERS);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals("", pFParameters.getForwarderType());
+ assertEquals("", pFParameters.getForwarderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult().contains(
+ "field \"forwarderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"));
+ assertTrue(validationResult.getResult()
+ .contains("field \"forwarderClassName\" type \"java.lang.String\" value \"\" INVALID, "
+ + "must be a non-blank string containing full class name of the forwarder"));
+ }
+
+ @Test
+ public void testArtifactForwarderParameters_NullForwarderType() {
+ final ArtifactForwarderParameters pFParameters =
+ new ArtifactForwarderParameters(null, FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals(null, pFParameters.getForwarderType());
+ assertEquals(FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"forwarderType\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "must be a non-blank string"));
+ }
+
+ @Test
+ public void testArtifactForwarderParameters_NullForwarderClassName() {
+ final ArtifactForwarderParameters pFParameters =
+ new ArtifactForwarderParameters(FORWARDER_TYPE, null, FORWARDER_CONFIGURATION_PARAMETERS);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(null, pFParameters.getForwarderClassName());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"forwarderClassName\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "must be a non-blank string containing full class name of the forwarder"));
+ }
+
+ @Test
+ public void testArtifactForwarderParameters_InvalidForwarderClass() {
+ final ArtifactForwarderParameters pFParameters = new ArtifactForwarderParameters(FORWARDER_TYPE,
+ FORWARDER_CLASS_NAME + "Invalid", FORWARDER_CONFIGURATION_PARAMETERS);
+ final GroupValidationResult validationResult = pFParameters.validate();
+ assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType());
+ assertEquals(FORWARDER_CLASS_NAME + "Invalid", pFParameters.getForwarderClassName());
+ assertFalse(validationResult.isValid());
+ }
+}
diff --git a/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
new file mode 100644
index 0000000..505c34f
--- /dev/null
+++ b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java
@@ -0,0 +1,219 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+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.DummyArtifactForwarderParameterGroup;
+import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup;
+import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
+import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
+
+/**
+ * Class to perform unit test of DistributionParameterGroup.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestDistributionParameterGroup {
+ CommonTestData commonTestData = new CommonTestData();
+
+ @Test
+ public void testDistributionParameterGroup() {
+ final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
+ commonTestData.getReceptionHandlerParameters(false);
+ final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations =
+ commonTestData.getReceptionHandlerConfigurationParameters(false);
+ final Map<String, ArtifactForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getArtifactForwarderConfigurationParameters(false);
+
+ final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
+ CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters,
+ receptionHandlerConfigurations, forwarderConfigurations);
+ final GroupValidationResult validationResult = distributionParameters.validate();
+ assertTrue(validationResult.isValid());
+ assertEquals(restServerParameters.getHost(), distributionParameters.getRestServerParameters().getHost());
+ assertEquals(restServerParameters.getPort(), distributionParameters.getRestServerParameters().getPort());
+ assertEquals(restServerParameters.getUserName(),
+ distributionParameters.getRestServerParameters().getUserName());
+ assertEquals(restServerParameters.getPassword(),
+ distributionParameters.getRestServerParameters().getPassword());
+ assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, distributionParameters.getName());
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getReceptionHandlerType());
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getReceptionHandlerClassName(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getReceptionHandlerClassName());
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getPluginHandlerParameters());
+ assertEquals(CommonTestData.MY_STRING_PARAMETER_VALUE,
+ ((DummyReceptionHandlerParameterGroup) distributionParameters
+ .getReceptionHandlerConfigurationParameters()
+ .get(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS)).getMyStringParameter());
+ assertEquals(CommonTestData.MY_INTEGER_PARAMETER_VALUE,
+ ((DummyReceptionHandlerParameterGroup) distributionParameters
+ .getReceptionHandlerConfigurationParameters()
+ .get(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS)).getMyIntegerParameter());
+ assertEquals(CommonTestData.MY_BOOLEAN_PARAMETER_VALUE,
+ ((DummyReceptionHandlerParameterGroup) distributionParameters
+ .getReceptionHandlerConfigurationParameters()
+ .get(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS)).isMyBooleanParameter());
+ assertEquals(CommonTestData.FORWARDER_HOST,
+ ((DummyArtifactForwarderParameterGroup) distributionParameters.getArtifactForwarderConfigurationParameters()
+ .get(CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS)).getHostname());
+ }
+
+ @Test
+ public void testDistributionParameterGroup_NullName() {
+ final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
+ commonTestData.getReceptionHandlerParameters(false);
+ final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations =
+ commonTestData.getReceptionHandlerConfigurationParameters(false);
+ final Map<String, ArtifactForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getArtifactForwarderConfigurationParameters(false);
+
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(null, restServerParameters, receptionHandlerParameters,
+ receptionHandlerConfigurations, forwarderConfigurations);
+ final GroupValidationResult validationResult = distributionParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertEquals(null, distributionParameters.getName());
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getReceptionHandlerType());
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getReceptionHandlerClassName(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getReceptionHandlerClassName());
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getPluginHandlerParameters());
+ assertTrue(validationResult.getResult().contains(
+ "field \"name\" type \"java.lang.String\" value \"null\" INVALID, " + "must be a non-blank string"));
+ }
+
+ @Test
+ public void testDistributionParameterGroup_EmptyName() {
+ final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
+ commonTestData.getReceptionHandlerParameters(false);
+ final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations =
+ commonTestData.getReceptionHandlerConfigurationParameters(false);
+ final Map<String, ArtifactForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getArtifactForwarderConfigurationParameters(false);
+
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup("", restServerParameters, receptionHandlerParameters,
+ receptionHandlerConfigurations, forwarderConfigurations);
+ final GroupValidationResult validationResult = distributionParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertEquals("", distributionParameters.getName());
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getReceptionHandlerType());
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getReceptionHandlerClassName(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getReceptionHandlerClassName());
+ assertEquals(
+ receptionHandlerParameters.get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters(),
+ distributionParameters.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getPluginHandlerParameters());
+ assertTrue(validationResult.getResult().contains(
+ "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
+ }
+
+ @Test
+ public void testDistributionParameterGroup_NullReceptionHandlerParameters() {
+ final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations =
+ commonTestData.getReceptionHandlerConfigurationParameters(false);
+ final Map<String, ArtifactForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getArtifactForwarderConfigurationParameters(false);
+ try {
+ final DistributionParameterGroup distributionParameters =
+ new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, null,
+ receptionHandlerConfigurations, forwarderConfigurations);
+ distributionParameters.validate();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("map parameter \"receptionHandlerParameters\" is null"));
+ }
+
+ }
+
+ @Test
+ public void testDistributionParameterGroup_EmptyReceptionHandlerParameters() {
+ final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(false);
+ final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
+ commonTestData.getReceptionHandlerParameters(true);
+ final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations =
+ commonTestData.getReceptionHandlerConfigurationParameters(false);
+ final Map<String, ArtifactForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getArtifactForwarderConfigurationParameters(false);
+ final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
+ CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters,
+ receptionHandlerConfigurations, forwarderConfigurations);
+ distributionParameters.validate();
+ final GroupValidationResult result = distributionParameters.validate();
+ assertFalse(result.isValid());
+ assertTrue(result.getResult().endsWith("must have at least one reception handler\n"));
+ }
+
+ @Test
+ public void testDistributionParameterGroup_EmptyRestServerParameters() {
+ final RestServerParameters restServerParameters = commonTestData.getRestServerParameters(true);
+ final Map<String, ReceptionHandlerParameters> receptionHandlerParameters =
+ commonTestData.getReceptionHandlerParameters(false);
+ final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurations =
+ commonTestData.getReceptionHandlerConfigurationParameters(false);
+ final Map<String, ArtifactForwarderConfigurationParameterGroup> forwarderConfigurations =
+ commonTestData.getArtifactForwarderConfigurationParameters(false);
+
+ final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(
+ CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters,
+ receptionHandlerConfigurations, forwarderConfigurations);
+ final GroupValidationResult validationResult = distributionParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("\"org.onap.policy.distribution.main.parameters.RestServerParameters\" INVALID, "
+ + "parameter group has status INVALID"));
+ }
+}
diff --git a/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java
new file mode 100644
index 0000000..17faf33
--- /dev/null
+++ b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java
@@ -0,0 +1,377 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+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.DummyArtifactForwarderParameterGroup;
+
+/**
+ * Class to perform unit test of DistributionParameterHandler.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestDistributionParameterHandler {
+ @Test
+ public void testParameterHandlerNoParameterFile() throws PolicyDistributionException {
+ final String[] noArgumentString =
+ { "-c", "parameters/NoParameterFile.json" };
+
+ final DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("FileNotFoundException"));
+ }
+ }
+
+ @Test
+ public void testParameterHandlerEmptyParameters() throws PolicyDistributionException {
+ final String[] emptyArgumentString =
+ { "-c", "parameters/EmptyParameters.json" };
+
+ final DistributionCommandLineArguments emptyArguments = new DistributionCommandLineArguments();
+ emptyArguments.parse(emptyArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(emptyArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("no parameters found in \"parameters/EmptyParameters.json\"", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerBadParameters() throws PolicyDistributionException {
+ final String[] badArgumentString =
+ { "-c", "parameters/BadParameters.json" };
+
+ final DistributionCommandLineArguments badArguments = new DistributionCommandLineArguments();
+ badArguments.parse(badArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(badArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("error reading parameters from \"parameters/BadParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerInvalidParameters() throws PolicyDistributionException {
+ final String[] invalidArgumentString =
+ { "-c", "parameters/InvalidParameters.json" };
+
+ final DistributionCommandLineArguments invalidArguments = new DistributionCommandLineArguments();
+ invalidArguments.parse(invalidArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(invalidArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("error reading parameters from \"parameters/InvalidParameters.json\"\n"
+ + "(JsonSyntaxException):java.lang.IllegalStateException: "
+ + "Expected a string but was BEGIN_ARRAY at line 2 column 15 path $.name", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerNoParameters() throws PolicyDistributionException {
+ final String[] noArgumentString =
+ { "-c", "parameters/NoParameters.json" };
+
+ final DistributionCommandLineArguments noArguments = new DistributionCommandLineArguments();
+ noArguments.parse(noArgumentString);
+
+ try {
+ new DistributionParameterHandler().getParameters(noArguments);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("map parameter \"receptionHandlerParameters\" is null", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParameterHandlerMinumumParameters() throws PolicyDistributionException {
+ final String[] minArgumentString =
+ { "-c", "parameters/MinimumParameters.json" };
+
+ final DistributionCommandLineArguments minArguments = new DistributionCommandLineArguments();
+ minArguments.parse(minArgumentString);
+
+ //final DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(minArguments);
+ //assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, parGroup.getName());
+ }
+
+ @Test
+ public void testDistributionParameterGroup() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters.json" };
+
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ arguments.parse(distributionConfigParameters);
+
+ final DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(arguments);
+ assertTrue(arguments.checkSetConfigurationFilePath());
+ assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, parGroup.getName());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, parGroup.getReceptionHandlerParameters()
+ .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType());
+ assertEquals(CommonTestData.FORWARDER_TYPE,
+ parGroup.getReceptionHandlerParameters().get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY)
+ .getPluginHandlerParameters().getArtifactForwarders()
+ .get(CommonTestData.DUMMY_ENGINE_FORWARDER_KEY).getForwarderType());
+ assertEquals(CommonTestData.FORWARDER_HOST,
+ ((DummyArtifactForwarderParameterGroup) parGroup.getArtifactForwarderConfigurationParameters()
+ .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" };
+
+ 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(
+ "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_NoReceptionHandler() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_NoReceptionHandler.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("map parameter \"receptionHandlerParameters\" is null"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_EmptyReceptionHandler() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_EmptyReceptionHandler.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("must have at least one reception handler\n"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_NoArtifactForwarder() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_NoArtifactForwarder.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("map parameter \"artifactForwarders\" is null"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_EmptyArtifactForwarder() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_EmptyArtifactForwarder.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) {
+ System.out.println("libo result is " + e.getMessage());
+ assertTrue(e.getMessage().endsWith("must have at least one policy forwarder\n"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidReceptionHandlerParameters()
+ throws PolicyDistributionException, IOException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.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) {
+ final String expectedResult = new String(Files.readAllBytes(
+ Paths.get("src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt")))
+ .replaceAll("\\s+", "");
+ assertEquals(expectedResult, e.getMessage().replaceAll("\\s+", ""));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidRestServerParameters()
+ throws PolicyDistributionException, IOException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidRestServerParameters.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) {
+ final String expectedResult = new String(Files.readAllBytes(
+ Paths.get("src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt")))
+ .replaceAll("\\s+", "");
+ assertEquals(expectedResult, e.getMessage().replaceAll("\\s+", ""));
+ }
+ }
+
+ @Test
+ public void testDistributionVersion() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-v" };
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ final String version = arguments.parse(distributionConfigParameters);
+ assertTrue(version.startsWith("ONAP Policy Framework Distribution Service"));
+ }
+
+ @Test
+ public void testDistributionHelp() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-h" };
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ final String help = arguments.parse(distributionConfigParameters);
+ assertTrue(help.startsWith("usage:"));
+ }
+
+ @Test
+ public void testDistributionInvalidOption() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-d" };
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ try {
+ arguments.parse(distributionConfigParameters);
+ } catch (final Exception exp) {
+ assertTrue(exp.getMessage().startsWith("invalid command line arguments specified"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_InvalidReceptionHandlerClass() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidReceptionHandlerClass.json" };
+
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ arguments.parse(distributionConfigParameters);
+
+ try {
+ new DistributionParameterHandler().getParameters(arguments);
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("could not find class"));
+ }
+ }
+
+ @Test
+ public void testDistributionParameterGroup_EmptyReceptionHandlerClass() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_EmptyReceptionHandlerClass.json" };
+
+ final DistributionCommandLineArguments arguments = new DistributionCommandLineArguments();
+ arguments.parse(distributionConfigParameters);
+
+ try {
+ new DistributionParameterHandler().getParameters(arguments);
+ } catch (final Exception e) {
+ assertTrue(e.getMessage().contains("invalid in JSON file"));
+ }
+ }
+
+}
diff --git a/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
new file mode 100644
index 0000000..6df7705
--- /dev/null
+++ b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java
@@ -0,0 +1,60 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+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.ArtifactForwarderParameters;
+import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
+
+/**
+ * Class to perform unit test of PluginHandlerParameters.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestPluginHandlerParameters {
+ CommonTestData commonTestData = new CommonTestData();
+
+ @Test
+ public void testPluginHandlerParameters() {
+ final Map<String, ArtifactForwarderParameters> policyForwarders = commonTestData.getArtifactForwarders(false);
+ final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyForwarders);
+ final GroupValidationResult validationResult = pHParameters.validate();
+ assertEquals(policyForwarders.get(CommonTestData.DUMMY_ENGINE_FORWARDER_KEY),
+ pHParameters.getArtifactForwarders().get(CommonTestData.DUMMY_ENGINE_FORWARDER_KEY));
+ assertTrue(validationResult.isValid());
+ }
+
+ @Test
+ public void testPluginHandlerParameters_EmptyArtifactForwarders() {
+ final Map<String, ArtifactForwarderParameters> policyForwarders = commonTestData.getArtifactForwarders(true);
+ final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyForwarders);
+ GroupValidationResult result = pHParameters.validate();
+ assertFalse(result.isValid());
+ assertTrue(result.getResult().endsWith("must have at least one policy forwarder\n"));
+ }
+}
diff --git a/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java
new file mode 100644
index 0000000..2dde966
--- /dev/null
+++ b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java
@@ -0,0 +1,153 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters;
+import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters;
+
+/**
+ * Class to perform unit test of ReceptionHandlerParameters.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestReceptionHandlerParameters {
+ CommonTestData commonTestData = new CommonTestData();
+
+ @Test
+ public void testReceptionHandlerParameters() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+ final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(
+ CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME,
+ CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName());
+ assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS,
+ rHParameters.getReceptionHandlerConfigurationName());
+ assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
+ assertTrue(validationResult.isValid());
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_NullReceptionHandlerType() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+ final ReceptionHandlerParameters rHParameters =
+ new ReceptionHandlerParameters(null, CommonTestData.RECEPTION_HANDLER_CLASS_NAME,
+ CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals(null, rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName());
+ assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS,
+ rHParameters.getReceptionHandlerConfigurationName());
+ assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"receptionHandlerType\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "must be a non-blank string"));
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_NullReceptionHandlerClassName() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+ final ReceptionHandlerParameters rHParameters =
+ new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, null,
+ CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
+ assertEquals(null, rHParameters.getReceptionHandlerClassName());
+ assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS,
+ rHParameters.getReceptionHandlerConfigurationName());
+ assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"receptionHandlerClassName\" type \"java.lang.String\" value \"null\" INVALID, "
+ + "must be a non-blank string containing full class name " + "of the reception handler"));
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_EmptyReceptionHandlerType() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+ final ReceptionHandlerParameters rHParameters =
+ new ReceptionHandlerParameters("", CommonTestData.RECEPTION_HANDLER_CLASS_NAME,
+ CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals("", rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName());
+ assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"receptionHandlerType\" type \"java.lang.String\" value \"\" INVALID, "
+ + "must be a non-blank string"));
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_EmptyReceptionHandlerClassName() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+ final ReceptionHandlerParameters rHParameters =
+ new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, "",
+ CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
+ assertEquals("", rHParameters.getReceptionHandlerClassName());
+ assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS,
+ rHParameters.getReceptionHandlerConfigurationName());
+ assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("field \"receptionHandlerClassName\" type \"java.lang.String\" value \"\" INVALID, "
+ + "must be a non-blank string containing full class name " + "of the reception handler"));
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_EmptyPluginHandler() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(true);
+ final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(
+ CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME,
+ CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
+ GroupValidationResult result = rHParameters.validate();
+ assertFalse(result.isValid());
+ assertTrue(result.getResult().endsWith("must have at least one policy forwarder\n"));
+ }
+
+ @Test
+ public void testReceptionHandlerParameters_InvalidReceptionHandlerClass() {
+ final PluginHandlerParameters pHParameters = commonTestData.getPluginHandlerParameters(false);
+
+ final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(
+ CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid",
+ CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters);
+ final GroupValidationResult validationResult = rHParameters.validate();
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid",
+ rHParameters.getReceptionHandlerClassName());
+ assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS,
+ rHParameters.getReceptionHandlerConfigurationName());
+ assertEquals(pHParameters, rHParameters.getPluginHandlerParameters());
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult().contains("reception handler class not found in classpath"));
+ }
+}
diff --git a/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
new file mode 100644
index 0000000..a6d04e5
--- /dev/null
+++ b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/startstop/TestDistributionActivator.java
@@ -0,0 +1,68 @@
+/*-
+ * ============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.startstop;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+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.DummyArtifactForwarderParameterGroup;
+
+/**
+ * Class to perform unit test of DistributionActivator.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestDistributionActivator {
+
+ @Test
+ public void testDistributionActivator() throws PolicyDistributionException {
+ final String[] distributionConfigParameters = {"-c", "parameters/DistributionConfigParameters.json"};
+
+ final DistributionCommandLineArguments arguments =
+ new DistributionCommandLineArguments(distributionConfigParameters);
+
+ final DistributionParameterGroup parGroup = new DistributionParameterHandler().getParameters(arguments);
+
+ final DistributionActivator activator = new DistributionActivator(parGroup);
+ activator.initialize();
+ assertTrue(activator.getParameterGroup().isValid());
+ assertTrue(DistributionActivator.isAlive());
+ assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, activator.getParameterGroup().getName());
+ assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE,
+ activator.getParameterGroup().getReceptionHandlerParameters()
+ .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getReceptionHandlerType());
+ assertEquals(CommonTestData.FORWARDER_TYPE,
+ activator.getParameterGroup().getReceptionHandlerParameters()
+ .get(CommonTestData.DUMMY_RECEPTION_HANDLER_KEY).getPluginHandlerParameters()
+ .getArtifactForwarders().get(CommonTestData.DUMMY_ENGINE_FORWARDER_KEY).getForwarderType());
+ assertEquals(DummyArtifactForwarderParameterGroup.class,
+ activator.getParameterGroup().getArtifactForwarderConfigurationParameters()
+ .get(CommonTestData.FORWARDER_CONFIGURATION_PARAMETERS).getClass());
+ activator.terminate();
+ assertFalse(DistributionActivator.isAlive());
+ }
+}
diff --git a/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
new file mode 100644
index 0000000..e1c5d22
--- /dev/null
+++ b/artifactbroker/main/src/test/java/org/onap/policy/distribution/main/startstop/TestMain.java
@@ -0,0 +1,77 @@
+/*-
+ * ============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.startstop;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.distribution.main.PolicyDistributionException;
+import org.onap.policy.distribution.main.parameters.CommonTestData;
+
+/**
+ * Class to perform unit test of Main.
+ *
+ * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com)
+ */
+public class TestMain {
+
+ @Test
+ public void testMain() throws PolicyDistributionException {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters.json" };
+ final Main main = new Main(distributionConfigParameters);
+ assertTrue(main.getParameters().isValid());
+ assertEquals(CommonTestData.DISTRIBUTION_GROUP_NAME, main.getParameters().getName());
+ main.shutdown();
+ }
+
+ @Test
+ public void testMain_NoArguments() {
+ final String[] distributionConfigParameters =
+ {};
+ final Main main = new Main(distributionConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+
+ @Test
+ public void testMain_InvalidArguments() {
+ final String[] distributionConfigParameters =
+ { "parameters/DistributionConfigParameters.json" };
+ final Main main = new Main(distributionConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+
+ @Test
+ public void testMain_Help() {
+ final String[] distributionConfigParameters =
+ { "-h" };
+ Main.main(distributionConfigParameters);
+ }
+
+ @Test
+ public void testMain_InvalidParameters() {
+ final String[] distributionConfigParameters =
+ { "-c", "parameters/DistributionConfigParameters_InvalidName.json" };
+ final Main main = new Main(distributionConfigParameters);
+ assertTrue(main.getParameters() == null);
+ }
+}
diff --git a/artifactbroker/main/src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt b/artifactbroker/main/src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt
new file mode 100644
index 0000000..392f845
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt
@@ -0,0 +1,17 @@
+validation error(s) on parameters from "parameters/DistributionConfigParameters_InvalidDecoderAndForwarderParameters.json"
+parameter group "SDCDistributionGroup" type "org.onap.policy.distribution.main.parameters.DistributionParameterGroup" INVALID, parameter group has status INVALID
+ parameter group map "receptionHandlerParameters" INVALID, parameter group has status INVALID
+ parameter group "null_DummyReceptionHandler" type "org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters" INVALID, parameter group has status INVALID
+ parameter group "null_PluginHandler" type "org.onap.policy.distribution.reception.parameters.PluginHandlerParameters" INVALID, parameter group has status INVALID
+ parameter group map "policyDecoders" INVALID, parameter group has status INVALID
+ parameter group "" type "org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters" INVALID, parameter group has status INVALID
+ field "decoderType" type "java.lang.String" value "" INVALID, must be a non-blank string
+ field "decoderClassName" type "java.lang.String" value "org.onap.policy.distribution.main.testclasses.PolicyDecoderApexPdpa" INVALID, policy decoder class not found in classpath
+ parameter group "DROOLS" type "org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters" INVALID, parameter group has status INVALID
+ field "decoderClassName" type "java.lang.String" value "" INVALID, must be a non-blank string containing full class name of the decoder
+ parameter group map "policyForwarders" INVALID, parameter group has status INVALID
+ parameter group "" type "org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters" INVALID, parameter group has status INVALID
+ field "forwarderType" type "java.lang.String" value "" INVALID, must be a non-blank string
+ field "forwarderClassName" type "java.lang.String" value "org.onap.policy.distribution.main.testclasses.PapStandalonePolicyForwarder" INVALID, policy forwarder class not found in classpath
+ parameter group "PAPEngineForwarder" type "org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters" INVALID, parameter group has status INVALID
+ field "forwarderClassName" type "java.lang.String" value "" INVALID, must be a non-blank string containing full class name of the forwarder \ No newline at end of file
diff --git a/artifactbroker/main/src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt b/artifactbroker/main/src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt
new file mode 100644
index 0000000..cec33d0
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt
@@ -0,0 +1,6 @@
+validation error(s) on parameters from "parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json"
+parameter group "SDCDistributionGroup" type "org.onap.policy.distribution.main.parameters.DistributionParameterGroup" INVALID, parameter group has status INVALID
+ parameter group map "receptionHandlerParameters" INVALID, parameter group has status INVALID
+ parameter group "null_" type "org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters" INVALID, parameter group has status INVALID
+ field "receptionHandlerType" type "java.lang.String" value "" INVALID, must be a non-blank string
+ field "receptionHandlerClassName" type "java.lang.String" value "org.onap.policy.distribution.main.testclasses.InvalidSdcReceptionHandler" INVALID, reception handler class not found in classpath
diff --git a/artifactbroker/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt b/artifactbroker/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt
new file mode 100644
index 0000000..ceb195a
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt
@@ -0,0 +1,7 @@
+validation error(s) on parameters from "parameters/DistributionConfigParameters_InvalidRestServerParameters.json"
+parameter group "SDCDistributionGroup" type "org.onap.policy.distribution.main.parameters.DistributionParameterGroup" INVALID, parameter group has status INVALID
+ parameter group "null" type "org.onap.policy.distribution.main.parameters.RestServerParameters" INVALID, parameter group has status INVALID
+ field "host" type "java.lang.String" value "" INVALID, must be a non-blank string containing hostname/ipaddress of the distribution rest server
+ field "port" type "int" value "-1" INVALID, must be a positive integer containing port of the distribution rest server
+ field "userName" type "java.lang.String" value "" INVALID, must be a non-blank string containing userName for distribution rest server credentials
+ field "password" type "java.lang.String" value "" INVALID, must be a non-blank string containing password for distribution rest server credentials
diff --git a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyArtifactForwarder.json b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyArtifactForwarder.json
new file mode 100644
index 0000000..4318c1e
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyArtifactForwarder.json
@@ -0,0 +1,43 @@
+{
+ "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",
+ "receptionHandlerConfigurationName":"dummyReceptionHandlerConfiguration",
+ "pluginHandlerParameters":{
+ "artifactForwarders":{
+ }
+ }
+ }
+ },
+ "receptionHandlerConfigurationParameters":{
+ "dummyReceptionHandlerConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup",
+ "parameters":{
+ "myStringParameter": "stringValue",
+ "myIntegerParameter":20,
+ "myBooleanParameter": true
+ }
+ }
+ },
+ "artifactForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
+ }
+}
diff --git a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandler.json b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandler.json
index c1535e0..39a04d8 100644
--- a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandler.json
+++ b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandler.json
@@ -18,9 +18,9 @@
}
}
},
- "policyForwarderConfigurationParameters":{
+ "artifactForwarderConfigurationParameters":{
"dummyConfiguration":{
- "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup",
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup",
"parameters":{
"useHttps": false,
"hostname": "192.168.99.100",
diff --git a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandlerClass.json b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandlerClass.json
new file mode 100644
index 0000000..099de71
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_EmptyReceptionHandlerClass.json
@@ -0,0 +1,48 @@
+{
+ "name":"SDCDistributionGroup",
+ "restServerParameters":{
+ "host":"0.0.0.0",
+ "port":6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34"
+ },
+ "receptionHandlerParameters":{
+ "DummyReceptionHandler":{
+ "receptionHandlerType":"",
+ "receptionHandlerClassName":"org.onap.policy.distribution.main.testclasses.InvalidSdcReceptionHandler",
+ "receptionHandlerConfigurationName":"dummyReceptionHandlerConfiguration",
+ "pluginHandlerParameters":{
+ "artifactForwarders":{
+ "DummyForwarder":{
+ "forwarderType":"DummyForwarder",
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
+ }
+ }
+ }
+ }
+ },
+ "receptionHandlerConfigurationParameters":{
+ "dummyReceptionHandlerConfiguration":{
+ "parameterClassName":"",
+ "parameters":{
+ "myStringParameter": "stringValue",
+ "myIntegerParameter":20,
+ "myBooleanParameter": true
+ }
+ }
+ },
+ "artifactForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
+ }
+}
diff --git a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidForwarderConfigurationClassName.json b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidForwarderConfigurationClassName.json
new file mode 100644
index 0000000..b70fdaa
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidForwarderConfigurationClassName.json
@@ -0,0 +1,48 @@
+{
+ "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",
+ "receptionHandlerConfigurationName":"dummyReceptionHandlerConfiguration",
+ "pluginHandlerParameters":{
+ "artifactForwarders":{
+ "DummyForwarder":{
+ "forwarderType":"DummyForwarder",
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarder",
+ "forwarderConfigurationParameters": "dummyConfiguration"
+ }
+ }
+ }
+ }
+ },
+ "receptionHandlerConfigurationParameters":{
+ "dummyReceptionHandlerConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup",
+ "parameters":{
+ "myStringParameter": "stringValue",
+ "myIntegerParameter":20,
+ "myBooleanParameter": true
+ }
+ }
+ },
+ "artifactForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
+ }
+}
diff --git a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidName.json b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidName.json
new file mode 100644
index 0000000..6bbecad
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidName.json
@@ -0,0 +1,48 @@
+{
+ "name":" ",
+ "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",
+ "receptionHandlerConfigurationName":"dummyReceptionHandlerConfiguration",
+ "pluginHandlerParameters":{
+ "artifactForwarders":{
+ "DummyForwarder":{
+ "forwarderType":"DummyForwarder",
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
+ }
+ }
+ }
+ }
+ },
+ "receptionHandlerConfigurationParameters":{
+ "dummyReceptionHandlerConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup",
+ "parameters":{
+ "myStringParameter": "stringValue",
+ "myIntegerParameter":20,
+ "myBooleanParameter": true
+ }
+ }
+ },
+ "artifactForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
+ }
+}
diff --git a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerClass.json b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerClass.json
new file mode 100644
index 0000000..2def59a
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerClass.json
@@ -0,0 +1,48 @@
+{
+ "name":"SDCDistributionGroup",
+ "restServerParameters":{
+ "host":"0.0.0.0",
+ "port":6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34"
+ },
+ "receptionHandlerParameters":{
+ "DummyReceptionHandler":{
+ "receptionHandlerType":"",
+ "receptionHandlerClassName":"org.onap.policy.distribution.main.testclasses.InvalidSdcReceptionHandler",
+ "receptionHandlerConfigurationName":"dummyReceptionHandlerConfiguration",
+ "pluginHandlerParameters":{
+ "artifactForwarders":{
+ "DummyForwarder":{
+ "forwarderType":"DummyForwarder",
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
+ }
+ }
+ }
+ }
+ },
+ "receptionHandlerConfigurationParameters":{
+ "dummyReceptionHandlerConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.InvalidReceptionHandlerParameterGroup",
+ "parameters":{
+ "myStringParameter": "stringValue",
+ "myIntegerParameter":20,
+ "myBooleanParameter": true
+ }
+ }
+ },
+ "artifactForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
+ }
+}
diff --git a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json
new file mode 100644
index 0000000..d3ad8b2
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidReceptionHandlerParameters.json
@@ -0,0 +1,48 @@
+{
+ "name":"SDCDistributionGroup",
+ "restServerParameters":{
+ "host":"0.0.0.0",
+ "port":6969,
+ "userName":"healthcheck",
+ "password":"zb!XztG34"
+ },
+ "receptionHandlerParameters":{
+ "DummyReceptionHandler":{
+ "receptionHandlerType":"",
+ "receptionHandlerClassName":"org.onap.policy.distribution.main.testclasses.InvalidSdcReceptionHandler",
+ "receptionHandlerConfigurationName":"dummyReceptionHandlerConfiguration",
+ "pluginHandlerParameters":{
+ "artifactForwarders":{
+ "DummyForwarder":{
+ "forwarderType":"DummyForwarder",
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
+ }
+ }
+ }
+ }
+ },
+ "receptionHandlerConfigurationParameters":{
+ "dummyReceptionHandlerConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup",
+ "parameters":{
+ "myStringParameter": "stringValue",
+ "myIntegerParameter":20,
+ "myBooleanParameter": true
+ }
+ }
+ },
+ "artifactForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
+ }
+}
diff --git a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidRestServerParameters.json b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidRestServerParameters.json
new file mode 100644
index 0000000..a37ca47
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_InvalidRestServerParameters.json
@@ -0,0 +1,48 @@
+{
+ "name":"SDCDistributionGroup",
+ "restServerParameters":{
+ "host":"",
+ "port":-1,
+ "userName":"",
+ "password":""
+ },
+ "receptionHandlerParameters":{
+ "DummyReceptionHandler":{
+ "receptionHandlerType":"DummyReceptionHandler",
+ "receptionHandlerClassName":"org.onap.policy.distribution.main.testclasses.DummyReceptionHandler",
+ "receptionHandlerConfigurationName":"dummyReceptionHandlerConfiguration",
+ "pluginHandlerParameters":{
+ "artifactForwarders":{
+ "DummyForwarder":{
+ "forwarderType":"DummyForwarder",
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarder",
+ "forwarderConfigurationName": "dummyConfiguration"
+ }
+ }
+ }
+ }
+ },
+ "receptionHandlerConfigurationParameters":{
+ "dummyReceptionHandlerConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup",
+ "parameters":{
+ "myStringParameter": "stringValue",
+ "myIntegerParameter":20,
+ "myBooleanParameter": true
+ }
+ }
+ },
+ "artifactForwarderConfigurationParameters":{
+ "dummyConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarderParameterGroup",
+ "parameters":{
+ "useHttps": false,
+ "hostname": "192.168.99.100",
+ "port": 8081,
+ "userName": "user",
+ "password": "pw123",
+ "isManaged": true
+ }
+ }
+ }
+}
diff --git a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_NoPolicyForwarder.json b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_NoArtifactForwarder.json
index abd0d6d..abd0d6d 100644
--- a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_NoPolicyForwarder.json
+++ b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_NoArtifactForwarder.json
diff --git a/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_UnknownForwarderConfigurationClassName.json b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_UnknownForwarderConfigurationClassName.json
new file mode 100644
index 0000000..2bde3c0
--- /dev/null
+++ b/artifactbroker/main/src/test/resources/parameters/DistributionConfigParameters_UnknownForwarderConfigurationClassName.json
@@ -0,0 +1,48 @@
+{
+ "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",
+ "receptionHandlerConfigurationName":"dummyReceptionHandlerConfiguration",
+ "pluginHandlerParameters":{
+ "artifactForwarders":{
+ "DummyForwarder":{
+ "forwarderType":"DummyForwarder",
+ "forwarderClassName":"org.onap.policy.distribution.main.testclasses.DummyArtifactForwarder",
+ "forwarderConfigurationParameters": "dummyConfiguration"
+ }
+ }
+ }
+ }
+ },
+ "receptionHandlerConfigurationParameters":{
+ "dummyReceptionHandlerConfiguration":{
+ "parameterClassName":"org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup",
+ "parameters":{
+ "myStringParameter": "stringValue",
+ "myIntegerParameter":20,
+ "myBooleanParameter": true
+ }
+ }
+ },
+ "artifactForwarderConfigurationParameters":{
+ "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/artifactbroker/packages/pom.xml b/artifactbroker/packages/pom.xml
index c371cad..63769f4 100644
--- a/artifactbroker/packages/pom.xml
+++ b/artifactbroker/packages/pom.xml
@@ -52,6 +52,11 @@
<artifactId>multicloud-framework-artifactbroker-reception-plugins</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.onap.multicloud.framework</groupId>
+ <artifactId>multicloud-framework-artifactbroker-forwarding-plugins</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
<build>
diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java
deleted file mode 100644
index 941cdd6..0000000
--- a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandler.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Intel Corp. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.distribution.reception.handling.sdc;
-
-import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.FileSystems;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.WatchEvent;
-import java.nio.file.WatchKey;
-import java.nio.file.WatchService;
-
-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.model.Csar;
-import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
-import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler;
-
-/**
- * Handles reception of inputs from File System which can be used to decode policies.
- */
-public class FileSystemReceptionHandler extends AbstractReceptionHandler {
- private boolean running = false;
- private static final Logger LOGGER = FlexLogger.getLogger(FileSystemReceptionHandler.class);
-
- @Override
- protected void initializeReception(final String parameterGroupName) {
- LOGGER.debug("FileSystemReceptionHandler init...");
- try {
- final FileSystemReceptionHandlerConfigurationParameterGroup handlerParameters =
- ParameterService.get(parameterGroupName);
- main(handlerParameters.getWatchPath());
- } catch (final Exception ex) {
- LOGGER.error(ex);
- }
- running = false;
- LOGGER.debug("FileSystemReceptionHandler main loop exited...");
- }
-
- @Override
- public void destroy() {
- // Tear down subscription etc
- running = false;
- }
-
- public boolean isRunning() {
- return running;
- }
-
- /**
- * Main entry point.
- *
- * @param watchPath Path to watch
- */
- public void main(String watchPath) throws IOException {
- try (final WatchService watcher = FileSystems.getDefault().newWatchService()) {
- final Path dir = Paths.get(watchPath);
- dir.register(watcher, ENTRY_CREATE);
- LOGGER.debug("Watch Service registered for dir: " + dir.getFileName());
- startMainLoop(watcher, dir);
- } catch (final InterruptedException ex) {
- LOGGER.debug(ex);
- Thread.currentThread().interrupt();
- }
- }
-
- @SuppressWarnings("unchecked")
- protected void startMainLoop(WatchService watcher, Path dir) throws InterruptedException {
- WatchKey key;
- running = true;
- while (running) {
- key = watcher.take();
-
- for (final WatchEvent<?> event : key.pollEvents()) {
- final WatchEvent<Path> ev = (WatchEvent<Path>) event;
- final Path fileName = ev.context();
- LOGGER.debug("new CSAR found: " + fileName);
- createPolicyInputAndCallHandler(dir.toString() + File.separator + fileName.toString());
- LOGGER.debug("CSAR complete: " + fileName);
- }
- final boolean valid = key.reset();
- if (!valid) {
- LOGGER.error("Watch key no longer valid!");
- break;
- }
- }
- }
-
- protected void createPolicyInputAndCallHandler(final String fileName) {
- try {
- final Csar csarObject = new Csar(fileName);
- inputReceived(csarObject);
- } catch (final PolicyDecodingException ex) {
- LOGGER.error(ex);
- }
- }
-}
diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java
deleted file mode 100644
index 37a1698..0000000
--- a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterBuilder.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Intel Corp. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.distribution.reception.handling.sdc;
-
-/**
- * This class builds an instance of {@link FileSystemReceptionHandlerConfigurationParameterGroup} class.
- *
- */
-public class FileSystemReceptionHandlerConfigurationParameterBuilder {
-
- private String watchPath;
-
- /**
- * Set watchPath to this {@link FileSystemReceptionHandlerConfigurationParameterBuilder} instance.
- *
- * @param watchPath the watchPath
- */
- public FileSystemReceptionHandlerConfigurationParameterBuilder setWatchPath(final String watchPath) {
- this.watchPath = watchPath;
- return this;
- }
-
-
- /**
- * Returns the watchPath of this {@link FileSystemReceptionHandlerConfigurationParameterBuilder} instance.
- *
- * @return the watchPath
- */
- public String getWatchPath() {
- return watchPath;
- }
-}
-
-
diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java
deleted file mode 100644
index 457cd5e..0000000
--- a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/FileSystemReceptionHandlerConfigurationParameterGroup.java
+++ /dev/null
@@ -1,84 +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.handling.sdc;
-
-import java.io.File;
-
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ValidationStatus;
-import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
-
-/**
- * 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 FileSystemReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
-
- private String watchPath;
-
- /**
- * The constructor for instantiating {@link FileSystemReceptionHandlerConfigurationParameterGroup} class.
- *
- * @param builder the SDC configuration builder
- */
- public FileSystemReceptionHandlerConfigurationParameterGroup(
- final FileSystemReceptionHandlerConfigurationParameterBuilder builder) {
- watchPath = builder.getWatchPath();
- }
-
- public String getWatchPath() {
- return watchPath;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult validationResult = new GroupValidationResult(this);
- validatePathElement(validationResult, watchPath, "watchPath");
- return validationResult;
- }
-
-
- /**
- * 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 validatePathElement(final GroupValidationResult validationResult, final String element,
- final String elementName) {
- boolean valid = false;
- if (element != null) {
- File file = new File(element);
- if (file.exists() && file.isDirectory()) {
- valid = true;
- }
- }
- if (!valid) {
- validationResult.setResult(elementName, ValidationStatus.INVALID,
- elementName + " must be a valid directory");
- }
- }
-}
-