From 532e25ad45ba6bab39aa7442fbb8c675fad6264e Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 27 Apr 2021 10:30:14 -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: I9597dc84e8a81ac5b8954bb2ce4ad0d7e2a3a4a7 Signed-off-by: Jim Hahn --- .../pap/main/parameters/TestPapParameterGroup.java | 25 ++++++++++--------- .../main/parameters/TestPapParameterHandler.java | 5 ++-- .../pap/main/parameters/TestPdpParameters.java | 28 ++++++++++------------ .../main/parameters/TestPdpRequestParameters.java | 15 ++++++------ .../parameters/TestPdpStateChangeParameters.java | 6 ++--- .../main/parameters/TestPdpUpdateParameters.java | 6 ++--- 6 files changed, 41 insertions(+), 44 deletions(-) (limited to 'main/src/test') diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java index c22f5e1f..8962f45b 100644 --- a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java +++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterGroup.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. + * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ package org.onap.policy.pap.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 +29,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.onap.policy.common.endpoints.parameters.RestServerParameters; import org.onap.policy.common.endpoints.parameters.TopicParameterGroup; -import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.StandardCoder; @@ -53,7 +54,7 @@ public class TestPapParameterGroup { final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1); final RestServerParameters restServerParameters = papParameters.getRestServerParameters(); final TopicParameterGroup topicParameterGroup = papParameters.getTopicParameterGroup(); - final GroupValidationResult validationResult = papParameters.validate(); + final ValidationResult validationResult = papParameters.validate(); assertTrue(validationResult.isValid()); assertEquals(CommonTestData.PAP_GROUP_NAME, papParameters.getName()); assertEquals(restServerParameters.getHost(), papParameters.getRestServerParameters().getHost()); @@ -70,28 +71,27 @@ public class TestPapParameterGroup { public void testPapParameterGroup_NullName() throws Exception { String json = commonTestData.getPapParameterGroupAsString(1).replace("\"PapGroup\"", "null"); final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class); - final GroupValidationResult validationResult = papParameters.validate(); + final ValidationResult validationResult = papParameters.validate(); assertFalse(validationResult.isValid()); assertEquals(null, papParameters.getName()); - assertTrue(validationResult.getResult().contains("is null")); + assertThat(validationResult.getResult()).contains("is null"); } @Test public void testPapParameterGroup_EmptyName() throws Exception { String json = commonTestData.getPapParameterGroupAsString(1).replace(CommonTestData.PAP_GROUP_NAME, ""); final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class); - final GroupValidationResult validationResult = papParameters.validate(); + final ValidationResult validationResult = papParameters.validate(); assertFalse(validationResult.isValid()); assertEquals("", papParameters.getName()); - 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 public void testPapParameterGroup_SetName() { final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1); papParameters.setName("PapNewGroup"); - final GroupValidationResult validationResult = papParameters.validate(); + final ValidationResult validationResult = papParameters.validate(); assertTrue(validationResult.isValid()); assertEquals("PapNewGroup", papParameters.getName()); } @@ -101,10 +101,9 @@ public class TestPapParameterGroup { String json = commonTestData.getPapParameterGroupAsString(1); json = commonTestData.nullifyField(json, "restServerParameters"); final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(0); - final GroupValidationResult validationResult = papParameters.validate(); + final ValidationResult validationResult = papParameters.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, item has status INVALID"); } } diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java index 1761a7d1..6b6431fa 100644 --- a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java +++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPapParameterHandler.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. + * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. * Modifications Copyright (C) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -116,8 +116,7 @@ public class TestPapParameterHandler { arguments.parse(papConfigParameters); assertThatThrownBy(() -> new PapParameterHandler().getParameters(arguments)) - .hasMessageContaining("field \"name\" type \"java.lang.String\" value \" \" " - + "INVALID, must be a non-blank string"); + .hasMessageContaining("\"name\" value \" \" INVALID, is blank"); } @Test diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpParameters.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpParameters.java index c47b5301..6f398c6f 100644 --- a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpParameters.java +++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpParameters.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * 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. @@ -20,6 +20,7 @@ package org.onap.policy.pap.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.assertNotNull; @@ -27,7 +28,7 @@ import static org.junit.Assert.assertNull; 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.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.StandardCoder; @@ -61,7 +62,7 @@ public class TestPdpParameters { // valid String json2 = json; - GroupValidationResult result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate(); + ValidationResult result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate(); assertNull(result.getResult()); assertTrue(result.isValid()); @@ -69,30 +70,28 @@ public class TestPdpParameters { json2 = json.replaceFirst(": 6", ": 0"); result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate(); assertFalse(result.isValid()); - assertTrue(result.getResult().contains( - "field 'heartBeatMs' type 'long' value '0' INVALID, must be >= 1".replace('\'', '"'))); + assertThat(result.getResult()).contains( + "'heartBeatMs' value '0' INVALID, is below the minimum value: 1".replace('\'', '"')); // invalid max message age json2 = json.replaceFirst(": 20000", ": 0"); result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate(); assertFalse(result.isValid()); - assertTrue(result.getResult().contains( - "field 'maxMessageAgeMs' type 'long' value '0' INVALID, must be >= 1".replace('\'', '"'))); + assertThat(result.getResult()).contains( + "'maxMessageAgeMs' value '0' INVALID, is below the minimum value: 1".replace('\'', '"')); // no update params json2 = testData.nullifyField(json, "updateParameters"); result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate(); assertFalse(result.isValid()); - assertTrue(result.getResult().contains("field 'updateParameters'".replace('\'', '"'))); - assertTrue(result.getResult().contains("is null")); + assertThat(result.getResult()).contains("\"updateParameters\"", "is null"); // invalid update params json2 = json.replaceFirst(": 2", ": -2"); result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate(); assertFalse(result.isValid()); - assertTrue(result.getResult().contains("parameter group 'PdpUpdateParameters'".replace('\'', '"'))); - assertTrue(result.getResult().contains( - "field 'maxWaitMs' type 'long' value '-2' INVALID, must be >= 0".replace('\'', '"'))); + assertThat(result.getResult()).contains("\"PdpUpdateParameters\"", + "'maxWaitMs' value '-2' INVALID, is below the minimum value: 0".replace('\'', '"')); // no state-change params json2 = testData.nullifyField(json, "stateChangeParameters"); @@ -103,9 +102,8 @@ public class TestPdpParameters { json2 = json.replaceFirst(": 5", ": -5"); result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate(); assertFalse(result.isValid()); - assertTrue(result.getResult().contains("parameter group 'PdpStateChangeParameters'".replace('\'', '"'))); - assertTrue(result.getResult().contains( - "field 'maxWaitMs' type 'long' value '-5' INVALID, must be >= 0".replace('\'', '"'))); + assertThat(result.getResult()).contains("\"PdpStateChangeParameters\"", + "'maxWaitMs' value '-5' INVALID, is below the minimum value: 0".replace('\'', '"')); } } diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpRequestParameters.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpRequestParameters.java index e852442f..810bc448 100644 --- a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpRequestParameters.java +++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpRequestParameters.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * 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. @@ -20,13 +20,14 @@ package org.onap.policy.pap.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.assertNull; 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.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.StandardCoder; @@ -44,7 +45,7 @@ public class TestPdpRequestParameters { public void testValidate() throws Exception { // valid, zeroes PdpRequestParameters params = makeParams(0, 0); - GroupValidationResult result = params.validate(); + ValidationResult result = params.validate(); assertNull(result.getResult()); assertTrue(result.isValid()); @@ -58,15 +59,15 @@ public class TestPdpRequestParameters { params = makeParams(-1, 120); result = params.validate(); assertFalse(result.isValid()); - assertTrue(result.getResult().contains( - "field 'maxRetryCount' type 'int' value '-1' INVALID, must be >= 0".replace('\'', '"'))); + assertThat(result.getResult()).contains( + "'maxRetryCount' value '-1' INVALID, is below the minimum value: 0".replace('\'', '"')); // invalid wait time params = makeParams(130, -1); result = params.validate(); assertFalse(result.isValid()); - assertTrue(result.getResult() - .contains("field 'maxWaitMs' type 'long' value '-1' INVALID, must be >= 0".replace('\'', '"'))); + assertThat(result.getResult()).contains( + "'maxWaitMs' value '-1' INVALID, is below the minimum value: 0".replace('\'', '"')); } private PdpRequestParameters makeParams(int maxRetry, long maxWait) throws Exception { diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpStateChangeParameters.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpStateChangeParameters.java index 5744303f..45cbe372 100644 --- a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpStateChangeParameters.java +++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpStateChangeParameters.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * 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. @@ -24,7 +24,7 @@ import static org.junit.Assert.assertNull; 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.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.StandardCoder; @@ -39,7 +39,7 @@ public class TestPdpStateChangeParameters { public void testValidate() throws Exception { // valid, zeroes PdpStateChangeParameters params = makeParams(10, 20); - GroupValidationResult result = params.validate(); + ValidationResult result = params.validate(); assertNull(result.getResult()); assertTrue(result.isValid()); } diff --git a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpUpdateParameters.java b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpUpdateParameters.java index 6866c401..814894c6 100644 --- a/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpUpdateParameters.java +++ b/main/src/test/java/org/onap/policy/pap/main/parameters/TestPdpUpdateParameters.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * 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. @@ -24,7 +24,7 @@ import static org.junit.Assert.assertNull; 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.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.StandardCoder; @@ -39,7 +39,7 @@ public class TestPdpUpdateParameters { public void testValidate() throws Exception { // valid, zeroes PdpUpdateParameters params = makeParams(10, 20); - GroupValidationResult result = params.validate(); + ValidationResult result = params.validate(); assertNull(result.getResult()); assertTrue(result.isValid()); } -- cgit 1.2.3-korg