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 void setName(String name) {
65 public void setL10IntField(int l10IntField) {
66 this.l10IntField = l10IntField;
69 public void setL10StringField(String l10StringField) {
70 this.l10StringField = l10StringField;
73 public void setL10LGenericNested0(TestParametersLGeneric l10lGenericNested0) {
74 l10LGenericNested0 = l10lGenericNested0;
77 public void setL10LGenericNested1(TestParametersLGeneric l10lGenericNested1) {
78 l10LGenericNested1 = l10lGenericNested1;
81 public void setL10LGenericNestedMap(Map<String, TestParametersLGeneric> l10lGenericNestedMap) {
82 l10LGenericNestedMap = l10lGenericNestedMap;
86 * Trigger a validation message.
88 * @param level Number of levels to recurse before stopping
90 public void triggerValidationStatus(final ValidationStatus triggerStatus, int level) {
98 switch (triggerStatus) {
100 l10StringField = "Legal " + this.getClass().getCanonicalName();
104 l10StringField = "aString";
108 l10StringField = "l10StringField";
119 l10LGenericNested0.triggerValidationStatus(triggerStatus, level);
120 l10LGenericNested1.triggerValidationStatus(triggerStatus, level);
122 for (TestParametersLGeneric nestedParameterGroup : l10LGenericNestedMap.values()) {
123 nestedParameterGroup.triggerValidationStatus(triggerStatus, level);
128 public String getName() {
133 public GroupValidationResult validate() {
134 GroupValidationResult validationResult = new GroupValidationResult(this);
136 if (l10StringField == null || l10StringField.trim().length() == 0) {
137 validationResult.setResult("l10StringField", ValidationStatus.INVALID,
138 "l10StringField must be a non-blank string");
139 } else if (l10StringField.equals("l10StringField")) {
140 validationResult.setResult("l10StringField", ValidationStatus.WARNING,
141 "using the field name for the parameter value is dangerous");
142 } else if (l10StringField.equals("aString")) {
143 validationResult.setResult("l10StringField", ValidationStatus.OBSERVATION,
144 "this value for name is unhelpful");
146 validationResult.setResult("l10StringField", ValidationStatus.CLEAN,
147 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
150 if (l10IntField < 0) {
151 validationResult.setResult("l10IntField", ValidationStatus.INVALID,
152 "l10IntField must be a positive integer");
153 } else if (l10IntField > 2) {
154 validationResult.setResult("l10IntField", ValidationStatus.WARNING,
155 "values greater than 2 are not recommended");
156 } else if (l10IntField == 2) {
157 validationResult.setResult("l10IntField", ValidationStatus.OBSERVATION, "this field has been set to 2");
159 validationResult.setResult("l10IntField", ValidationStatus.CLEAN,
160 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
164 validationResult.setResult("l10LGenericNested0", l10LGenericNested0.validate());
165 validationResult.setResult("l10LGenericNested1", l10LGenericNested1.validate());
167 for (Entry<String, TestParametersLGeneric> nestedGroupEntry : l10LGenericNestedMap.entrySet()) {
168 validationResult.setResult("l10LGenericNestedMap", nestedGroupEntry.getKey(),
169 nestedGroupEntry.getValue().validate());
172 return validationResult;