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 java.util.LinkedHashMap;
25 import java.util.Map.Entry;
27 import org.onap.policy.common.parameters.GroupValidationResult;
28 import org.onap.policy.common.parameters.ParameterConstants;
29 import org.onap.policy.common.parameters.ParameterGroup;
30 import org.onap.policy.common.parameters.ValidationStatus;
32 public class TestParametersL10 implements ParameterGroup {
34 private int l10IntField = 0;
35 private String l10StringField = "Legal " + this.getClass().getCanonicalName();
36 private TestParametersLGeneric l10LGenericNested0 = new TestParametersLGeneric("l10LGenericNested0");
37 private TestParametersLGeneric l10LGenericNested1 = new TestParametersLGeneric("l10LGenericNested1");
38 private Map<String, TestParametersLGeneric> l10LGenericNestedMap = new LinkedHashMap<>();
41 * Default constructor.
43 public TestParametersL10() {
44 // Default Constructor
48 * Create a test parameter group.
50 * @param name the parameter group name
52 public TestParametersL10(final String name) {
55 TestParametersLGeneric l10LGenericNestedMapVal0 = new TestParametersLGeneric("l10LGenericNestedMapVal0");
56 l10LGenericNestedMap.put(l10LGenericNestedMapVal0.getName(), l10LGenericNestedMapVal0);
57 TestParametersLGeneric l10LGenericNestedMapVal1 = new TestParametersLGeneric("l10LGenericNestedMapVal1");
58 l10LGenericNestedMap.put(l10LGenericNestedMapVal1.getName(), l10LGenericNestedMapVal1);
61 public int getL10IntField() {
65 public String getL10StringField() {
66 return l10StringField;
69 public TestParametersLGeneric getL10LGenericNested0() {
70 return l10LGenericNested0;
73 public TestParametersLGeneric getL10LGenericNested1() {
74 return l10LGenericNested1;
77 public Map<String, TestParametersLGeneric> getL10LGenericNestedMap() {
78 return l10LGenericNestedMap;
81 public void setName(String name) {
85 public void setL10IntField(int l10IntField) {
86 this.l10IntField = l10IntField;
89 public void setL10StringField(String l10StringField) {
90 this.l10StringField = l10StringField;
93 public void setL10LGenericNested0(TestParametersLGeneric l10lGenericNested0) {
94 l10LGenericNested0 = l10lGenericNested0;
97 public void setL10LGenericNested1(TestParametersLGeneric l10lGenericNested1) {
98 l10LGenericNested1 = l10lGenericNested1;
101 public void setL10LGenericNestedMap(Map<String, TestParametersLGeneric> l10lGenericNestedMap) {
102 l10LGenericNestedMap = l10lGenericNestedMap;
106 * Trigger a validation message.
108 * @param level Number of levels to recurse before stopping
110 public void triggerValidationStatus(final ValidationStatus triggerStatus, int level) {
118 switch (triggerStatus) {
120 l10StringField = "Legal " + this.getClass().getCanonicalName();
124 l10StringField = "aString";
128 l10StringField = "l10StringField";
139 l10LGenericNested0.triggerValidationStatus(triggerStatus, level);
140 l10LGenericNested1.triggerValidationStatus(triggerStatus, level);
142 for (TestParametersLGeneric nestedParameterGroup : l10LGenericNestedMap.values()) {
143 nestedParameterGroup.triggerValidationStatus(triggerStatus, level);
148 public String getName() {
153 public GroupValidationResult validate() {
154 GroupValidationResult validationResult = new GroupValidationResult(this);
156 if (l10StringField == null || l10StringField.trim().length() == 0) {
157 validationResult.setResult("l10StringField", ValidationStatus.INVALID,
158 "l10StringField must be a non-blank string");
159 } else if (l10StringField.equals("l10StringField")) {
160 validationResult.setResult("l10StringField", ValidationStatus.WARNING,
161 "using the field name for the parameter value is dangerous");
162 } else if (l10StringField.equals("aString")) {
163 validationResult.setResult("l10StringField", ValidationStatus.OBSERVATION,
164 "this value for name is unhelpful");
166 validationResult.setResult("l10StringField", ValidationStatus.CLEAN,
167 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
170 if (l10IntField < 0) {
171 validationResult.setResult("l10IntField", ValidationStatus.INVALID,
172 "l10IntField must be a positive integer");
173 } else if (l10IntField > 2) {
174 validationResult.setResult("l10IntField", ValidationStatus.WARNING,
175 "values greater than 2 are not recommended");
176 } else if (l10IntField == 2) {
177 validationResult.setResult("l10IntField", ValidationStatus.OBSERVATION, "this field has been set to 2");
179 validationResult.setResult("l10IntField", ValidationStatus.CLEAN,
180 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
183 if (l10LGenericNested0 != null) {
184 validationResult.setResult("l10LGenericNested0", l10LGenericNested0.validate());
186 validationResult.setResult("l10LGenericNested1", l10LGenericNested1.validate());
188 for (Entry<String, TestParametersLGeneric> nestedGroupEntry : l10LGenericNestedMap.entrySet()) {
189 validationResult.setResult("l10LGenericNestedMap", nestedGroupEntry.getKey(),
190 nestedGroupEntry.getValue().validate());
193 return validationResult;