summaryrefslogtreecommitdiffstats
path: root/common-parameters
diff options
context:
space:
mode:
Diffstat (limited to 'common-parameters')
-rw-r--r--common-parameters/pom.xml4
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/GroupValidationResult.java70
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java61
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java56
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/Min.java39
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/NotBlank.java37
-rw-r--r--common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/NotNull.java37
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java262
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/EmptyParameterGroup.java32
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupMissingGetter.java32
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupPrivateGetter.java32
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithArray.java30
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithCollection.java33
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapKey.java33
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapValue.java33
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullCollection.java31
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullMapValue.java31
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullSubGroup.java29
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java32
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL00.java36
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL10.java32
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersLGeneric.java53
-rw-r--r--common-parameters/src/test/resources/expectedValidationResults/TestJsonYamlValidationResult.txt18
-rw-r--r--common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_0_OK.txt18
-rw-r--r--common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_2_Invalid.txt6
-rw-r--r--common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_3_Invalid.txt14
26 files changed, 668 insertions, 423 deletions
diff --git a/common-parameters/pom.xml b/common-parameters/pom.xml
index e8859c89..9eefb551 100644
--- a/common-parameters/pom.xml
+++ b/common-parameters/pom.xml
@@ -35,6 +35,10 @@
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/GroupValidationResult.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/GroupValidationResult.java
index 283f36b9..6da36c19 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/GroupValidationResult.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/GroupValidationResult.java
@@ -1,20 +1,20 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018-2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -66,7 +66,7 @@ public class GroupValidationResult implements ValidationResult {
// Check if a validation result should be added for this declared field
if (isIncludedField(field)) {
// Set a validation result for the field
- validationResultMap.put(field.getName(), getValidationResult(field, parameterGroup));
+ validationResultMap.put(field.getName(), getSetValidationResult(field, parameterGroup));
}
}
@@ -75,13 +75,29 @@ public class GroupValidationResult implements ValidationResult {
// Check if a validation result should be added for this declared field
if (isIncludedField(field)) {
// Set a validation result for the field
- validationResultMap.putIfAbsent(field.getName(), getValidationResult(field, parameterGroup));
+ validationResultMap.putIfAbsent(field.getName(), getSetValidationResult(field, parameterGroup));
}
}
}
+
+ /**
+ * Construct a validation result for a field, updating "this" status.
+ *
+ * @param field The parameter field
+ * @param ParameterGroup The parameter group containing the field
+ * @return the validation result
+ * @throws Exception on accessing private fields
+ */
+ private ValidationResult getSetValidationResult(Field field, ParameterGroup parameterGroup) {
+ ValidationResult result = getValidationResult(field, parameterGroup);
+ setResult(result.getStatus());
+
+ return result;
+ }
+
/**
* Construct a validation result for a field.
- *
+ *
* @param field The parameter field
* @param ParameterGroup The parameter group containing the field
* @return the validation result
@@ -92,6 +108,12 @@ public class GroupValidationResult implements ValidationResult {
final Class<?> fieldType = field.getType();
final Object fieldObject = getObjectField(parameterGroup, field);
+ // perform null checks
+ ParameterValidationResult result = new ParameterValidationResult(field, fieldObject);
+ if (!result.isValid()) {
+ return result;
+ }
+
// Nested parameter groups are allowed
if (ParameterGroup.class.isAssignableFrom(fieldType)) {
return new GroupValidationResult((ParameterGroup) fieldObject);
@@ -106,16 +128,16 @@ public class GroupValidationResult implements ValidationResult {
// Collections of parameter groups are not allowed
if (Collection.class.isAssignableFrom(field.getType())) {
checkCollection4ParameterGroups(fieldName, fieldObject);
- return new ParameterValidationResult(field, fieldObject);
+ return result;
}
// It's a regular parameter
- return new ParameterValidationResult(field, fieldObject);
+ return result;
}
/**
* Get the value of a field in an object using a getter found with reflection.
- *
+ *
* @param targetObject The object on which to read the field value
* @param fieldName The name of the field
* @return The field value
@@ -156,7 +178,7 @@ public class GroupValidationResult implements ValidationResult {
/**
* Check if this field is a map of parameter groups indexed by string keys.
- *
+ *
* @param fieldName the name of the collection field.
* @param mapObject the map object to check
*/
@@ -184,7 +206,7 @@ public class GroupValidationResult implements ValidationResult {
/**
* Check if this field contains parameter groups.
- *
+ *
* @param fieldName the name of the collection field.
* @param collectionObject the collection object to check
*/
@@ -234,7 +256,7 @@ public class GroupValidationResult implements ValidationResult {
/**
* Set the validation result on a parameter group.
- *
+ *
* @param status The validation status the parameter group is receiving
* @param message The validation message explaining the validation status
*/
@@ -247,7 +269,7 @@ public class GroupValidationResult implements ValidationResult {
/**
* Set the validation result on a parameter group. On a sequence of calls, the most serious validation status is
* recorded, assuming the status enum ordinal increase in order of severity
- *
+ *
* @param status The validation status the parameter group is receiving
*/
public void setResult(final ValidationStatus status) {
@@ -260,7 +282,7 @@ public class GroupValidationResult implements ValidationResult {
/**
* Set the validation result on a parameter in a parameter group.
- *
+ *
* @param parameterName The name of the parameter
* @param status The validation status the field is receiving
* @param message The validation message explaining the validation status
@@ -281,7 +303,7 @@ public class GroupValidationResult implements ValidationResult {
/**
* Set the validation result on a nested parameter group.
- *
+ *
* @param parameterName The name of the parameter field
* @param nestedValidationResult The validation result from a nested field
*/
@@ -304,7 +326,7 @@ public class GroupValidationResult implements ValidationResult {
/**
* Set the validation result on a nested parameter group map entry.
- *
+ *
* @param parameterName The name of the parameter field
* @param key The key of the map entry
* @param nestedMapValidationResult The validation result from a nested map entry
@@ -329,7 +351,7 @@ public class GroupValidationResult implements ValidationResult {
/**
* Set the validation status on a group map entry.
- *
+ *
* @param parameterName The name of the parameter field
* @param key The key of the map entry
* @param status The validation status of the entry
@@ -395,11 +417,11 @@ public class GroupValidationResult implements ValidationResult {
return validationResultBuilder.toString();
}
-
+
/**
* Check if a field should be included for validation.
- *
+ *
* @param field the field to check for inclusion
* @return true of the field should be included
*/
@@ -425,11 +447,11 @@ public class GroupValidationResult implements ValidationResult {
superclassFields.add(field);
}
}
-
+
// Check the next super class down
currentClass = currentClass.getSuperclass();
}
-
+
return superclassFields;
}
-} \ No newline at end of file
+}
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java
new file mode 100644
index 00000000..f0f34ac1
--- /dev/null
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java
@@ -0,0 +1,61 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.parameters;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+
+/**
+ * Implementation of a parameter group.
+ */
+@NotNull
+@NotBlank
+@Getter
+@Setter
+public class ParameterGroupImpl implements ParameterGroup {
+ /**
+ * Group name. Note: this MUST not be "private" or it will not be validated.
+ */
+ protected String name;
+
+ /**
+ * Constructs the object, with a {@code null} name.
+ */
+ public ParameterGroupImpl() {
+ this.name = null;
+ }
+
+ /**
+ * Constructs the object.
+ *
+ * @param name the group's name
+ */
+ public ParameterGroupImpl(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public GroupValidationResult validate() {
+ return new GroupValidationResult(this);
+ }
+}
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java
index 9c829f4b..57232e1c 100644
--- a/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/ParameterValidationResult.java
@@ -1,26 +1,31 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.common.parameters;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* This class holds the result of the validation of a parameter.
@@ -43,6 +48,41 @@ public class ParameterValidationResult implements ValidationResult {
protected ParameterValidationResult(final Field field, final Object parameterValue) {
this.field = field;
this.parameterValue = parameterValue;
+
+ if (parameterValue == null) {
+ if (getAnyAnnotation(field, NotNull.class) != null) {
+ setResult(ValidationStatus.INVALID, "is null");
+ }
+
+ } else if (parameterValue instanceof String) {
+ if (getAnyAnnotation(field, NotBlank.class) != null && parameterValue.toString().trim().isEmpty()) {
+ setResult(ValidationStatus.INVALID, "must be a non-blank string");
+ }
+
+ } else if (parameterValue instanceof Number) {
+ Min minAnnot = field.getAnnotation(Min.class);
+ if (minAnnot != null && ((Number) parameterValue).longValue() < minAnnot.value()) {
+ setResult(ValidationStatus.INVALID, "must be >= " + minAnnot.value());
+ }
+ }
+ }
+
+ /**
+ * Gets an annotation for a field, first checking the field, itself, and then checking
+ * at the class level. Does not check super classes as class-level annotations should
+ * only apply to the fields within the class.
+ *
+ * @param field field of interest
+ * @param annotClass class of annotation that is desired
+ * @return the field's annotation, or {@code null} if it does not exist
+ */
+ private static <T extends Annotation> T getAnyAnnotation(final Field field, Class<T> annotClass) {
+ T annot = field.getAnnotation(annotClass);
+ if (annot != null) {
+ return annot;
+ }
+
+ return field.getDeclaringClass().getAnnotation(annotClass);
}
/**
@@ -66,14 +106,16 @@ public class ParameterValidationResult implements ValidationResult {
}
/**
- * Set the validation result on on a parameter field.
+ * Set the validation result on on a parameter field.
* @param status The validation status the field is receiving
* @param message The validation message explaining the validation status
*/
@Override
public void setResult(final ValidationStatus status, final String message) {
- this.status = status;
- this.message = message;
+ if (this.status == ValidationStatus.CLEAN) {
+ this.status = status;
+ this.message = message;
+ }
}
/**
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/Min.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/Min.java
new file mode 100644
index 00000000..9ad6d7e0
--- /dev/null
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/Min.java
@@ -0,0 +1,39 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.parameters.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target(FIELD)
+public @interface Min {
+
+ /**
+ * The minimum value allowed.
+ *
+ * @return the minimum value allowed
+ */
+ long value();
+}
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/NotBlank.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/NotBlank.java
new file mode 100644
index 00000000..169fa593
--- /dev/null
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/NotBlank.java
@@ -0,0 +1,37 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.parameters.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Indicates that a field (i.e., String) may not be empty.
+ */
+@Retention(RUNTIME)
+@Target({TYPE, FIELD})
+public @interface NotBlank {
+
+}
diff --git a/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/NotNull.java b/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/NotNull.java
new file mode 100644
index 00000000..3c7bc8b7
--- /dev/null
+++ b/common-parameters/src/main/java/org/onap/policy/common/parameters/annotations/NotNull.java
@@ -0,0 +1,37 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.parameters.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Indicates that a field may not be null.
+ */
+@Retention(RUNTIME)
+@Target({TYPE, FIELD})
+public @interface NotNull {
+
+}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java
index fb08d325..8adf1165 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java
@@ -1,19 +1,20 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -28,12 +29,43 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-
import org.junit.Test;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.testclasses.TestParametersL00;
import org.onap.policy.common.parameters.testclasses.TestParametersL10;
public class TestValidation {
+ private static final String NOT_BLANK_STRING_MESSAGE =
+ "field 'notBlankString' type 'java.lang.String' value '' INVALID, must be a non-blank string\n"
+ .replace('\'', '"');
+
+ private static final String NULL_STRING_MESSAGE =
+ "field 'notNullString' type 'java.lang.String' value 'null' INVALID, is null\n".replace('\'', '"');
+
+
+ private static final String NOT_BLANK_OBJECT_NAME = "notBlankObject";
+ private static final String NOT_BLANK_STRING_NAME = "notBlankString";
+ private static final String NOT_NULL_OBJECT_NAME = "notNullObject";
+ private static final String NOT_NULL_STRING_NAME = "notNullString";
+ private static final String MIN_LONG_NAME = "minLong";
+
+ @NotNull
+ private String notNullString;
+
+ @NotNull
+ private Object notNullObject;
+
+ @NotBlank
+ private String notBlankString;
+
+ @NotBlank
+ private Object notBlankObject;
+
+ @Min(value = 10)
+ private long minLong;
+
@Test
public void testValidationOk() throws IOException {
TestParametersL00 l0Parameters = new TestParametersL00("l0Parameters");
@@ -50,11 +82,11 @@ public class TestValidation {
.replaceAll("\\s+", "");
assertEquals(expectedResult, validationResult.getResult("", " ", true).replaceAll("\\s+", ""));
}
-
+
@Test
public void testValidationObservation() throws IOException {
TestParametersL00 l0Parameters = new TestParametersL00("l0Parameters");
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.OBSERVATION, 3);
String expectedResult = new String(Files.readAllBytes(
@@ -65,7 +97,7 @@ public class TestValidation {
assertTrue(validationResult.isValid());
assertFalse(validationResult.isClean());
assertEquals(expectedResult, validationResult.getResult().replaceAll("\\s+", ""));
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.CLEAN, 3);
l0Parameters.triggerValidationStatus(ValidationStatus.OBSERVATION, 2);
@@ -76,7 +108,7 @@ public class TestValidation {
validationResult = l0Parameters.validate();
assertTrue(validationResult.isValid());
assertEquals(expectedResult, validationResult.getResult().replaceAll("\\s+", ""));
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.CLEAN, 3);
l0Parameters.triggerValidationStatus(ValidationStatus.OBSERVATION, 1);
@@ -87,7 +119,7 @@ public class TestValidation {
validationResult = l0Parameters.validate();
assertTrue(validationResult.isValid());
assertEquals(expectedResult, validationResult.getResult().replaceAll("\\s+", ""));
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.CLEAN, 3);
l0Parameters.triggerValidationStatus(ValidationStatus.OBSERVATION, 0);
@@ -95,11 +127,11 @@ public class TestValidation {
assertTrue(validationResult.isValid());
assertEquals(null, validationResult.getResult());
}
-
+
@Test
public void testValidationWarning() throws IOException {
TestParametersL00 l0Parameters = new TestParametersL00("l0Parameters");
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.WARNING, 3);
String expectedResult = new String(Files.readAllBytes(
@@ -109,7 +141,7 @@ public class TestValidation {
GroupValidationResult validationResult = l0Parameters.validate();
assertTrue(validationResult.isValid());
assertEquals(expectedResult, validationResult.getResult().replaceAll("\\s+", ""));
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.CLEAN, 3);
l0Parameters.triggerValidationStatus(ValidationStatus.WARNING, 2);
@@ -120,7 +152,7 @@ public class TestValidation {
validationResult = l0Parameters.validate();
assertTrue(validationResult.isValid());
assertEquals(expectedResult, validationResult.getResult().replaceAll("\\s+", ""));
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.CLEAN, 3);
l0Parameters.triggerValidationStatus(ValidationStatus.WARNING, 1);
@@ -131,7 +163,7 @@ public class TestValidation {
validationResult = l0Parameters.validate();
assertTrue(validationResult.isValid());
assertEquals(expectedResult, validationResult.getResult().replaceAll("\\s+", ""));
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.CLEAN, 3);
l0Parameters.triggerValidationStatus(ValidationStatus.WARNING, 0);
@@ -139,11 +171,11 @@ public class TestValidation {
assertTrue(validationResult.isValid());
assertEquals(null, validationResult.getResult());
}
-
+
@Test
public void testValidationInvalid() throws IOException {
TestParametersL00 l0Parameters = new TestParametersL00("l0Parameters");
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.INVALID, 3);
String expectedResult = new String(Files.readAllBytes(
@@ -153,7 +185,7 @@ public class TestValidation {
GroupValidationResult validationResult = l0Parameters.validate();
assertFalse(validationResult.isValid());
assertEquals(expectedResult, validationResult.getResult().replaceAll("\\s+", ""));
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.CLEAN, 3);
l0Parameters.triggerValidationStatus(ValidationStatus.INVALID, 2);
@@ -164,7 +196,7 @@ public class TestValidation {
validationResult = l0Parameters.validate();
assertFalse(validationResult.isValid());
assertEquals(expectedResult, validationResult.getResult().replaceAll("\\s+", ""));
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.CLEAN, 3);
l0Parameters.triggerValidationStatus(ValidationStatus.INVALID, 1);
@@ -175,7 +207,7 @@ public class TestValidation {
validationResult = l0Parameters.validate();
assertFalse(validationResult.isValid());
assertEquals(expectedResult, validationResult.getResult().replaceAll("\\s+", ""));
-
+
l0Parameters.triggerValidationStatus(ValidationStatus.CLEAN, 3);
l0Parameters.triggerValidationStatus(ValidationStatus.INVALID, 0);
@@ -183,7 +215,7 @@ public class TestValidation {
assertTrue(validationResult.isValid());
assertEquals(null, validationResult.getResult());
}
-
+
@Test
public void testValidationEmptySubGroup() throws IOException {
TestParametersL10 l10Parameters = new TestParametersL10("l10Parameters");
@@ -192,7 +224,193 @@ public class TestValidation {
GroupValidationResult validationResult = l10Parameters.validate();
assertTrue(validationResult.isValid());
-
+
assertTrue(validationResult.getResult("", "", true).contains("UNDEFINED"));
}
+
+ @Test
+ public void testGetValidationResult() throws Exception {
+ Contained item = new Contained();
+ item.setName("item");
+
+ Container cont = new Container();
+ cont.item = item;
+ GroupValidationResult result = cont.validate();
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertTrue(result.getResult().contains(">= 1"));
+
+ item.minInt = 1000;
+ result = cont.validate();
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ cont.item = null;
+ result = cont.validate();
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertTrue(result.getResult().contains("is null"));
+ }
+
+ @Test
+ public void testParameterValidationResult_NotNull() throws Exception {
+ ParameterValidationResult result = new ParameterValidationResult(
+ TestValidation.class.getDeclaredField(NOT_NULL_STRING_NAME), null);
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertEquals(NULL_STRING_MESSAGE, result.getResult());
+
+ // don't allow overwrite - values should remain unchanged
+ result.setResult(ValidationStatus.WARNING, "unknown");
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertEquals(NULL_STRING_MESSAGE, result.getResult());
+
+ // non-null should be OK
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_NULL_STRING_NAME), "");
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ // non-null should be OK
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_NULL_STRING_NAME), "abc");
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ /*
+ * Check plain object fields, too.
+ */
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_NULL_OBJECT_NAME), null);
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertEquals("field 'notNullObject' type 'java.lang.Object' value 'null' INVALID, is null\n".replace('\'', '"'),
+ result.getResult());
+
+ // non-null should be OK
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_NULL_OBJECT_NAME),
+ new Object());
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ /*
+ * Class-level annotation.
+ */
+
+ result = new ParameterValidationResult(NotNullSub.class.getDeclaredField(NOT_NULL_STRING_NAME), null);
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertEquals(NULL_STRING_MESSAGE, result.getResult());
+
+ // non-null should be OK
+ result = new ParameterValidationResult(NotNullSub.class.getDeclaredField(NOT_NULL_STRING_NAME), "");
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ /*
+ * Super class annotation - null should be OK
+ */
+ result = new ParameterValidationResult(NotNullSub2.class.getDeclaredField("anotherString"), null);
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+ }
+
+ @Test
+ public void testParameterValidationResult_NotBlank() throws Exception {
+ ParameterValidationResult result =
+ new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_BLANK_STRING_NAME), "");
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertEquals(NOT_BLANK_STRING_MESSAGE, result.getResult());
+
+ // spaces only
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_BLANK_STRING_NAME), " \t");
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+
+ // null should be OK
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_BLANK_STRING_NAME), null);
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ // null should be OK
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_BLANK_STRING_NAME), "abc");
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ /*
+ * Check plain object fields, too.
+ */
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_BLANK_OBJECT_NAME), null);
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_BLANK_OBJECT_NAME),
+ new Object());
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ /*
+ * Class-level annotation.
+ */
+ result = new ParameterValidationResult(NotBlankSub.class.getDeclaredField(NOT_BLANK_STRING_NAME), "");
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertEquals(NOT_BLANK_STRING_MESSAGE, result.getResult());
+
+ // non-null should be OK
+ result = new ParameterValidationResult(NotBlankSub.class.getDeclaredField(NOT_BLANK_STRING_NAME), "abc");
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+ }
+
+ @Test
+ public void testParameterValidationResult_Min() throws Exception {
+ ParameterValidationResult result =
+ new ParameterValidationResult(TestValidation.class.getDeclaredField(MIN_LONG_NAME), 9L);
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertEquals("field 'minLong' type 'long' value '9' INVALID, must be >= 10\n".replace('\'', '"'),
+ result.getResult());
+
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(MIN_LONG_NAME), -2);
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+ assertEquals("field 'minLong' type 'long' value '-2' INVALID, must be >= 10\n".replace('\'', '"'),
+ result.getResult());
+
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(MIN_LONG_NAME), 10L);
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+
+ result = new ParameterValidationResult(TestValidation.class.getDeclaredField(MIN_LONG_NAME), 11);
+ assertEquals(ValidationStatus.CLEAN, result.getStatus());
+ }
+
+ // these classes are used to test class-level annotations
+
+
+ private static class EmptyBase {
+
+ }
+
+ @NotNull
+ private static class NotNullSub extends EmptyBase {
+ @SuppressWarnings("unused")
+ private String notNullString;
+ }
+
+ private static class NotNullSub2 extends NotNullSub {
+ @SuppressWarnings("unused")
+ private String anotherString;
+ }
+
+ @NotBlank
+ private static class NotBlankSub extends EmptyBase {
+ @SuppressWarnings("unused")
+ private String notBlankString;
+ }
+
+ private static class Contained extends ParameterGroupImpl {
+ @Min(value = 1)
+ private int minInt;
+
+ public Contained() {
+ super("Contained");
+ }
+
+ @SuppressWarnings("unused")
+ public int getMinInt() {
+ return minInt;
+ }
+ }
+
+ private static class Container extends ParameterGroupImpl {
+ @NotNull
+ private Contained item;
+
+ public Container() {
+ super("Container");
+ }
+
+ @SuppressWarnings("unused")
+ public Contained getItem() {
+ return item;
+ }
+ }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/EmptyParameterGroup.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/EmptyParameterGroup.java
index 505b2ce4..d1787482 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/EmptyParameterGroup.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/EmptyParameterGroup.java
@@ -1,47 +1,31 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.common.parameters.testclasses;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-public class EmptyParameterGroup implements ParameterGroup {
- private String name;
+public class EmptyParameterGroup extends ParameterGroupImpl {
- public EmptyParameterGroup(final String name) {
- this.name = name;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
+ public EmptyParameterGroup(String name) {
+ super(name);
}
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupMissingGetter.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupMissingGetter.java
index e05eea3f..e6c85923 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupMissingGetter.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupMissingGetter.java
@@ -1,36 +1,35 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.common.parameters.testclasses;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-public class ParameterGroupMissingGetter implements ParameterGroup {
- private String name;
+public class ParameterGroupMissingGetter extends ParameterGroupImpl {
private String value;
public ParameterGroupMissingGetter(final String name) {
- this.name = name;
+ super(name);
}
-
+
public String getTheValue() {
return value;
}
@@ -38,19 +37,4 @@ public class ParameterGroupMissingGetter implements ParameterGroup {
public void setValue(String value) {
this.value = value;
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupPrivateGetter.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupPrivateGetter.java
index 78a7c157..1d90ca1f 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupPrivateGetter.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupPrivateGetter.java
@@ -1,36 +1,35 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.common.parameters.testclasses;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-public class ParameterGroupPrivateGetter implements ParameterGroup {
- private String name;
+public class ParameterGroupPrivateGetter extends ParameterGroupImpl {
private String value;
public ParameterGroupPrivateGetter(final String name) {
- this.name = name;
+ super(name);
}
-
+
public String getTheValue() {
return getValue();
}
@@ -42,19 +41,4 @@ public class ParameterGroupPrivateGetter implements ParameterGroup {
public void setValue(String value) {
this.value = value;
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithArray.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithArray.java
index c448cea1..e37b47ae 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithArray.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithArray.java
@@ -1,52 +1,36 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.common.parameters.testclasses;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-public class ParameterGroupWithArray implements ParameterGroup {
- private String name;
+public class ParameterGroupWithArray extends ParameterGroupImpl {
private int[] intArray = {1, 2, 3};
public ParameterGroupWithArray(final String name) {
- this.name = name;
+ super(name);
}
public int[] getIntArray() {
return intArray;
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithCollection.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithCollection.java
index 7f2c0ab5..ee7c1715 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithCollection.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithCollection.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -22,21 +23,18 @@ package org.onap.policy.common.parameters.testclasses;
import java.util.ArrayList;
import java.util.List;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-
-public class ParameterGroupWithCollection implements ParameterGroup {
- private String name;
+public class ParameterGroupWithCollection extends ParameterGroupImpl {
private List<Integer> intArrayList = new ArrayList<>();
/**
* Create a test parameter group.
- *
+ *
* @param name the parameter group name
*/
public ParameterGroupWithCollection(final String name) {
- this.name = name;
+ super(name);
intArrayList.add(1);
intArrayList.add(2);
@@ -46,19 +44,4 @@ public class ParameterGroupWithCollection implements ParameterGroup {
public List<Integer> getIntArrayList() {
return intArrayList;
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapKey.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapKey.java
index 57a5a110..b3c7d1b7 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapKey.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapKey.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -22,12 +23,10 @@ package org.onap.policy.common.parameters.testclasses;
import java.util.LinkedHashMap;
import java.util.Map;
-
-import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-public class ParameterGroupWithIllegalMapKey implements ParameterGroup {
- private String name;
+public class ParameterGroupWithIllegalMapKey extends ParameterGroupImpl {
private Map<Integer, ParameterGroup> badMap = new LinkedHashMap<>();
/**
@@ -35,8 +34,8 @@ public class ParameterGroupWithIllegalMapKey implements ParameterGroup {
* @param name the parameter group name
*/
public ParameterGroupWithIllegalMapKey(final String name) {
- this.name = name;
-
+ super(name);
+
badMap.put(1, new TestParametersLGeneric("One"));
badMap.put(2, new TestParametersLGeneric("Two"));
badMap.put(3, new TestParametersLGeneric("Three"));
@@ -45,20 +44,4 @@ public class ParameterGroupWithIllegalMapKey implements ParameterGroup {
public Map<Integer, ParameterGroup> getBadMap() {
return badMap;
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
-
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapValue.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapValue.java
index 39e35d9c..4df708a4 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapValue.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapValue.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -22,12 +23,9 @@ package org.onap.policy.common.parameters.testclasses;
import java.util.LinkedHashMap;
import java.util.Map;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-
-public class ParameterGroupWithIllegalMapValue implements ParameterGroup {
- private String name;
+public class ParameterGroupWithIllegalMapValue extends ParameterGroupImpl {
private Map<String, Integer> intMap = new LinkedHashMap<>();
/**
@@ -35,8 +33,8 @@ public class ParameterGroupWithIllegalMapValue implements ParameterGroup {
* @param name the parameter group name
*/
public ParameterGroupWithIllegalMapValue(final String name) {
- this.name = name;
-
+ super(name);
+
intMap.put("One", 1);
intMap.put("Two", 2);
intMap.put("Three", 3);
@@ -45,19 +43,4 @@ public class ParameterGroupWithIllegalMapValue implements ParameterGroup {
public Map<String, Integer> getIntMap() {
return intMap;
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullCollection.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullCollection.java
index 9b661bd5..35752c75 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullCollection.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullCollection.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -21,12 +22,9 @@
package org.onap.policy.common.parameters.testclasses;
import java.util.List;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-
-public class ParameterGroupWithNullCollection implements ParameterGroup {
- private String name;
+public class ParameterGroupWithNullCollection extends ParameterGroupImpl {
private List<Integer> nullList = null;
/**
@@ -34,25 +32,10 @@ public class ParameterGroupWithNullCollection implements ParameterGroup {
* @param name the parameter group name
*/
public ParameterGroupWithNullCollection(final String name) {
- this.name = name;
+ super(name);
}
public List<Integer> getNullList() {
return nullList;
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullMapValue.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullMapValue.java
index ac863a42..1a640023 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullMapValue.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullMapValue.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -21,12 +22,9 @@
package org.onap.policy.common.parameters.testclasses;
import java.util.Map;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-
-public class ParameterGroupWithNullMapValue implements ParameterGroup {
- private String name;
+public class ParameterGroupWithNullMapValue extends ParameterGroupImpl {
private Map<String, Integer> nullMap = null;
/**
@@ -34,25 +32,10 @@ public class ParameterGroupWithNullMapValue implements ParameterGroup {
* @param name the parameter group name
*/
public ParameterGroupWithNullMapValue(final String name) {
- this.name = name;
+ super(name);
}
public Map<String, Integer> getNullMap() {
return nullMap;
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullSubGroup.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullSubGroup.java
index 830c8117..7fe1402f 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullSubGroup.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullSubGroup.java
@@ -1,30 +1,30 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.common.parameters.testclasses;
-import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-public class ParameterGroupWithNullSubGroup implements ParameterGroup {
- private String name;
+public class ParameterGroupWithNullSubGroup extends ParameterGroupImpl {
private ParameterGroup subGroup = null;
/**
@@ -32,25 +32,10 @@ public class ParameterGroupWithNullSubGroup implements ParameterGroup {
* @param name the parameter group name
*/
public ParameterGroupWithNullSubGroup(final String name) {
- this.name = name;
+ super(name);
}
public ParameterGroup getSubGroup() {
return subGroup;
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java
index 3966e49c..08c799f5 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -22,12 +23,10 @@ package org.onap.policy.common.parameters.testclasses;
import java.util.ArrayList;
import java.util.List;
-
-import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
-public class ParameterGroupWithParameterGroupCollection implements ParameterGroup {
- private String name;
+public class ParameterGroupWithParameterGroupCollection extends ParameterGroupImpl {
private List<ParameterGroup> parameterGroupArrayList = new ArrayList<>();
/**
@@ -35,8 +34,8 @@ public class ParameterGroupWithParameterGroupCollection implements ParameterGrou
* @param name the parameter group name
*/
public ParameterGroupWithParameterGroupCollection(final String name) {
- this.name = name;
-
+ super(name);
+
parameterGroupArrayList.add(new TestParametersLGeneric("Generic0"));
parameterGroupArrayList.add(new TestParametersLGeneric("Generic1"));
parameterGroupArrayList.add(new TestParametersLGeneric("Generic2"));
@@ -45,19 +44,4 @@ public class ParameterGroupWithParameterGroupCollection implements ParameterGrou
public List<ParameterGroup> getParameterGroupArrayList() {
return parameterGroupArrayList;
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL00.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL00.java
index b4a7e9c8..748eb902 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL00.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL00.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -23,16 +24,14 @@ package org.onap.policy.common.parameters.testclasses;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
-
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterConstants;
-import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.ValidationStatus;
-public class TestParametersL00 implements ParameterGroup {
+public class TestParametersL00 extends ParameterGroupImpl {
private static final String A_CONSTANT = "A Constant";
-
- private String name = A_CONSTANT;
+
private int l00IntField = 0;
private String l00StringField = "Legal " + this.getClass().getCanonicalName();
private TestParametersL10 l00L10Nested = new TestParametersL10("l00L10Nested");
@@ -45,16 +44,16 @@ public class TestParametersL00 implements ParameterGroup {
* Default constructor.
*/
public TestParametersL00() {
- // Default Cnstructor
+ super(A_CONSTANT);
}
/**
* Create a test parameter group.
- *
+ *
* @param name the parameter group name
*/
public TestParametersL00(final String name) {
- this.name = name;
+ super(name);
TestParametersLGeneric l00LGenericNestedMapVal0 = new TestParametersLGeneric("l00LGenericNestedMapVal0");
l00LGenericNestedMap.put(l00LGenericNestedMapVal0.getName(), l00LGenericNestedMapVal0);
@@ -94,10 +93,6 @@ public class TestParametersL00 implements ParameterGroup {
this.isSomeFlag = isSomeFlag;
}
- public void setName(String name) {
- this.name = name;
- }
-
public void setL00IntField(int l00IntField) {
this.l00IntField = l00IntField;
}
@@ -120,7 +115,7 @@ public class TestParametersL00 implements ParameterGroup {
/**
* Trigger a validation message.
- *
+ *
* @param triggerStatus Validation status to trigger
* @param level Number of levels to recurse before stopping
*/
@@ -162,15 +157,10 @@ public class TestParametersL00 implements ParameterGroup {
}
@Override
- public String getName() {
- return name;
- }
-
- @Override
public GroupValidationResult validate() {
- GroupValidationResult validationResult = new GroupValidationResult(this);
+ GroupValidationResult validationResult = super.validate();
- if (name == null || name.trim().length() == 0) {
+ if (getName() == null || getName().trim().length() == 0) {
validationResult.setResult("name", ValidationStatus.INVALID, "name must be a non-blank string");
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL10.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL10.java
index f63ec3f9..8ad682ff 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL10.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL10.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -23,14 +24,12 @@ package org.onap.policy.common.parameters.testclasses;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
-
import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterConstants;
-import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.ValidationStatus;
-public class TestParametersL10 implements ParameterGroup {
- private String name;
+public class TestParametersL10 extends ParameterGroupImpl {
private int l10IntField = 0;
private String l10StringField = "Legal " + this.getClass().getCanonicalName();
private TestParametersLGeneric l10LGenericNested0 = new TestParametersLGeneric("l10LGenericNested0");
@@ -43,14 +42,14 @@ public class TestParametersL10 implements ParameterGroup {
public TestParametersL10() {
// Default Constructor
}
-
+
/**
* Create a test parameter group.
- *
+ *
* @param name the parameter group name
*/
public TestParametersL10(final String name) {
- this.name = name;
+ super(name);
TestParametersLGeneric l10LGenericNestedMapVal0 = new TestParametersLGeneric("l10LGenericNestedMapVal0");
l10LGenericNestedMap.put(l10LGenericNestedMapVal0.getName(), l10LGenericNestedMapVal0);
@@ -78,10 +77,6 @@ public class TestParametersL10 implements ParameterGroup {
return l10LGenericNestedMap;
}
- public void setName(String name) {
- this.name = name;
- }
-
public void setL10IntField(int l10IntField) {
this.l10IntField = l10IntField;
}
@@ -104,7 +99,7 @@ public class TestParametersL10 implements ParameterGroup {
/**
* Trigger a validation message.
- *
+ *
* @param level Number of levels to recurse before stopping
*/
public void triggerValidationStatus(final ValidationStatus triggerStatus, int level) {
@@ -145,13 +140,8 @@ public class TestParametersL10 implements ParameterGroup {
}
@Override
- public String getName() {
- return this.name;
- }
-
- @Override
public GroupValidationResult validate() {
- GroupValidationResult validationResult = new GroupValidationResult(this);
+ GroupValidationResult validationResult = super.validate();
if (l10StringField == null || l10StringField.trim().length() == 0) {
validationResult.setResult("l10StringField", ValidationStatus.INVALID,
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersLGeneric.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersLGeneric.java
index 2d263fc7..2fc04180 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersLGeneric.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersLGeneric.java
@@ -1,19 +1,20 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -21,29 +22,31 @@
package org.onap.policy.common.parameters.testclasses;
import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterConstants;
-import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
-public class TestParametersLGeneric implements ParameterGroup {
- private String name;
+public class TestParametersLGeneric extends ParameterGroupImpl {
private int lgenericIntField = 0;
+
+ @NotNull @NotBlank
private String lgenericStringField = "Legal " + this.getClass().getCanonicalName();
-
+
/**
* Default constructor.
*/
public TestParametersLGeneric() {
// Default Constructor
}
-
+
/**
* Create a test parameter group.
- *
+ *
* @param name the parameter group name
*/
public TestParametersLGeneric(final String name) {
- this.name = name;
+ super(name);
}
public int getLgenericIntField() {
@@ -54,10 +57,6 @@ public class TestParametersLGeneric implements ParameterGroup {
return lgenericStringField;
}
- public void setName(String name) {
- this.name = name;
- }
-
public void setLgenericIntField(int lgenericIntField) {
this.lgenericIntField = lgenericIntField;
}
@@ -68,7 +67,7 @@ public class TestParametersLGeneric implements ParameterGroup {
/**
* Trigger a validation message.
- *
+ *
* @param level Number of levels to recurse before stopping
*/
public void triggerValidationStatus(final ValidationStatus triggerStatus, int level) {
@@ -103,26 +102,15 @@ public class TestParametersLGeneric implements ParameterGroup {
}
@Override
- public String getName() {
- return this.name;
- }
-
- @Override
public GroupValidationResult validate() {
- GroupValidationResult validationResult = new GroupValidationResult(this);
+ GroupValidationResult validationResult = super.validate();
- if (lgenericStringField == null || lgenericStringField.trim().length() == 0) {
- validationResult.setResult("lgenericStringField", ValidationStatus.INVALID,
- "lgenericStringField must be a non-blank string");
- } else if (lgenericStringField.equals("lgenericStringField")) {
+ if ("lgenericStringField".equals(lgenericStringField)) {
validationResult.setResult("lgenericStringField", ValidationStatus.WARNING,
"using the field name for the parameter value is dangerous");
- } else if (lgenericStringField.equals("aString")) {
+ } else if ("aString".equals(lgenericStringField)) {
validationResult.setResult("lgenericStringField", ValidationStatus.OBSERVATION,
"this value for name is unhelpful");
- } else {
- validationResult.setResult("lgenericStringField", ValidationStatus.CLEAN,
- ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
}
if (lgenericIntField < 0) {
@@ -134,9 +122,6 @@ public class TestParametersLGeneric implements ParameterGroup {
} else if (lgenericIntField == 2) {
validationResult.setResult("lgenericIntField", ValidationStatus.OBSERVATION,
"this field has been set to 2");
- } else {
- validationResult.setResult("lgenericIntField", ValidationStatus.CLEAN,
- ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
}
return validationResult;
diff --git a/common-parameters/src/test/resources/expectedValidationResults/TestJsonYamlValidationResult.txt b/common-parameters/src/test/resources/expectedValidationResults/TestJsonYamlValidationResult.txt
index 8439e0b1..64af7247 100644
--- a/common-parameters/src/test/resources/expectedValidationResults/TestJsonYamlValidationResult.txt
+++ b/common-parameters/src/test/resources/expectedValidationResults/TestJsonYamlValidationResult.txt
@@ -1,41 +1,41 @@
parameter group "l00NameFromFile" type "org.onap.policy.common.parameters.testclasses.TestParametersL00" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l00NameFromFile" CLEAN, parameter has status CLEAN
field "l00IntField" type "int" value "1" CLEAN, parameter has status CLEAN
field "l00StringField" type "java.lang.String" value "l00 string field value from file" CLEAN, parameter has status CLEAN
parameter group "l00L10NestedNameFromFile" type "org.onap.policy.common.parameters.testclasses.TestParametersL10" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l00L10NestedNameFromFile" CLEAN, parameter has status CLEAN
field "l10IntField" type "int" value "1" CLEAN, parameter has status CLEAN
field "l10StringField" type "java.lang.String" value "l00 L10 nested string field value from file" CLEAN, parameter has status CLEAN
parameter group "l10LGenericNested0NameFromFile" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l10LGenericNested0NameFromFile" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "1" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "l10 generic nested 0 string field value from file" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l10LGenericNested0NameFromFile" CLEAN, parameter has status CLEAN
parameter group "l10LGenericNested1NameFromFile" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l10LGenericNested1NameFromFile" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "1" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "l10 generic nested 1 string field value from file" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l10LGenericNested1NameFromFile" CLEAN, parameter has status CLEAN
parameter group map "l10LGenericNestedMap" CLEAN, parameter group map has status CLEAN
parameter group "L10Entry0Name" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "L10Entry0Name" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "1" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "L10Entry0 value from file" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "L10Entry0Name" CLEAN, parameter has status CLEAN
parameter group "L10Entry1Name" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "L10Entry1Name" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "1" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "L10Entry1 value from file" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "L10Entry1Name" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l00L10NestedNameFromFile" CLEAN, parameter has status CLEAN
parameter group "l00GenericNestedNameFromFile" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l00GenericNestedNameFromFile" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "1" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "l00 generic nested string field value from file" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l00GenericNestedNameFromFile" CLEAN, parameter has status CLEAN
parameter group map "l00LGenericNestedMap" CLEAN, parameter group map has status CLEAN
parameter group "L00Entry0Name" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "L00Entry0Name" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "1" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "L00Entry0 value from file" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "L00Entry0Name" CLEAN, parameter has status CLEAN
parameter group "L00Entry1Name" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "L00Entry1Name" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "1" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "L00Entry1 value from file" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "L00Entry1Name" CLEAN, parameter has status CLEAN
field "isSomeFlag" type "boolean" value "false" CLEAN, parameter has status CLEAN
field "someNonIsFlag" type "boolean" value "false" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l00NameFromFile" CLEAN, parameter has status CLEAN
\ No newline at end of file
diff --git a/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_0_OK.txt b/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_0_OK.txt
index 2774f35c..d6b43312 100644
--- a/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_0_OK.txt
+++ b/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_0_OK.txt
@@ -1,41 +1,41 @@
parameter group "l0Parameters" type "org.onap.policy.common.parameters.testclasses.TestParametersL00" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l0Parameters" CLEAN, parameter has status CLEAN
field "l00IntField" type "int" value "0" CLEAN, parameter has status CLEAN
field "l00StringField" type "java.lang.String" value "Legal org.onap.policy.common.parameters.testclasses.TestParametersL00" CLEAN, parameter has status CLEAN
parameter group "l00L10Nested" type "org.onap.policy.common.parameters.testclasses.TestParametersL10" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l00L10Nested" CLEAN, parameter has status CLEAN
field "l10IntField" type "int" value "0" CLEAN, parameter has status CLEAN
field "l10StringField" type "java.lang.String" value "Legal org.onap.policy.common.parameters.testclasses.TestParametersL10" CLEAN, parameter has status CLEAN
parameter group "l10LGenericNested0" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l10LGenericNested0" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "0" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "Legal org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l10LGenericNested0" CLEAN, parameter has status CLEAN
parameter group "l10LGenericNested1" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l10LGenericNested1" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "0" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "Legal org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l10LGenericNested1" CLEAN, parameter has status CLEAN
parameter group map "l10LGenericNestedMap" CLEAN, parameter group map has status CLEAN
parameter group "l10LGenericNestedMapVal0" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l10LGenericNestedMapVal0" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "0" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "Legal org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l10LGenericNestedMapVal0" CLEAN, parameter has status CLEAN
parameter group "l10LGenericNestedMapVal1" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l10LGenericNestedMapVal1" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "0" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "Legal org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l10LGenericNestedMapVal1" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l00L10Nested" CLEAN, parameter has status CLEAN
parameter group "l00LGenericNested" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l00LGenericNested" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "0" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "Legal org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l00LGenericNested" CLEAN, parameter has status CLEAN
parameter group map "l00LGenericNestedMap" CLEAN, parameter group map has status CLEAN
parameter group "l00LGenericNestedMapVal0" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l00LGenericNestedMapVal0" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "0" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "Legal org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l00LGenericNestedMapVal0" CLEAN, parameter has status CLEAN
parameter group "l00LGenericNestedMapVal1" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter group has status CLEAN
- field "name" type "java.lang.String" value "l00LGenericNestedMapVal1" CLEAN, parameter has status CLEAN
field "lgenericIntField" type "int" value "0" CLEAN, parameter has status CLEAN
field "lgenericStringField" type "java.lang.String" value "Legal org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l00LGenericNestedMapVal1" CLEAN, parameter has status CLEAN
field "isSomeFlag" type "boolean" value "false" CLEAN, parameter has status CLEAN
field "someNonIsFlag" type "boolean" value "false" CLEAN, parameter has status CLEAN
+ field "name" type "java.lang.String" value "l0Parameters" CLEAN, parameter has status CLEAN
\ No newline at end of file
diff --git a/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_2_Invalid.txt b/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_2_Invalid.txt
index 0dec4a61..d9301997 100644
--- a/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_2_Invalid.txt
+++ b/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_2_Invalid.txt
@@ -6,11 +6,11 @@ parameter group "l0Parameters" type "org.onap.policy.common.parameters.testclass
field "l10StringField" type "java.lang.String" value "" INVALID, l10StringField must be a non-blank string
parameter group "l00LGenericNested" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" INVALID, parameter group has status INVALID
field "lgenericIntField" type "int" value "-1" INVALID, lgenericIntField must be a positive integer
- field "lgenericStringField" type "java.lang.String" value "" INVALID, lgenericStringField must be a non-blank string
+ field "lgenericStringField" type "java.lang.String" value "" INVALID, must be a non-blank string
parameter group map "l00LGenericNestedMap" INVALID, parameter group has status INVALID
parameter group "l00LGenericNestedMapVal0" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" INVALID, parameter group has status INVALID
field "lgenericIntField" type "int" value "-1" INVALID, lgenericIntField must be a positive integer
- field "lgenericStringField" type "java.lang.String" value "" INVALID, lgenericStringField must be a non-blank string
+ field "lgenericStringField" type "java.lang.String" value "" INVALID, must be a non-blank string
parameter group "l00LGenericNestedMapVal1" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" INVALID, parameter group has status INVALID
field "lgenericIntField" type "int" value "-1" INVALID, lgenericIntField must be a positive integer
- field "lgenericStringField" type "java.lang.String" value "" INVALID, lgenericStringField must be a non-blank string \ No newline at end of file
+ field "lgenericStringField" type "java.lang.String" value "" INVALID, must be a non-blank string \ No newline at end of file
diff --git a/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_3_Invalid.txt b/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_3_Invalid.txt
index 762ef46c..e45a7a6b 100644
--- a/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_3_Invalid.txt
+++ b/common-parameters/src/test/resources/expectedValidationResults/TestParametersL0_3_Invalid.txt
@@ -6,24 +6,24 @@ parameter group "l0Parameters" type "org.onap.policy.common.parameters.testclass
field "l10StringField" type "java.lang.String" value "" INVALID, l10StringField must be a non-blank string
parameter group "l10LGenericNested0" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" INVALID, parameter group has status INVALID
field "lgenericIntField" type "int" value "-1" INVALID, lgenericIntField must be a positive integer
- field "lgenericStringField" type "java.lang.String" value "" INVALID, lgenericStringField must be a non-blank string
+ field "lgenericStringField" type "java.lang.String" value "" INVALID, must be a non-blank string
parameter group "l10LGenericNested1" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" INVALID, parameter group has status INVALID
field "lgenericIntField" type "int" value "-1" INVALID, lgenericIntField must be a positive integer
- field "lgenericStringField" type "java.lang.String" value "" INVALID, lgenericStringField must be a non-blank string
+ field "lgenericStringField" type "java.lang.String" value "" INVALID, must be a non-blank string
parameter group map "l10LGenericNestedMap" INVALID, parameter group has status INVALID
parameter group "l10LGenericNestedMapVal0" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" INVALID, parameter group has status INVALID
field "lgenericIntField" type "int" value "-1" INVALID, lgenericIntField must be a positive integer
- field "lgenericStringField" type "java.lang.String" value "" INVALID, lgenericStringField must be a non-blank string
+ field "lgenericStringField" type "java.lang.String" value "" INVALID, must be a non-blank string
parameter group "l10LGenericNestedMapVal1" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" INVALID, parameter group has status INVALID
field "lgenericIntField" type "int" value "-1" INVALID, lgenericIntField must be a positive integer
- field "lgenericStringField" type "java.lang.String" value "" INVALID, lgenericStringField must be a non-blank string
+ field "lgenericStringField" type "java.lang.String" value "" INVALID, must be a non-blank string
parameter group "l00LGenericNested" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" INVALID, parameter group has status INVALID
field "lgenericIntField" type "int" value "-1" INVALID, lgenericIntField must be a positive integer
- field "lgenericStringField" type "java.lang.String" value "" INVALID, lgenericStringField must be a non-blank string
+ field "lgenericStringField" type "java.lang.String" value "" INVALID, must be a non-blank string
parameter group map "l00LGenericNestedMap" INVALID, parameter group has status INVALID
parameter group "l00LGenericNestedMapVal0" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" INVALID, parameter group has status INVALID
field "lgenericIntField" type "int" value "-1" INVALID, lgenericIntField must be a positive integer
- field "lgenericStringField" type "java.lang.String" value "" INVALID, lgenericStringField must be a non-blank string
+ field "lgenericStringField" type "java.lang.String" value "" INVALID, must be a non-blank string
parameter group "l00LGenericNestedMapVal1" type "org.onap.policy.common.parameters.testclasses.TestParametersLGeneric" INVALID, parameter group has status INVALID
field "lgenericIntField" type "int" value "-1" INVALID, lgenericIntField must be a positive integer
- field "lgenericStringField" type "java.lang.String" value "" INVALID, lgenericStringField must be a non-blank string \ No newline at end of file
+ field "lgenericStringField" type "java.lang.String" value "" INVALID, must be a non-blank string \ No newline at end of file