From a05cc62b6426d31c23f60dbe4a6f367331431ea4 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 27 Apr 2021 15:08:59 -0400 Subject: Remove GroupValidationResult Removed GroupValidationResult, replacing it with BeanValidationResult. Modified the ParameterGroup subclasses to use BeanValidator, adding annotations where needed to trigger the validations that had been automatically performed by GroupValidationResult. Issue-ID: POLICY-2059 Change-Id: Ib5c0dc0ac3762e68307e63f5ce29efb49208e55d Signed-off-by: Jim Hahn --- .../parameters/TestDistributionParameterGroup.java | 40 +++++++++------------ .../TestDistributionParameterHandler.java | 27 +++++++------- .../parameters/TestPluginHandlerParameters.java | 23 ++++++------ .../parameters/TestPolicyDecoderParameters.java | 41 +++++++++------------ .../parameters/TestPolicyForwarderParameters.java | 42 +++++++++------------- .../parameters/TestReceptionHandlerParameters.java | 39 +++++++++----------- .../InvalidDecoderAndForwarderParameters.txt | 37 ++++++++++--------- .../InvalidReceptionHandlerParameters.txt | 11 +++--- .../InvalidRestServerParameters.txt | 12 +++---- 9 files changed, 124 insertions(+), 148 deletions(-) (limited to 'main/src/test') 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 policyDecoders = commonTestData.getPolicyDecoders(false); final Map 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 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 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 policyDecoders = commonTestData.getPolicyDecoders(true); final Map 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 policyForwarders = commonTestData.getPolicyForwarders(true); final Map 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 -- cgit 1.2.3-korg