2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.common.parameters.testclasses;
24 import org.onap.policy.common.parameters.GroupValidationResult;
25 import org.onap.policy.common.parameters.ParameterGroupImpl;
26 import org.onap.policy.common.parameters.ValidationStatus;
27 import org.onap.policy.common.parameters.annotations.NotBlank;
28 import org.onap.policy.common.parameters.annotations.NotNull;
30 public class TestParametersLGeneric extends ParameterGroupImpl {
31 private int lgenericIntField = 0;
34 private String lgenericStringField = "Legal " + this.getClass().getCanonicalName();
37 * Default constructor.
39 public TestParametersLGeneric() {
40 // Default Constructor
44 * Create a test parameter group.
46 * @param name the parameter group name
48 public TestParametersLGeneric(final String name) {
52 public int getLgenericIntField() {
53 return lgenericIntField;
56 public String getLgenericStringField() {
57 return lgenericStringField;
60 public void setLgenericIntField(int lgenericIntField) {
61 this.lgenericIntField = lgenericIntField;
64 public void setLgenericStringField(String lgenericStringField) {
65 this.lgenericStringField = lgenericStringField;
69 * Trigger a validation message.
71 * @param level Number of levels to recurse before stopping
73 public void triggerValidationStatus(final ValidationStatus triggerStatus, int level) {
81 switch (triggerStatus) {
83 lgenericStringField = "Legal " + this.getClass().getCanonicalName();
87 lgenericStringField = "aString";
91 lgenericStringField = "lgenericStringField";
95 lgenericStringField = "";
96 lgenericIntField = -1;
105 public GroupValidationResult validate() {
106 GroupValidationResult validationResult = super.validate();
108 if ("lgenericStringField".equals(lgenericStringField)) {
109 validationResult.setResult("lgenericStringField", ValidationStatus.WARNING,
110 "using the field name for the parameter value is dangerous");
111 } else if ("aString".equals(lgenericStringField)) {
112 validationResult.setResult("lgenericStringField", ValidationStatus.OBSERVATION,
113 "this value for name is unhelpful");
116 if (lgenericIntField < 0) {
117 validationResult.setResult("lgenericIntField", ValidationStatus.INVALID,
118 "lgenericIntField must be a positive integer");
119 } else if (lgenericIntField > 2) {
120 validationResult.setResult("lgenericIntField", ValidationStatus.WARNING,
121 "values greater than 2 are not recommended");
122 } else if (lgenericIntField == 2) {
123 validationResult.setResult("lgenericIntField", ValidationStatus.OBSERVATION,
124 "this field has been set to 2");
127 return validationResult;