diff options
author | 2019-04-16 08:19:04 +0800 | |
---|---|---|
committer | 2019-04-16 08:21:01 +0800 | |
commit | dc1321b4c135242c67e94f5af57d0e39866ce2d8 (patch) | |
tree | ff1bf759c068f79b54aacb3fc4b43bb192ba290b /artifactbroker/main/src/test | |
parent | 76cb15908ebfab78034aff381ba5c867b5491c05 (diff) |
add testcase to improve test coverage
. add distribution parameter test case
. remove unused FileSystem plugin
. fix pom.xml of package to include forwarding plugin
Change-Id: I531169dd4cb498ae50e4f2ef93fe3a3eecd33263
Issue-ID: MULTICLOUD-569
Signed-off-by: liboNet <libo.zhu@intel.com>
Diffstat (limited to 'artifactbroker/main/src/test')
21 files changed, 1671 insertions, 2 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 + } + } + } +} |