2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.common.parameters.testclasses;
23 import org.onap.policy.common.parameters.GroupValidationResult;
24 import org.onap.policy.common.parameters.ParameterConstants;
25 import org.onap.policy.common.parameters.ParameterGroup;
26 import org.onap.policy.common.parameters.ValidationStatus;
28 public class TestParametersLGeneric implements ParameterGroup {
30 private int lgenericIntField = 0;
31 private String lgenericStringField = "Legal " + this.getClass().getCanonicalName();
34 * Default constructor.
36 public TestParametersLGeneric() {
37 // Default Constructor
41 * Create a test parameter group.
43 * @param name the parameter group name
45 public TestParametersLGeneric(final String name) {
49 public int getLgenericIntField() {
50 return lgenericIntField;
53 public String getLgenericStringField() {
54 return lgenericStringField;
57 public void setName(String name) {
61 public void setLgenericIntField(int lgenericIntField) {
62 this.lgenericIntField = lgenericIntField;
65 public void setLgenericStringField(String lgenericStringField) {
66 this.lgenericStringField = lgenericStringField;
70 * Trigger a validation message.
72 * @param level Number of levels to recurse before stopping
74 public void triggerValidationStatus(final ValidationStatus triggerStatus, int level) {
82 switch (triggerStatus) {
84 lgenericStringField = "Legal " + this.getClass().getCanonicalName();
88 lgenericStringField = "aString";
92 lgenericStringField = "lgenericStringField";
96 lgenericStringField = "";
97 lgenericIntField = -1;
106 public String getName() {
111 public GroupValidationResult validate() {
112 GroupValidationResult validationResult = new GroupValidationResult(this);
114 if (lgenericStringField == null || lgenericStringField.trim().length() == 0) {
115 validationResult.setResult("lgenericStringField", ValidationStatus.INVALID,
116 "lgenericStringField must be a non-blank string");
117 } else if (lgenericStringField.equals("lgenericStringField")) {
118 validationResult.setResult("lgenericStringField", ValidationStatus.WARNING,
119 "using the field name for the parameter value is dangerous");
120 } else if (lgenericStringField.equals("aString")) {
121 validationResult.setResult("lgenericStringField", ValidationStatus.OBSERVATION,
122 "this value for name is unhelpful");
124 validationResult.setResult("lgenericStringField", ValidationStatus.CLEAN,
125 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
128 if (lgenericIntField < 0) {
129 validationResult.setResult("lgenericIntField", ValidationStatus.INVALID,
130 "lgenericIntField must be a positive integer");
131 } else if (lgenericIntField > 2) {
132 validationResult.setResult("lgenericIntField", ValidationStatus.WARNING,
133 "values greater than 2 are not recommended");
134 } else if (lgenericIntField == 2) {
135 validationResult.setResult("lgenericIntField", ValidationStatus.OBSERVATION,
136 "this field has been set to 2");
138 validationResult.setResult("lgenericIntField", ValidationStatus.CLEAN,
139 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
142 return validationResult;