2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property.
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 java.util.LinkedHashMap;
26 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.ParameterGroupImpl;
30 import org.onap.policy.common.parameters.ValidationStatus;
32 public class TestParametersL10 extends ParameterGroupImpl {
33 private int l10IntField = 0;
34 private String l10StringField = "Legal " + this.getClass().getCanonicalName();
35 private TestParametersLGeneric l10LGenericNested0 = new TestParametersLGeneric("l10LGenericNested0");
36 private TestParametersLGeneric l10LGenericNested1 = new TestParametersLGeneric("l10LGenericNested1");
37 private Map<String, TestParametersLGeneric> l10LGenericNestedMap = new LinkedHashMap<>();
40 * Default constructor.
42 public TestParametersL10() {
43 // Default Constructor
47 * Create a test parameter group.
49 * @param name the parameter group name
51 public TestParametersL10(final String name) {
54 TestParametersLGeneric l10LGenericNestedMapVal0 = new TestParametersLGeneric("l10LGenericNestedMapVal0");
55 l10LGenericNestedMap.put(l10LGenericNestedMapVal0.getName(), l10LGenericNestedMapVal0);
56 TestParametersLGeneric l10LGenericNestedMapVal1 = new TestParametersLGeneric("l10LGenericNestedMapVal1");
57 l10LGenericNestedMap.put(l10LGenericNestedMapVal1.getName(), l10LGenericNestedMapVal1);
60 public int getL10IntField() {
64 public String getL10StringField() {
65 return l10StringField;
68 public TestParametersLGeneric getL10LGenericNested0() {
69 return l10LGenericNested0;
72 public TestParametersLGeneric getL10LGenericNested1() {
73 return l10LGenericNested1;
76 public Map<String, TestParametersLGeneric> getL10LGenericNestedMap() {
77 return l10LGenericNestedMap;
80 public void setL10IntField(int l10IntField) {
81 this.l10IntField = l10IntField;
84 public void setL10StringField(String l10StringField) {
85 this.l10StringField = l10StringField;
88 public void setL10LGenericNested0(TestParametersLGeneric l10lGenericNested0) {
89 l10LGenericNested0 = l10lGenericNested0;
92 public void setL10LGenericNested1(TestParametersLGeneric l10lGenericNested1) {
93 l10LGenericNested1 = l10lGenericNested1;
96 public void setL10LGenericNestedMap(Map<String, TestParametersLGeneric> l10lGenericNestedMap) {
97 l10LGenericNestedMap = l10lGenericNestedMap;
101 * Trigger a validation message.
103 * @param level Number of levels to recurse before stopping
105 public void triggerValidationStatus(final ValidationStatus triggerStatus, int level) {
113 switch (triggerStatus) {
115 l10StringField = "Legal " + this.getClass().getCanonicalName();
119 l10StringField = "aString";
123 l10StringField = "l10StringField";
134 l10LGenericNested0.triggerValidationStatus(triggerStatus, level);
135 l10LGenericNested1.triggerValidationStatus(triggerStatus, level);
137 for (TestParametersLGeneric nestedParameterGroup : l10LGenericNestedMap.values()) {
138 nestedParameterGroup.triggerValidationStatus(triggerStatus, level);
143 public GroupValidationResult validate() {
144 GroupValidationResult validationResult = super.validate();
146 if (l10StringField == null || l10StringField.trim().length() == 0) {
147 validationResult.setResult("l10StringField", ValidationStatus.INVALID,
148 "l10StringField must be a non-blank string");
149 } else if (l10StringField.equals("l10StringField")) {
150 validationResult.setResult("l10StringField", ValidationStatus.WARNING,
151 "using the field name for the parameter value is dangerous");
152 } else if (l10StringField.equals("aString")) {
153 validationResult.setResult("l10StringField", ValidationStatus.OBSERVATION,
154 "this value for name is unhelpful");
156 validationResult.setResult("l10StringField", ValidationStatus.CLEAN,
157 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
160 if (l10IntField < 0) {
161 validationResult.setResult("l10IntField", ValidationStatus.INVALID,
162 "l10IntField must be a positive integer");
163 } else if (l10IntField > 2) {
164 validationResult.setResult("l10IntField", ValidationStatus.WARNING,
165 "values greater than 2 are not recommended");
166 } else if (l10IntField == 2) {
167 validationResult.setResult("l10IntField", ValidationStatus.OBSERVATION, "this field has been set to 2");
169 validationResult.setResult("l10IntField", ValidationStatus.CLEAN,
170 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
173 if (l10LGenericNested0 != null) {
174 validationResult.setResult("l10LGenericNested0", l10LGenericNested0.validate());
176 validationResult.setResult("l10LGenericNested1", l10LGenericNested1.validate());
178 for (Entry<String, TestParametersLGeneric> nestedGroupEntry : l10LGenericNestedMap.entrySet()) {
179 validationResult.setResult("l10LGenericNestedMap", nestedGroupEntry.getKey(),
180 nestedGroupEntry.getValue().validate());
183 return validationResult;