aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/reception-plugins
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-04-27 15:08:59 -0400
committerJim Hahn <jrh3@att.com>2021-04-29 14:49:33 -0400
commita05cc62b6426d31c23f60dbe4a6f367331431ea4 (patch)
treebb38e4b81c133004ab9541c15db030750957f5f3 /plugins/reception-plugins
parentadfc3ee02f3194a143bcea430e5e3aeb99a23206 (diff)
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 <jrh3@att.com>
Diffstat (limited to 'plugins/reception-plugins')
-rw-r--r--plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandlerConfigurationParameterGroup.java26
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/file/TestFileSystemReceptionHandlerConfigurationParameterGroup.java12
-rw-r--r--plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandlerConfigurationParameterGroup.java7
3 files changed, 23 insertions, 22 deletions
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());
}