diff options
22 files changed, 270 insertions, 618 deletions
diff --git a/forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java b/forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java index e5c757b1..bc8041a4 100644 --- a/forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java +++ b/forwarding/src/main/java/org/onap/policy/distribution/forwarding/parameters/PolicyForwarderParameters.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -21,23 +22,25 @@ package org.onap.policy.distribution.forwarding.parameters; -import org.onap.policy.common.parameters.GroupValidationResult; +import lombok.Getter; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.BeanValidator; import org.onap.policy.common.parameters.ParameterGroup; -import org.onap.policy.common.parameters.ValidationStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.policy.common.parameters.annotations.ClassName; +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; /** * Class to hold all the policy forwarder parameters. * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ +@Getter +@NotBlank public class PolicyForwarderParameters implements ParameterGroup { - private static final Logger LOGGER = LoggerFactory.getLogger(PolicyForwarderParameters.class); - - private String forwarderType; - private String forwarderClassName; + private @NotNull String forwarderType; + private @NotNull @ClassName String forwarderClassName; private String forwarderConfigurationName; /** @@ -55,33 +58,6 @@ public class PolicyForwarderParameters implements ParameterGroup { } /** - * Return the forwarderType of this PolicyForwarderParameters instance. - * - * @return the forwarderType - */ - public String getForwarderType() { - return forwarderType; - } - - /** - * Return the forwarderClassName of this PolicyForwarderParameters instance. - * - * @return the forwarderClassName - */ - public String getForwarderClassName() { - return forwarderClassName; - } - - /** - * Return the name of the forwarder configuration of this PolicyForwarderParameters instance. - * - * @return the the name of the forwarder configuration - */ - public String getForwarderConfigurationName() { - return forwarderConfigurationName; - } - - /** * {@inheritDoc}. */ @Override @@ -101,27 +77,7 @@ public class PolicyForwarderParameters implements ParameterGroup { * {@inheritDoc}. */ @Override - public GroupValidationResult validate() { - final GroupValidationResult validationResult = new GroupValidationResult(this); - if (forwarderType == null || forwarderType.trim().length() == 0) { - validationResult.setResult("forwarderType", ValidationStatus.INVALID, "must be a non-blank string"); - } - if (forwarderClassName == null || forwarderClassName.trim().length() == 0) { - validationResult.setResult("forwarderClassName", ValidationStatus.INVALID, - "must be a non-blank string containing full class name of the forwarder"); - } else { - validatePolicyForwarderClass(validationResult); - } - return validationResult; - } - - private void validatePolicyForwarderClass(final GroupValidationResult validationResult) { - try { - Class.forName(forwarderClassName); - } catch (final ClassNotFoundException exp) { - LOGGER.trace("policy forwarder class not found in classpath", exp); - validationResult.setResult("forwarderClassName", ValidationStatus.INVALID, - "policy forwarder class not found in classpath"); - } + public BeanValidationResult validate() { + return new BeanValidator().validateTop(getClass().getSimpleName(), this); } } diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java index d568980a..b78031b7 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java +++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterGroup.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. 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. @@ -23,12 +23,14 @@ package org.onap.policy.distribution.main.parameters; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Map.Entry; +import lombok.Getter; +import lombok.Setter; import org.onap.policy.common.endpoints.parameters.RestServerParameters; -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ParameterGroup; -import org.onap.policy.common.parameters.ValidationStatus; -import org.onap.policy.common.utils.validation.ParameterValidationUtils; +import org.onap.policy.common.parameters.ParameterGroupImpl; +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Size; +import org.onap.policy.common.parameters.annotations.Valid; import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup; import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters; @@ -38,17 +40,26 @@ import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParamet * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ -public class DistributionParameterGroup implements ParameterGroup { +@Getter +@Setter +@NotNull +@NotBlank +public class DistributionParameterGroup extends ParameterGroupImpl { // @formatter:off - private String name; + @Valid private RestServerParameters restServerParameters; - private Map<String, ReceptionHandlerParameters> receptionHandlerParameters; - private Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurationParameters - = new LinkedHashMap<>(); - private Map<String, PolicyForwarderConfigurationParameterGroup> policyForwarderConfigurationParameters - = new LinkedHashMap<>(); - private Map<String, PolicyDecoderConfigurationParameterGroup> policyDecoderConfigurationParameters - = new LinkedHashMap<>(); + + @Size(min = 1) + private Map<String, @NotNull @Valid ReceptionHandlerParameters> receptionHandlerParameters; + + private Map<String, @NotNull @Valid ReceptionHandlerConfigurationParameterGroup> + receptionHandlerConfigurationParameters = new LinkedHashMap<>(); + + private Map<String, @NotNull @Valid PolicyForwarderConfigurationParameterGroup> + policyForwarderConfigurationParameters = new LinkedHashMap<>(); + + private Map<String, @NotNull @Valid PolicyDecoderConfigurationParameterGroup> + policyDecoderConfigurationParameters = new LinkedHashMap<>(); // @formatter:on /** @@ -61,162 +72,11 @@ public class DistributionParameterGroup implements ParameterGroup { final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurationParameters, final Map<String, PolicyForwarderConfigurationParameterGroup> policyForwarderConfigurationParameters, final Map<String, PolicyDecoderConfigurationParameterGroup> policyDecoderConfigurationParameters) { - this.name = name; + super(name); this.restServerParameters = restServerParameters; this.receptionHandlerParameters = receptionHandlerParameters; this.receptionHandlerConfigurationParameters = receptionHandlerConfigurationParameters; this.policyForwarderConfigurationParameters = policyForwarderConfigurationParameters; this.policyDecoderConfigurationParameters = policyDecoderConfigurationParameters; } - - /** - * Return the name of this parameter group instance. - * - * @return name the parameter group name - */ - @Override - public String getName() { - return name; - } - - /** - * Set the name of this parameter group instance. - * - * @param name the parameter group name - */ - @Override - public void setName(final String name) { - this.name = name; - } - - /** - * Return the receptionHandlerParameters of this parameter group instance. - * - * @return the receptionHandlerParameters - */ - public Map<String, ReceptionHandlerParameters> getReceptionHandlerParameters() { - return receptionHandlerParameters; - } - - /** - * Return the restServerParameters of this parameter group instance. - * - * @return the restServerParameters - */ - public RestServerParameters getRestServerParameters() { - return restServerParameters; - } - - /** - * Gets the reception handler configuration parameter map. - * - * @return the reception handler configuration parameter map - */ - public Map<String, ReceptionHandlerConfigurationParameterGroup> getReceptionHandlerConfigurationParameters() { - return receptionHandlerConfigurationParameters; - } - - /** - * Sets the reception handler configuration parameter map. - * - * @param receptionHandlerConfigurationParameters the reception handler configuration parameters - */ - public void setReceptionHandlerConfigurationParameters( - final Map<String, ReceptionHandlerConfigurationParameterGroup> receptionHandlerConfigurationParameters) { - this.receptionHandlerConfigurationParameters = receptionHandlerConfigurationParameters; - } - - /** - * Gets the policy forwarder configuration parameter map. - * - * @return the policy forwarder configuration parameter map - */ - public Map<String, PolicyForwarderConfigurationParameterGroup> getPolicyForwarderConfigurationParameters() { - return policyForwarderConfigurationParameters; - } - - /** - * Sets the policy forwarder configuration parameter map. - * - * @param policyForwarderConfigurationParameters the policy forwarder configuration parameters - */ - public void setPolicyForwarderConfigurationParameters( - final Map<String, PolicyForwarderConfigurationParameterGroup> policyForwarderConfigurationParameters) { - this.policyForwarderConfigurationParameters = policyForwarderConfigurationParameters; - } - - /** - * Returns the policy decoder configuration parameter map. - * - * @return the policyDecoderConfigurationParameters - */ - public Map<String, PolicyDecoderConfigurationParameterGroup> getPolicyDecoderConfigurationParameters() { - return policyDecoderConfigurationParameters; - } - - /** - * Set the policy decoder configuration parameter map. - * - * @param policyDecoderConfigurationParameters the policyDecoderConfigurationParameters to set - */ - public void setPolicyDecoderConfigurationParameters( - final Map<String, PolicyDecoderConfigurationParameterGroup> policyDecoderConfigurationParameters) { - this.policyDecoderConfigurationParameters = policyDecoderConfigurationParameters; - } - - /** - * Validate the parameter group. - * - * @return the result of the validation - */ - @Override - public GroupValidationResult validate() { - final GroupValidationResult validationResult = new GroupValidationResult(this); - if (!ParameterValidationUtils.validateStringParameter(name)) { - validationResult.setResult("name", ValidationStatus.INVALID, "must be a non-blank string"); - } - if (restServerParameters == null) { - validationResult.setResult("restServerParameters", ValidationStatus.INVALID, - "must have restServerParameters to configure distribution rest server"); - } else { - validationResult.setResult("restServerParameters", restServerParameters.validate()); - } - validateReceptionHandlers(validationResult); - validateForwarderConfigurations(validationResult); - validateDecoderConfigurations(validationResult); - return validationResult; - } - - private void validateReceptionHandlers(final GroupValidationResult validationResult) { - if (receptionHandlerParameters == null || receptionHandlerParameters.size() == 0) { - validationResult.setResult("receptionHandlerParameters", ValidationStatus.INVALID, - "must have at least one reception handler"); - } else { - for (final Entry<String, ReceptionHandlerParameters> nestedGroupEntry : receptionHandlerParameters - .entrySet()) { - validationResult.setResult("receptionHandlerParameters", nestedGroupEntry.getKey(), - nestedGroupEntry.getValue().validate()); - } - } - } - - private void validateForwarderConfigurations(final GroupValidationResult validationResult) { - // @formatter:off - for (final Entry<String, PolicyForwarderConfigurationParameterGroup> configurationParameters : - policyForwarderConfigurationParameters.entrySet()) { - validationResult.setResult("policyForwarderConfigurationParameters", configurationParameters.getKey(), - configurationParameters.getValue().validate()); - } - // @formatter:on - } - - private void validateDecoderConfigurations(final GroupValidationResult validationResult) { - // @formatter:off - for (final Entry<String, PolicyDecoderConfigurationParameterGroup> configurationParameters : - policyDecoderConfigurationParameters.entrySet()) { - validationResult.setResult("policyDecoderConfigurationParameters", configurationParameters.getKey(), - configurationParameters.getValue().validate()); - } - // @formatter:on - } } diff --git a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java index ea7cde6d..7807dcc1 100644 --- a/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java +++ b/main/src/main/java/org/onap/policy/distribution/main/parameters/DistributionParameterHandler.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2020 AT&T Inc. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. 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. @@ -25,7 +25,7 @@ package org.onap.policy.distribution.main.parameters; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.io.FileReader; -import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.distribution.main.PolicyDistributionException; import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments; import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; @@ -79,7 +79,7 @@ public class DistributionParameterHandler { } // validate the parameters - final GroupValidationResult validationResult = distributionParameterGroup.validate(); + final ValidationResult validationResult = distributionParameterGroup.validate(); if (!validationResult.isValid()) { String returnMessage = "validation error(s) on parameters from \"" + arguments.getConfigurationFilePath() + "\"\n"; diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java index fb5dfbd4..0b5bfcb8 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterGroup.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,6 @@ package org.onap.policy.distribution.main.parameters; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -31,8 +30,7 @@ import static org.junit.Assert.assertTrue; import java.util.Map; import org.junit.Test; import org.onap.policy.common.endpoints.parameters.RestServerParameters; -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ParameterRuntimeException; +import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.distribution.main.testclasses.DummyPolicyForwarderParameterGroup; import org.onap.policy.distribution.main.testclasses.DummyReceptionHandlerParameterGroup; import org.onap.policy.distribution.reception.parameters.PolicyDecoderConfigurationParameterGroup; @@ -62,7 +60,7 @@ public class TestDistributionParameterGroup { final DistributionParameterGroup distributionParameters = new DistributionParameterGroup( CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters, receptionHandlerConfigurations, forwarderConfigurations, decoderConfigurations); - final GroupValidationResult validationResult = distributionParameters.validate(); + final ValidationResult validationResult = distributionParameters.validate(); assertTrue(validationResult.isValid()); assertEquals(restServerParameters.getHost(), distributionParameters.getRestServerParameters().getHost()); assertEquals(restServerParameters.getPort(), distributionParameters.getRestServerParameters().getPort()); @@ -116,7 +114,7 @@ public class TestDistributionParameterGroup { final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(null, restServerParameters, receptionHandlerParameters, receptionHandlerConfigurations, forwarderConfigurations, decoderConfigurations); - final GroupValidationResult validationResult = distributionParameters.validate(); + final ValidationResult validationResult = distributionParameters.validate(); assertFalse(validationResult.isValid()); assertEquals(null, distributionParameters.getName()); assertEquals( @@ -132,8 +130,7 @@ public class TestDistributionParameterGroup { 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")); + assertThat(validationResult.getResult()).contains("\"name\" value \"null\" INVALID, is null"); } @Test @@ -151,7 +148,7 @@ public class TestDistributionParameterGroup { final DistributionParameterGroup distributionParameters = new DistributionParameterGroup("", restServerParameters, receptionHandlerParameters, receptionHandlerConfigurations, forwarderConfigurations, decoderConfigurations); - final GroupValidationResult validationResult = distributionParameters.validate(); + final ValidationResult validationResult = distributionParameters.validate(); assertFalse(validationResult.isValid()); assertEquals("", distributionParameters.getName()); assertEquals( @@ -167,8 +164,7 @@ public class TestDistributionParameterGroup { 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")); + assertThat(validationResult.getResult()).contains("\"name\" value \"\" INVALID, is blank"); } @Test @@ -182,9 +178,9 @@ public class TestDistributionParameterGroup { commonTestData.getPolicyDecoderConfigurationParameters(false); final DistributionParameterGroup distributionParameters = new DistributionParameterGroup(CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, null, - receptionHandlerConfigurations, forwarderConfigurations, decoderConfigurations); - assertThatThrownBy(distributionParameters::validate).isInstanceOf(ParameterRuntimeException.class) - .hasMessageContaining("map parameter \"receptionHandlerParameters\" is null"); + receptionHandlerConfigurations, forwarderConfigurations, decoderConfigurations); + assertThat(distributionParameters.validate().getResult()) + .contains("\"receptionHandlerParameters\" value \"null\" INVALID, is null"); } @Test @@ -202,9 +198,9 @@ public class TestDistributionParameterGroup { CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters, receptionHandlerConfigurations, forwarderConfigurations, decoderConfigurations); distributionParameters.validate(); - final GroupValidationResult result = distributionParameters.validate(); + final ValidationResult result = distributionParameters.validate(); assertFalse(result.isValid()); - assertTrue(result.getResult().endsWith("must have at least one reception handler\n")); + assertThat(result.getResult()).contains("minimum"); } @Test @@ -222,11 +218,9 @@ public class TestDistributionParameterGroup { final DistributionParameterGroup distributionParameters = new DistributionParameterGroup( CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters, receptionHandlerConfigurations, forwarderConfigurations, decoderConfigurations); - final GroupValidationResult validationResult = distributionParameters.validate(); + final ValidationResult validationResult = distributionParameters.validate(); assertFalse(validationResult.isValid()); - assertTrue(validationResult.getResult() - .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, " - + "parameter group has status INVALID")); + assertThat(validationResult.getResult()).contains("\"RestServerParameters\" INVALID"); } @Test @@ -244,10 +238,8 @@ public class TestDistributionParameterGroup { final DistributionParameterGroup distributionParameters = new DistributionParameterGroup( CommonTestData.DISTRIBUTION_GROUP_NAME, restServerParameters, receptionHandlerParameters, receptionHandlerConfigurations, forwarderConfigurations, decoderConfigurations); - final GroupValidationResult validationResult = distributionParameters.validate(); + final ValidationResult validationResult = distributionParameters.validate(); assertFalse(validationResult.isValid()); - assertThat(validationResult.getResult()) - .contains("parameter group \"UNDEFINED\" INVALID, " - + "must have restServerParameters to configure distribution rest server"); + assertThat(validationResult.getResult()).contains("\"restServerParameters\" value \"null\" INVALID, is null"); } } diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java index dcafe68c..b83b3fc9 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestDistributionParameterHandler.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020-2021 Nordix Foundation. - * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. 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. @@ -30,7 +30,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import org.junit.Test; -import org.onap.policy.common.parameters.ParameterRuntimeException; import org.onap.policy.common.utils.cmd.CommandLineException; import org.onap.policy.distribution.main.PolicyDistributionException; import org.onap.policy.distribution.main.startstop.DistributionCommandLineArguments; @@ -72,8 +71,8 @@ public class TestDistributionParameterHandler { @Test public void testParameterHandlerNoParameters() throws PolicyDistributionException, CommandLineException { - verifyFailure("NoParameters.json", ParameterRuntimeException.class, - "map parameter \"receptionHandlerParameters\" is null"); + verifyFailure("NoParameters.json", PolicyDistributionException.class, + "\"receptionHandlerParameters\" value \"null\" INVALID, is null"); } @Test @@ -136,49 +135,49 @@ public class TestDistributionParameterHandler { @Test public void testDistributionParameterGroup_InvalidName() throws PolicyDistributionException, CommandLineException { verifyFailure("DistributionConfigParameters_InvalidName.json", PolicyDistributionException.class, - "field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a non-blank string"); + "\"name\" value \" \" INVALID, is blank"); } @Test public void testDistributionParameterGroup_NoReceptionHandler() throws PolicyDistributionException, CommandLineException { - verifyFailure("DistributionConfigParameters_NoReceptionHandler.json", ParameterRuntimeException.class, - "map parameter \"receptionHandlerParameters\" is null"); + verifyFailure("DistributionConfigParameters_NoReceptionHandler.json", PolicyDistributionException.class, + "\"receptionHandlerParameters\" value \"null\" INVALID, is null"); } @Test public void testDistributionParameterGroup_EmptyReceptionHandler() throws PolicyDistributionException, CommandLineException { verifyFailure("DistributionConfigParameters_EmptyReceptionHandler.json", PolicyDistributionException.class, - "must have at least one reception handler\n"); + "\"receptionHandlerParameters\" value \"{}\" INVALID, minimum number of elements: 1"); } @Test public void testDistributionParameterGroup_NoPolicyDecoder() throws PolicyDistributionException, CommandLineException { - verifyFailure("DistributionConfigParameters_NoPolicyDecoder.json", ParameterRuntimeException.class, - "map parameter \"policyDecoders\" is null"); + verifyFailure("DistributionConfigParameters_NoPolicyDecoder.json", PolicyDistributionException.class, + "\"policyDecoders\" value \"null\" INVALID, is null"); } @Test public void testDistributionParameterGroup_NoPolicyForwarder() throws PolicyDistributionException, CommandLineException { - verifyFailure("DistributionConfigParameters_NoPolicyForwarder.json", ParameterRuntimeException.class, - "map parameter \"policyForwarders\" is null"); + verifyFailure("DistributionConfigParameters_NoPolicyForwarder.json", PolicyDistributionException.class, + "\"policyForwarderConfigurationParameters\" value \"null\" INVALID, is null"); } @Test public void testDistributionParameterGroup_EmptyPolicyDecoder() throws PolicyDistributionException, CommandLineException { verifyFailure("DistributionConfigParameters_EmptyPolicyDecoder.json", PolicyDistributionException.class, - "must have at least one policy decoder\n"); + "\"policyDecoders\" value \"{}\" INVALID, minimum number of elements: 1"); } @Test public void testDistributionParameterGroup_EmptyPolicyForwarder() throws PolicyDistributionException, CommandLineException { verifyFailure("DistributionConfigParameters_EmptyPolicyForwarder.json", PolicyDistributionException.class, - "must have at least one policy forwarder\n"); + "\"policyForwarders\" value \"{}\" INVALID, minimum number of elements: 1"); } @Test diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java index 73ec0ba3..9def403d 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPluginHandlerParameters.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -21,15 +22,14 @@ package org.onap.policy.distribution.main.parameters; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.Map; import org.junit.Test; -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ParameterRuntimeException; +import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters; import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters; import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters; @@ -47,7 +47,7 @@ public class TestPluginHandlerParameters { final Map<String, PolicyDecoderParameters> policyDecoders = commonTestData.getPolicyDecoders(false); final Map<String, PolicyForwarderParameters> policyForwarders = commonTestData.getPolicyForwarders(false); final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders); - final GroupValidationResult validationResult = pHParameters.validate(); + final ValidationResult validationResult = pHParameters.validate(); assertEquals(policyDecoders.get(CommonTestData.DUMMY_DECODER_KEY), pHParameters.getPolicyDecoders().get(CommonTestData.DUMMY_DECODER_KEY)); assertEquals(policyForwarders.get(CommonTestData.DUMMY_ENGINE_FORWARDER_KEY), @@ -59,16 +59,15 @@ public class TestPluginHandlerParameters { public void testPluginHandlerParameters_NullPolicyDecoders() { final Map<String, PolicyForwarderParameters> policyForwarders = commonTestData.getPolicyForwarders(false); final PluginHandlerParameters pHParameters = new PluginHandlerParameters(null, policyForwarders); - assertThatThrownBy(pHParameters::validate).isInstanceOf(ParameterRuntimeException.class) - .hasMessage("map parameter \"policyDecoders\" is null"); + assertThat(pHParameters.validate().getResult()).contains("\"policyDecoders\" value \"null\" INVALID, is null"); } @Test public void testPluginHandlerParameters_NullPolicyForwarders() { final Map<String, PolicyDecoderParameters> policyDecoders = commonTestData.getPolicyDecoders(false); final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, null); - assertThatThrownBy(pHParameters::validate).isInstanceOf(ParameterRuntimeException.class) - .hasMessage("map parameter \"policyForwarders\" is null"); + assertThat(pHParameters.validate().getResult()) + .contains("\"policyForwarders\" value \"null\" INVALID, is null"); } @Test @@ -76,9 +75,9 @@ public class TestPluginHandlerParameters { final Map<String, PolicyDecoderParameters> policyDecoders = commonTestData.getPolicyDecoders(true); final Map<String, PolicyForwarderParameters> policyForwarders = commonTestData.getPolicyForwarders(false); final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders); - GroupValidationResult result = pHParameters.validate(); + ValidationResult result = pHParameters.validate(); assertFalse(result.isValid()); - assertTrue(result.getResult().endsWith("must have at least one policy decoder\n")); + assertThat(pHParameters.validate().getResult()).contains("\"policyDecoders\"", "minimum"); } @Test @@ -86,8 +85,8 @@ public class TestPluginHandlerParameters { final Map<String, PolicyForwarderParameters> policyForwarders = commonTestData.getPolicyForwarders(true); final Map<String, PolicyDecoderParameters> policyDecoders = commonTestData.getPolicyDecoders(false); final PluginHandlerParameters pHParameters = new PluginHandlerParameters(policyDecoders, policyForwarders); - GroupValidationResult result = pHParameters.validate(); + ValidationResult result = pHParameters.validate(); assertFalse(result.isValid()); - assertTrue(result.getResult().endsWith("must have at least one policy forwarder\n")); + assertThat(pHParameters.validate().getResult()).contains("\"policyForwarders\"", "minimum"); } } diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java index 7b9e6095..4195f1b6 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyDecoderParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -20,6 +21,7 @@ package org.onap.policy.distribution.main.parameters; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -28,7 +30,7 @@ import static org.onap.policy.distribution.main.parameters.CommonTestData.DECODE import static org.onap.policy.distribution.main.parameters.CommonTestData.DECODER_TYPE; import org.junit.Test; -import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.distribution.reception.parameters.PolicyDecoderParameters; /** @@ -42,7 +44,7 @@ public class TestPolicyDecoderParameters { public void testPolicyDecoderParameters() { final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(DECODER_TYPE, DECODER_CLASS_NAME, DECODER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pDParameters.validate(); + final ValidationResult validationResult = pDParameters.validate(); assertEquals(DECODER_TYPE, pDParameters.getDecoderType()); assertEquals(DECODER_CLASS_NAME, pDParameters.getDecoderClassName()); assertEquals(DECODER_CONFIGURATION_PARAMETERS, pDParameters.getDecoderConfigurationName()); @@ -53,75 +55,66 @@ public class TestPolicyDecoderParameters { public void testPolicyDecoderParameters_InvalidDecoderType() { final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters("", DECODER_CLASS_NAME, DECODER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pDParameters.validate(); + final ValidationResult validationResult = pDParameters.validate(); assertEquals("", pDParameters.getDecoderType()); assertEquals(DECODER_CLASS_NAME, pDParameters.getDecoderClassName()); assertFalse(validationResult.isValid()); - assertTrue(validationResult.getResult().contains( - "field \"decoderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string")); + assertThat(validationResult.getResult()).contains("\"decoderType\" value \"\" INVALID, is blank"); } @Test public void testPolicyDecoderParameters_InvalidDecoderClassName() { final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(DECODER_TYPE, "", DECODER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pDParameters.validate(); + final ValidationResult validationResult = pDParameters.validate(); assertEquals(DECODER_TYPE, pDParameters.getDecoderType()); assertEquals("", pDParameters.getDecoderClassName()); assertFalse(validationResult.isValid()); - assertTrue(validationResult.getResult() - .contains("field \"decoderClassName\" type \"java.lang.String\" value \"\" INVALID, " - + "must be a non-blank string containing full class name of the decoder")); + assertThat(validationResult.getResult()).contains("\"decoderClassName\" value \"\" INVALID, is blank"); } @Test public void testPolicyDecoderParameters_InvalidDecoderTypeAndClassName() { final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters("", "", DECODER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pDParameters.validate(); + final ValidationResult validationResult = pDParameters.validate(); assertEquals("", pDParameters.getDecoderType()); assertEquals("", pDParameters.getDecoderClassName()); assertFalse(validationResult.isValid()); - assertTrue(validationResult.getResult().contains( - "field \"decoderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string")); - assertTrue(validationResult.getResult() - .contains("field \"decoderClassName\" type \"java.lang.String\" value \"\" INVALID, " - + "must be a non-blank string containing full class name of the decoder")); + assertThat(validationResult.getResult()).contains("\"decoderType\" value \"\" INVALID, is blank", + "\"decoderClassName\" value \"\" INVALID, is blank"); } @Test public void testPolicyDecoderParameters_NullDecoderType() { final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(null, DECODER_CLASS_NAME, DECODER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pDParameters.validate(); + final ValidationResult validationResult = pDParameters.validate(); assertEquals(null, pDParameters.getDecoderType()); assertEquals(DECODER_CLASS_NAME, pDParameters.getDecoderClassName()); assertFalse(validationResult.isValid()); - assertTrue(validationResult.getResult().contains( - "field \"decoderType\" type \"java.lang.String\" value \"null\" INVALID, must be a non-blank string")); + assertThat(validationResult.getResult()).contains("\"decoderType\" value \"null\" INVALID, is null"); } @Test public void testPolicyDecoderParameters_NullDecoderClassName() { final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(DECODER_TYPE, null, DECODER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pDParameters.validate(); + final ValidationResult validationResult = pDParameters.validate(); assertEquals(DECODER_TYPE, pDParameters.getDecoderType()); assertEquals(null, pDParameters.getDecoderClassName()); assertFalse(validationResult.isValid()); - assertTrue(validationResult.getResult() - .contains("field \"decoderClassName\" type \"java.lang.String\" value \"null\" INVALID, " - + "must be a non-blank string containing full class name of the decoder")); + assertThat(validationResult.getResult()).contains("\"decoderClassName\" value \"null\" INVALID, is null"); } @Test public void testPolicyDecoderParameters_InvalidDecoderClass() { final PolicyDecoderParameters pDParameters = new PolicyDecoderParameters(DECODER_TYPE, DECODER_CLASS_NAME + "Invalid", DECODER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pDParameters.validate(); + final ValidationResult validationResult = pDParameters.validate(); assertEquals(DECODER_TYPE, pDParameters.getDecoderType()); assertEquals(DECODER_CLASS_NAME + "Invalid", pDParameters.getDecoderClassName()); assertFalse(validationResult.isValid()); - assertTrue(validationResult.getResult().contains("policy decoder class not found in classpath")); + assertThat(validationResult.getResult()).contains("\"decoderClassName\"", "classpath"); } } diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java index 9907bfb8..5dc1b448 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestPolicyForwarderParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -20,6 +21,7 @@ package org.onap.policy.distribution.main.parameters; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -28,7 +30,7 @@ import static org.onap.policy.distribution.main.parameters.CommonTestData.FORWAR 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.common.parameters.ValidationResult; import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters; /** @@ -42,7 +44,7 @@ public class TestPolicyForwarderParameters { public void testPolicyForwarderParameters() { final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pFParameters.validate(); + final ValidationResult validationResult = pFParameters.validate(); assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType()); assertEquals(FORWARDER_CLASS_NAME, pFParameters.getForwarderClassName()); assertTrue(validationResult.isValid()); @@ -52,76 +54,66 @@ public class TestPolicyForwarderParameters { public void testPolicyForwarderParameters_InvalidForwarderType() { final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters("", FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pFParameters.validate(); + final ValidationResult 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")); + assertThat(validationResult.getResult()).contains("\"forwarderType\" value \"\" INVALID, is blank"); } @Test public void testPolicyForwarderParameters_InvalidForwarderClassName() { final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(FORWARDER_TYPE, "", FORWARDER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pFParameters.validate(); + final ValidationResult 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")); + assertThat(validationResult.getResult()).contains("\"forwarderClassName\" value \"\" INVALID, is blank"); } @Test public void testPolicyForwarderParameters_InvalidForwarderTypeAndClassName() { final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters("", "", FORWARDER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pFParameters.validate(); + final ValidationResult 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")); + assertThat(validationResult.getResult()).contains("\"forwarderType\" value \"\" INVALID, is blank", + "\"forwarderClassName\" value \"\" INVALID, is blank"); } @Test public void testPolicyForwarderParameters_NullForwarderType() { final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(null, FORWARDER_CLASS_NAME, FORWARDER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pFParameters.validate(); + final ValidationResult 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")); + assertThat(validationResult.getResult()).contains("\"forwarderType\" value \"null\" INVALID, is null"); } @Test public void testPolicyForwarderParameters_NullForwarderClassName() { final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(FORWARDER_TYPE, null, FORWARDER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pFParameters.validate(); + final ValidationResult 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")); + assertThat(validationResult.getResult()).contains("\"forwarderClassName\" value \"null\" INVALID, is null"); } @Test public void testPolicyForwarderParameters_InvalidForwarderClass() { final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters(FORWARDER_TYPE, FORWARDER_CLASS_NAME + "Invalid", FORWARDER_CONFIGURATION_PARAMETERS); - final GroupValidationResult validationResult = pFParameters.validate(); + final ValidationResult validationResult = pFParameters.validate(); assertEquals(FORWARDER_TYPE, pFParameters.getForwarderType()); assertEquals(FORWARDER_CLASS_NAME + "Invalid", pFParameters.getForwarderClassName()); assertFalse(validationResult.isValid()); - assertTrue(validationResult.getResult().contains("policy forwarder class not found in classpath")); + assertThat(validationResult.getResult()).contains("class is not in the classpath"); } } diff --git a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java index 2dde9666..c02b96bc 100644 --- a/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java +++ b/main/src/test/java/org/onap/policy/distribution/main/parameters/TestReceptionHandlerParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -20,12 +21,13 @@ package org.onap.policy.distribution.main.parameters; +import static org.assertj.core.api.Assertions.assertThat; 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.common.parameters.ValidationResult; import org.onap.policy.distribution.reception.parameters.PluginHandlerParameters; import org.onap.policy.distribution.reception.parameters.ReceptionHandlerParameters; @@ -43,7 +45,7 @@ public class TestReceptionHandlerParameters { final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters( CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); - final GroupValidationResult validationResult = rHParameters.validate(); + final ValidationResult validationResult = rHParameters.validate(); assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType()); assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME, rHParameters.getReceptionHandlerClassName()); assertEquals(CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, @@ -58,16 +60,14 @@ public class TestReceptionHandlerParameters { final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(null, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); - final GroupValidationResult validationResult = rHParameters.validate(); + final ValidationResult 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")); + assertThat(validationResult.getResult()).contains("\"receptionHandlerType\" value \"null\" INVALID, is null"); } @Test @@ -76,16 +76,15 @@ public class TestReceptionHandlerParameters { final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, null, CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); - final GroupValidationResult validationResult = rHParameters.validate(); + final ValidationResult 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")); + assertThat(validationResult.getResult()) + .contains("\"receptionHandlerClassName\" value \"null\" INVALID, is null"); } @Test @@ -94,14 +93,12 @@ public class TestReceptionHandlerParameters { final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters("", CommonTestData.RECEPTION_HANDLER_CLASS_NAME, CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); - final GroupValidationResult validationResult = rHParameters.validate(); + final ValidationResult 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")); + assertThat(validationResult.getResult()).contains("\"receptionHandlerType\" value \"\" INVALID, is blank"); } @Test @@ -110,16 +107,14 @@ public class TestReceptionHandlerParameters { final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters(CommonTestData.RECEPTION_HANDLER_TYPE, "", CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); - final GroupValidationResult validationResult = rHParameters.validate(); + final ValidationResult 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")); + assertThat(validationResult.getResult()).contains("\"receptionHandlerClassName\" value \"\" INVALID, is blank"); } @Test @@ -128,9 +123,9 @@ public class TestReceptionHandlerParameters { final ReceptionHandlerParameters rHParameters = new ReceptionHandlerParameters( CommonTestData.RECEPTION_HANDLER_TYPE, CommonTestData.RECEPTION_HANDLER_CLASS_NAME, CommonTestData.RECEPTION_CONFIGURATION_PARAMETERS, pHParameters); - GroupValidationResult result = rHParameters.validate(); + ValidationResult result = rHParameters.validate(); assertFalse(result.isValid()); - assertTrue(result.getResult().endsWith("must have at least one policy forwarder\n")); + assertThat(result.getResult()).contains("\"policyForwarders\"", "minimum"); } @Test @@ -140,7 +135,7 @@ public class TestReceptionHandlerParameters { 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(); + final ValidationResult validationResult = rHParameters.validate(); assertEquals(CommonTestData.RECEPTION_HANDLER_TYPE, rHParameters.getReceptionHandlerType()); assertEquals(CommonTestData.RECEPTION_HANDLER_CLASS_NAME + "Invalid", rHParameters.getReceptionHandlerClassName()); @@ -148,6 +143,6 @@ public class TestReceptionHandlerParameters { rHParameters.getReceptionHandlerConfigurationName()); assertEquals(pHParameters, rHParameters.getPluginHandlerParameters()); assertFalse(validationResult.isValid()); - assertTrue(validationResult.getResult().contains("reception handler class not found in classpath")); + assertThat(validationResult.getResult()).contains("\"receptionHandlerClassName\"", "classpath"); } } diff --git a/main/src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt b/main/src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt index a5e84f5c..ebad6984 100644 --- a/main/src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt +++ b/main/src/test/resources/expectedValidationResults/InvalidDecoderAndForwarderParameters.txt @@ -1,17 +1,22 @@ 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 map 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 map 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 map 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 +"DistributionParameterGroup" INVALID, item has status INVALID + "receptionHandlerParameters" INVALID, item has status INVALID + "DummyReceptionHandler" INVALID, item has status INVALID + "ReceptionHandlerParameters" INVALID, item has status INVALID + "PluginHandlerParameters" INVALID, item has status INVALID + "policyDecoders" INVALID, item has status INVALID + "APEXDecoder" INVALID, item has status INVALID + "PolicyDecoderParameters" INVALID, item has status INVALID + item "decoderType" value "" INVALID, is blank + item "decoderClassName" value "org.onap.policy.distribution.main.testclasses.PolicyDecoderApexPdpa" INVALID, class is not in the classpath + "DROOLSDecoder" INVALID, item has status INVALID + "PolicyDecoderParameters" INVALID, item has status INVALID + item "decoderClassName" value "" INVALID, is blank + "policyForwarders" INVALID, item has status INVALID + "PAPStandaloneForwarder" INVALID, item has status INVALID + "PolicyForwarderParameters" INVALID, item has status INVALID + item "forwarderType" value "" INVALID, is blank + item "forwarderClassName" value "org.onap.policy.distribution.main.testclasses.PapStandalonePolicyForwarder" INVALID, class is not in the classpath + "PAPEngineForwarder" INVALID, item has status INVALID + "PolicyForwarderParameters" INVALID, item has status INVALID + item "forwarderClassName" value "" INVALID, is blank diff --git a/main/src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt b/main/src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt index 37c3457d..9879892a 100644 --- a/main/src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt +++ b/main/src/test/resources/expectedValidationResults/InvalidReceptionHandlerParameters.txt @@ -1,6 +1,7 @@ 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 map 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 +"DistributionParameterGroup" INVALID, item has status INVALID + "receptionHandlerParameters" INVALID, item has status INVALID + "DummyReceptionHandler" INVALID, item has status INVALID + "ReceptionHandlerParameters" INVALID, item has status INVALID + item "receptionHandlerType" value "" INVALID, is blank + item "receptionHandlerClassName" value "org.onap.policy.distribution.main.testclasses.InvalidSdcReceptionHandler" INVALID, class is not in the classpath diff --git a/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt b/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt index f3152e41..5ae0c819 100644 --- a/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt +++ b/main/src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt @@ -1,7 +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 "RestServerParameters" type "org.onap.policy.common.endpoints.parameters.RestServerParameters" INVALID, parameter group has status INVALID - field "host" type "java.lang.String" value "" INVALID, must be a non-blank string - field "port" type "int" value "-1" INVALID, must be >= 1 - field "userName" type "java.lang.String" value "" INVALID, must be a non-blank string - field "password" type "java.lang.String" value "" INVALID, must be a non-blank string
\ No newline at end of file +"DistributionParameterGroup" INVALID, item has status INVALID + "RestServerParameters" INVALID, item has status INVALID + item "host" value "" INVALID, is blank + item "port" value "-1" INVALID, is below the minimum value: 1 + item "userName" value "" INVALID, is blank + item "password" value "" INVALID, is blank diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParameters.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParameters.java index 4d141a95..c266a1ba 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParameters.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiForwarderParameters.java @@ -24,6 +24,7 @@ package org.onap.policy.distribution.forwarding.lifecycle.api; import lombok.Getter; import org.onap.policy.common.parameters.annotations.NotBlank; import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Valid; import org.onap.policy.distribution.main.parameters.PolicyForwarderConfigurationParameterGroup; /** @@ -37,8 +38,8 @@ import org.onap.policy.distribution.main.parameters.PolicyForwarderConfiguration public class LifecycleApiForwarderParameters extends PolicyForwarderConfigurationParameterGroup { public static final String POLICY_FORWARDER_PLUGIN_CLASS = LifecycleApiPolicyForwarder.class.getName(); - private LifecycleApiParameters apiParameters; - private LifecycleApiParameters papParameters; + private @Valid LifecycleApiParameters apiParameters; + private @Valid LifecycleApiParameters papParameters; private boolean isHttps; private boolean allowSelfSignedCerts; private boolean deployPolicies = true; diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandlerConfigurationParameterGroup.java index 9c596f76..44e89c07 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandlerConfigurationParameterGroup.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandlerConfigurationParameterGroup.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Intel. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -24,7 +25,10 @@ package org.onap.policy.distribution.reception.handling.file; import java.io.File; import lombok.Getter; import lombok.Setter; -import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.BeanValidator; +import org.onap.policy.common.parameters.ObjectValidationResult; +import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.common.parameters.annotations.NotBlank; import org.onap.policy.common.parameters.annotations.NotNull; @@ -51,9 +55,9 @@ public class FileSystemReceptionHandlerConfigurationParameterGroup extends Recep * {@inheritDoc}. */ @Override - public GroupValidationResult validate() { - final GroupValidationResult validationResult = new GroupValidationResult(this); - validatePathElement(validationResult, watchPath, "watchPath"); + public BeanValidationResult validate() { + final BeanValidationResult validationResult = new BeanValidator().validateTop(getClass().getSimpleName(), this); + validationResult.addResult(validatePathElement(watchPath, "watchPath")); return validationResult; } @@ -61,23 +65,17 @@ public class FileSystemReceptionHandlerConfigurationParameterGroup extends Recep /** * 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; + private ValidationResult validatePathElement(final String element, final String elementName) { if (element != null) { final File file = new File(element); if (file.exists() && file.isDirectory()) { - valid = true; + return null; } } - if (!valid) { - validationResult.setResult(elementName, ValidationStatus.INVALID, - elementName + " must be a valid directory"); - } + + return new ObjectValidationResult(elementName, element, ValidationStatus.INVALID, "is not a valid directory"); } } - diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java index 03455b84..c8bcc7bd 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java @@ -3,6 +3,7 @@ * Copyright (C) 2018 Intel. All rights reserved. * Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -22,6 +23,7 @@ package org.onap.policy.distribution.reception.handling.file; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -33,7 +35,7 @@ import java.io.IOException; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationResult; /** * Class to perform unit test of {@link FileSystemReceptionHandlerConfigurationParameterGroup}. @@ -54,7 +56,7 @@ public class TestFileSystemReceptionHandlerConfigurationParameterGroup { configParameters.setWatchPath(validPath); configParameters.setMaxThread(2); - final GroupValidationResult validationResult = configParameters.validate(); + final ValidationResult validationResult = configParameters.validate(); assertTrue(validationResult.isValid()); assertEquals(validPath, configParameters.getWatchPath()); assertEquals(2, configParameters.getMaxThread()); @@ -66,7 +68,7 @@ public class TestFileSystemReceptionHandlerConfigurationParameterGroup { final Gson gson = new GsonBuilder().create(); configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"), FileSystemReceptionHandlerConfigurationParameterGroup.class); - final GroupValidationResult validationResult = configParameters.validate(); + final ValidationResult validationResult = configParameters.validate(); assertFalse(validationResult.isValid()); } @@ -79,8 +81,8 @@ public class TestFileSystemReceptionHandlerConfigurationParameterGroup { new FileSystemReceptionHandlerConfigurationParameterGroup(); configParameters.setWatchPath(invalidPath); - final GroupValidationResult validateResult = configParameters.validate(); + final ValidationResult validateResult = configParameters.validate(); assertFalse(validateResult.isValid()); - assertTrue(validateResult.getResult().contains("must be a valid directory")); + assertThat(validateResult.getResult()).contains("is not a valid directory"); } } diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java index 51298c1e..cd7f2614 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Intel. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -31,7 +32,7 @@ import java.io.FileReader; import java.io.IOException; import java.util.Arrays; import org.junit.Test; -import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.parameters.ValidationStatus; /** @@ -47,7 +48,7 @@ public class TestSdcReceptionHandlerConfigurationParameterGroup { configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdc.json"), SdcReceptionHandlerConfigurationParameterGroup.class); - final GroupValidationResult validationResult = configParameters.validate(); + final ValidationResult validationResult = configParameters.validate(); assertTrue(validationResult.isValid()); final SdcConfiguration config = new SdcConfiguration(configParameters); assertEquals(Arrays.asList("a.com", "b.com", "c.com"), config.getMsgBusAddress()); @@ -75,7 +76,7 @@ public class TestSdcReceptionHandlerConfigurationParameterGroup { configParameters = gson.fromJson(new FileReader("src/test/resources/handling-sdcInvalid.json"), SdcReceptionHandlerConfigurationParameterGroup.class); - final GroupValidationResult validationResult = configParameters.validate(); + final ValidationResult validationResult = configParameters.validate(); assertFalse(validationResult.isValid()); } diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java index bd0ad900..c3e44274 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PluginHandlerParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -21,10 +22,13 @@ package org.onap.policy.distribution.reception.parameters; import java.util.Map; -import java.util.Map.Entry; -import org.onap.policy.common.parameters.GroupValidationResult; +import lombok.Setter; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.BeanValidator; import org.onap.policy.common.parameters.ParameterGroup; -import org.onap.policy.common.parameters.ValidationStatus; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Size; +import org.onap.policy.common.parameters.annotations.Valid; import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters; /** @@ -32,13 +36,19 @@ import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParamet * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ +@NotNull public class PluginHandlerParameters implements ParameterGroup { private static final String PLUGIN_HANDLER = "_PluginHandler"; + @Setter private String name; - private Map<String, PolicyDecoderParameters> policyDecoders; - private Map<String, PolicyForwarderParameters> policyForwarders; + + @Size(min = 1) + private Map<String, @NotNull @Valid PolicyDecoderParameters> policyDecoders; + + @Size(min = 1) + private Map<String, @NotNull @Valid PolicyForwarderParameters> policyForwarders; /** * Constructor for instantiating PluginHandlerParameters. @@ -80,36 +90,7 @@ public class PluginHandlerParameters implements ParameterGroup { * */ @Override - public GroupValidationResult validate() { - final GroupValidationResult validationResult = new GroupValidationResult(this); - if (policyDecoders == null || policyDecoders.size() == 0) { - validationResult.setResult("policyDecoders", ValidationStatus.INVALID, - "must have at least one policy decoder"); - } else { - for (final Entry<String, PolicyDecoderParameters> nestedGroupEntry : policyDecoders.entrySet()) { - validationResult.setResult("policyDecoders", nestedGroupEntry.getKey(), - nestedGroupEntry.getValue().validate()); - } - } - if (policyForwarders == null || policyForwarders.size() == 0) { - validationResult.setResult("policyForwarders", ValidationStatus.INVALID, - "must have at least one policy forwarder"); - } else { - for (final Entry<String, PolicyForwarderParameters> nestedGroupEntry : policyForwarders.entrySet()) { - validationResult.setResult("policyForwarders", nestedGroupEntry.getKey(), - nestedGroupEntry.getValue().validate()); - } - } - return validationResult; - } - - /** - * Set the name of this group. - * - * @param name the name to set. - */ - @Override - public void setName(final String name) { - this.name = name; + public BeanValidationResult validate() { + return new BeanValidator().validateTop(getClass().getSimpleName(), this); } } diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java index f8ede1a9..492e2e05 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderParameters.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -21,23 +22,24 @@ package org.onap.policy.distribution.reception.parameters; -import org.onap.policy.common.parameters.GroupValidationResult; +import lombok.Getter; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.BeanValidator; import org.onap.policy.common.parameters.ParameterGroup; -import org.onap.policy.common.parameters.ValidationStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.policy.common.parameters.annotations.ClassName; +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; /** * Class to hold all the policy decoder parameters. * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ +@Getter +@NotBlank public class PolicyDecoderParameters implements ParameterGroup { - - private static final Logger LOGGER = LoggerFactory.getLogger(PolicyDecoderParameters.class); - - private String decoderType; - private String decoderClassName; + private @NotNull String decoderType; + private @NotNull @ClassName String decoderClassName; private String decoderConfigurationName; /** @@ -55,33 +57,6 @@ public class PolicyDecoderParameters implements ParameterGroup { } /** - * Return the decoderType of this PolicyDecoderParameters instance. - * - * @return the decoderType - */ - public String getDecoderType() { - return decoderType; - } - - /** - * Return the decoderClassName of this PolicyDecoderParameters instance. - * - * @return the decoderClassName - */ - public String getDecoderClassName() { - return decoderClassName; - } - - /** - * Return the name of the decoder configuration of this {@link PolicyDecoderParameters} instance. - * - * @return the the name of the decoder configuration - */ - public String getDecoderConfigurationName() { - return decoderConfigurationName; - } - - /** * {@inheritDoc}. */ @Override @@ -101,27 +76,7 @@ public class PolicyDecoderParameters implements ParameterGroup { * {@inheritDoc}. */ @Override - public GroupValidationResult validate() { - final GroupValidationResult validationResult = new GroupValidationResult(this); - if (decoderType == null || decoderType.trim().length() == 0) { - validationResult.setResult("decoderType", ValidationStatus.INVALID, "must be a non-blank string"); - } - if (decoderClassName == null || decoderClassName.trim().length() == 0) { - validationResult.setResult("decoderClassName", ValidationStatus.INVALID, - "must be a non-blank string containing full class name of the decoder"); - } else { - validatePolicyDecoderClass(validationResult); - } - return validationResult; - } - - private void validatePolicyDecoderClass(final GroupValidationResult validationResult) { - try { - Class.forName(decoderClassName); - } catch (final ClassNotFoundException exp) { - LOGGER.trace("policy decoder class not found in classpath", exp); - validationResult.setResult("decoderClassName", ValidationStatus.INVALID, - "policy decoder class not found in classpath"); - } + public BeanValidationResult validate() { + return new BeanValidator().validateTop(getClass().getSimpleName(), this); } } diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java index ea6d8d86..901c4968 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerParameters.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -21,26 +22,30 @@ package org.onap.policy.distribution.reception.parameters; -import org.onap.policy.common.parameters.GroupValidationResult; +import lombok.Getter; +import lombok.Setter; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.common.parameters.BeanValidator; import org.onap.policy.common.parameters.ParameterGroup; -import org.onap.policy.common.parameters.ValidationStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.policy.common.parameters.annotations.ClassName; +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Valid; /** * Class to hold all the reception handler parameters. * * @author Ram Krishna Verma (ram.krishna.verma@ericsson.com) */ +@NotNull +@NotBlank +@Getter public class ReceptionHandlerParameters implements ParameterGroup { - - private static final Logger LOGGER = LoggerFactory.getLogger(ReceptionHandlerParameters.class); - - private String name; + private @Setter String name; private String receptionHandlerType; - private String receptionHandlerClassName; + private @ClassName String receptionHandlerClassName; private String receptionHandlerConfigurationName; - private PluginHandlerParameters pluginHandlerParameters; + private @Valid PluginHandlerParameters pluginHandlerParameters; /** * Constructor for instantiating ReceptionHandlerParameters. @@ -58,42 +63,6 @@ public class ReceptionHandlerParameters implements ParameterGroup { this.pluginHandlerParameters = pluginHandlerParameters; } - /** - * Return the receptionHandlerType of this ReceptionHandlerParameters instance. - * - * @return the receptionHandlerType - */ - public String getReceptionHandlerType() { - return receptionHandlerType; - } - - /** - * Return the receptionHandlerClassName of this ReceptionHandlerParameters instance. - * - * @return the receptionHandlerClassName - */ - public String getReceptionHandlerClassName() { - return receptionHandlerClassName; - } - - /** - * Return the name of the reception handler configuration for this ReceptionHandlerParameters instance. - * - * @return the PssdConfigurationParametersGroup - */ - public String getReceptionHandlerConfigurationName() { - return receptionHandlerConfigurationName; - } - - /** - * Return the pluginHandlerParameters of this ReceptionHandlerParameters instance. - * - * @return the pluginHandlerParameters - */ - public PluginHandlerParameters getPluginHandlerParameters() { - return pluginHandlerParameters; - } - @Override public String getName() { return name + "_" + receptionHandlerType; @@ -104,43 +73,7 @@ public class ReceptionHandlerParameters implements ParameterGroup { * */ @Override - public GroupValidationResult validate() { - final GroupValidationResult validationResult = new GroupValidationResult(this); - if (receptionHandlerType == null || receptionHandlerType.trim().length() == 0) { - validationResult.setResult("receptionHandlerType", ValidationStatus.INVALID, "must be a non-blank string"); - } - if (receptionHandlerClassName == null || receptionHandlerClassName.trim().length() == 0) { - validationResult.setResult("receptionHandlerClassName", ValidationStatus.INVALID, - "must be a non-blank string containing full class name of the reception handler"); - } else { - validateReceptionHandlerClass(validationResult); - } - if (pluginHandlerParameters == null) { - validationResult.setResult("pluginHandlerParameters", ValidationStatus.INVALID, - "must have a plugin handler"); - } else { - validationResult.setResult("pluginHandlerParameters", pluginHandlerParameters.validate()); - } - return validationResult; - } - - private void validateReceptionHandlerClass(final GroupValidationResult validationResult) { - try { - Class.forName(receptionHandlerClassName); - } catch (final ClassNotFoundException exp) { - LOGGER.error("reception handler class not found in classpath", exp); - validationResult.setResult("receptionHandlerClassName", ValidationStatus.INVALID, - "reception handler class not found in classpath"); - } - } - - /** - * Set the name of this group. - * - * @param name the name to set - */ - @Override - public void setName(final String name) { - this.name = name; + public BeanValidationResult validate() { + return new BeanValidator().validateTop(getClass().getSimpleName(), this); } } diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPluginHandlerParameters.java b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPluginHandlerParameters.java index 9d6a78d0..9a0ac316 100644 --- a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPluginHandlerParameters.java +++ b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPluginHandlerParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -25,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.HashMap; import java.util.Map; import org.junit.Test; -import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters; /** @@ -40,30 +41,24 @@ public class TestPluginHandlerParameters { public void testValidate_PolicyDecodersEmpty() { PluginHandlerParameters emptyDecoder = new PluginHandlerParameters(new HashMap<>(), getPolicyForwarders()); - GroupValidationResult result = emptyDecoder.validate(); + ValidationResult result = emptyDecoder.validate(); - assertThat(result.getResult()) - .contains("parameter group map \"policyDecoders\" INVALID, must have at least one policy decoder"); - assertThat(result.getResult()).doesNotContain( - "parameter group map \"policyForwarders\" INVALID, must have at least one policy forwarder"); + assertThat(result.getResult()).contains("\"policyDecoders\"", "minimum").doesNotContain("\"policyForwarders\""); } @Test public void testValidate_PolicyForwardersNullEmpty() { PluginHandlerParameters emptyDecoder = new PluginHandlerParameters(getPolicyDecoders(), new HashMap<>()); - GroupValidationResult result = emptyDecoder.validate(); + ValidationResult result = emptyDecoder.validate(); - assertThat(result.getResult()) - .contains("parameter group map \"policyForwarders\" INVALID, must have at least one policy forwarder"); - assertThat(result.getResult()).doesNotContain( - "parameter group map \"policyDecoders\" INVALID, must have at least one policy decoder"); + assertThat(result.getResult()).contains("\"policyForwarders\"", "minimum").doesNotContain("\"policyDecoders\""); } private Map<String, PolicyDecoderParameters> getPolicyDecoders() { final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<>(); final PolicyDecoderParameters pDParameters = - new PolicyDecoderParameters("DummyDecoder", "DummyDecoder", "dummyDecoderConfiguration"); + new PolicyDecoderParameters("DummyDecoder", getClass().getName(), "dummyDecoderConfiguration"); policyDecoders.put("DummyDecoder", pDParameters); return policyDecoders; @@ -72,7 +67,7 @@ public class TestPluginHandlerParameters { private Map<String, PolicyForwarderParameters> getPolicyForwarders() { final Map<String, PolicyForwarderParameters> policyForwarders = new HashMap<>(); final PolicyForwarderParameters pFParameters = - new PolicyForwarderParameters("DummyForwarder", "DummyForwarder", "dummyForwarderConfiguration"); + new PolicyForwarderParameters("DummyForwarder", getClass().getName(), "dummyForwarderConfiguration"); policyForwarders.put("DummyForwarder", pFParameters); return policyForwarders; diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderParameters.java b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderParameters.java index d1d0b421..dae91abf 100644 --- a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderParameters.java +++ b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestPolicyDecoderParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -23,6 +24,7 @@ package org.onap.policy.distribution.reception.parameters; import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; +import org.onap.policy.distribution.reception.handling.DummyDecoder; /** * Class for unit testing PolicyDecoderParameters class. @@ -32,7 +34,7 @@ import org.junit.Test; */ public class TestPolicyDecoderParameters { - static final String DECODER_CLASS_NAME = "org.onap.policy.distribution.reception.handling.DummyDecoder"; + static final String DECODER_CLASS_NAME = DummyDecoder.class.getName(); static final String DECODER_CONFIG = "decoderConfigName"; static final String DECODER_TYPE = "DummyDecoder"; @@ -40,14 +42,12 @@ public class TestPolicyDecoderParameters { public void testValidate_DecoderTypeEmptyNull() { PolicyDecoderParameters sutParams = new PolicyDecoderParameters(null, DECODER_CLASS_NAME, DECODER_CONFIG); - assertThat(sutParams.validate().getResult()).contains( - "field \"decoderType\" type \"java.lang.String\" value \"null\" INVALID, must be a non-blank string"); + assertThat(sutParams.validate().getResult()).contains("\"decoderType\" value \"null\" INVALID, is null"); sutParams.setName(""); - assertThat(sutParams.validate().getResult()).contains( - "field \"decoderType\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"); - assertThat(sutParams.validate().getResult()).doesNotContain("policy decoder class not found in classpath"); + assertThat(sutParams.validate().getResult()).contains("\"decoderType\" value \"\" INVALID, is blank") + .doesNotContain("not found in classpath"); } @Test @@ -55,13 +55,10 @@ public class TestPolicyDecoderParameters { PolicyDecoderParameters nullClassName = new PolicyDecoderParameters(DECODER_TYPE, null, DECODER_CONFIG); assertThat(nullClassName.validate().getResult()) - .contains("field \"decoderClassName\" type \"java.lang.String\" value \"null\" INVALID, " - + "must be a non-blank string containing full class name of the decoder"); + .contains("\"decoderClassName\" value \"null\" INVALID, is null"); PolicyDecoderParameters emptyClassName = new PolicyDecoderParameters(DECODER_TYPE, "", DECODER_CONFIG); - assertThat(emptyClassName.validate().getResult()) - .contains("field \"decoderClassName\" type \"java.lang.String\" value \"\" INVALID, " - + "must be a non-blank string containing full class name of the decoder"); + assertThat(emptyClassName.validate().getResult()).contains("\"decoderClassName\" value \"\" INVALID, is blank"); } } diff --git a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerParameters.java b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerParameters.java index e2ef01db..b12af003 100644 --- a/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerParameters.java +++ b/reception/src/test/java/org/onap/policy/distribution/reception/parameters/TestReceptionHandlerParameters.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -26,6 +27,7 @@ import java.util.HashMap; import java.util.Map; import org.junit.Test; import org.onap.policy.distribution.forwarding.parameters.PolicyForwarderParameters; +import org.onap.policy.distribution.reception.handling.DummyDecoder; /** * Class for unit testing ReceptionHandlerParameters class. @@ -42,25 +44,24 @@ public class TestReceptionHandlerParameters { ReceptionHandlerParameters sutParams = getReceptionHandlerParameters(className); sutParams.setName(className); - assertThat(sutParams.validate().getResult()).contains("reception handler class not found in classpath"); + assertThat(sutParams.validate().getResult()).contains("class is not in the classpath"); } @Test public void testValidate_ReceptionHandlerTypeNullEmpty() { - final String className = "org.onap.policy.distribution.reception.handling.DummyReceptionHandler"; + final String className = DummyDecoder.class.getName(); final PluginHandlerParameters pHParameters = new PluginHandlerParameters(getPolicyDecoders(), getPolicyForwarders()); ReceptionHandlerParameters nullType = new ReceptionHandlerParameters(null, className, className, pHParameters); - assertThat(nullType.validate().getResult()).contains("field \"receptionHandlerType\" type \"java.lang.String\"" - + " value \"null\" INVALID, must be a non-blank string"); + assertThat(nullType.validate().getResult()) + .contains("\"receptionHandlerType\" value \"null\" INVALID, is null"); ReceptionHandlerParameters emptyType = new ReceptionHandlerParameters("", className, className, pHParameters); - assertThat(emptyType.validate().getResult()).contains("field \"receptionHandlerType\" type \"java.lang.String\"" - + " value \"\" INVALID, must be a non-blank string"); - assertThat(emptyType.validate().getResult()).doesNotContain("reception handler class not found in classpath"); + assertThat(emptyType.validate().getResult()).contains("\"receptionHandlerType\" value \"\" INVALID, is blank") + .doesNotContain("classpath"); } @Test @@ -72,17 +73,13 @@ public class TestReceptionHandlerParameters { "dummyReceptionHandlerConfiguration", pHParameters); assertThat(nullType.validate().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"); + .contains("\"receptionHandlerClassName\" value \"null\" INVALID, is null"); ReceptionHandlerParameters emptyType = new ReceptionHandlerParameters("DummyReceptionHandler", "", "dummyReceptionHandlerConfiguration", pHParameters); assertThat(emptyType.validate().getResult()) - .contains("field \"receptionHandlerClassName\" type \"java.lang.String\" value " - + "\"\" INVALID, must be a non-blank string containing full class name of " - + "the reception handler"); + .contains("\"receptionHandlerClassName\" value \"\" INVALID, is blank"); } @Test @@ -93,7 +90,7 @@ public class TestReceptionHandlerParameters { "dummyReceptionHandlerConfiguration", null); assertThat(sutParams.validate().getResult()) - .contains("parameter group \"UNDEFINED\" INVALID, must have a plugin handler"); + .contains("\"pluginHandlerParameters\" value \"null\" INVALID, is null"); } private ReceptionHandlerParameters getReceptionHandlerParameters(String className) { @@ -109,7 +106,7 @@ public class TestReceptionHandlerParameters { final Map<String, PolicyDecoderParameters> policyDecoders = new HashMap<>(); final PolicyDecoderParameters pDParameters = - new PolicyDecoderParameters("DummyDecoder", "DummyDecoder", "dummyDecoderConfiguration"); + new PolicyDecoderParameters("DummyDecoder", DummyDecoder.class.getName(), "dummyDecoderConfiguration"); policyDecoders.put("DummyDecoder", pDParameters); return policyDecoders; @@ -118,8 +115,8 @@ public class TestReceptionHandlerParameters { private Map<String, PolicyForwarderParameters> getPolicyForwarders() { final Map<String, PolicyForwarderParameters> policyForwarders = new HashMap<>(); - final PolicyForwarderParameters pFParameters = - new PolicyForwarderParameters("DummyForwarder", "DummyForwarder", "dummyForwarderConfiguration"); + final PolicyForwarderParameters pFParameters = new PolicyForwarderParameters("DummyForwarder", + DummyDecoder.class.getName(), "dummyForwarderConfiguration"); policyForwarders.put("DummyForwarder", pFParameters); return policyForwarders; |