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 TestParametersL00 implements ParameterGroup {
33 private static final String A_CONSTANT = "A Constant";
35 private String name = A_CONSTANT;
36 private int l00IntField = 0;
37 private String l00StringField = "Legal " + this.getClass().getCanonicalName();
38 private TestParametersL10 l00L10Nested = new TestParametersL10("l00L10Nested");
39 private TestParametersLGeneric l00LGenericNested = new TestParametersLGeneric("l00LGenericNested");
40 private Map<String, TestParametersLGeneric> l00LGenericNestedMap = new LinkedHashMap<>();
41 private boolean isSomeFlag;
42 private boolean someNonIsFlag;
45 * Default constructor.
47 public TestParametersL00() {
52 * Create a test parameter group.
54 * @param name the parameter group name
56 public TestParametersL00(final String name) {
59 TestParametersLGeneric l00LGenericNestedMapVal0 = new TestParametersLGeneric("l00LGenericNestedMapVal0");
60 l00LGenericNestedMap.put(l00LGenericNestedMapVal0.getName(), l00LGenericNestedMapVal0);
61 TestParametersLGeneric l00LGenericNestedMapVal1 = new TestParametersLGeneric("l00LGenericNestedMapVal1");
62 l00LGenericNestedMap.put(l00LGenericNestedMapVal1.getName(), l00LGenericNestedMapVal1);
65 public int getL00IntField() {
69 public String getL00StringField() {
70 return l00StringField;
73 public TestParametersL10 getL00L10Nested() {
77 public TestParametersLGeneric getL00LGenericNested() {
78 return l00LGenericNested;
81 public Map<String, TestParametersLGeneric> getL00LGenericNestedMap() {
82 return l00LGenericNestedMap;
85 public boolean isSomeFlag() {
89 public boolean isSomeNonIsFlag() {
93 public void setSomeFlag(boolean isSomeFlag) {
94 this.isSomeFlag = isSomeFlag;
97 public void setName(String name) {
101 public void setL00IntField(int l00IntField) {
102 this.l00IntField = l00IntField;
105 public void setL00StringField(String l00StringField) {
106 this.l00StringField = l00StringField;
109 public void setL00L10Nested(TestParametersL10 l00l10Nested) {
110 l00L10Nested = l00l10Nested;
113 public void setL00LGenericNested(TestParametersLGeneric l00lGenericNested) {
114 l00LGenericNested = l00lGenericNested;
117 public void setL00LGenericNestedMap(Map<String, TestParametersLGeneric> l00lGenericNestedMap) {
118 l00LGenericNestedMap = l00lGenericNestedMap;
122 * Trigger a validation message.
124 * @param triggerStatus Validation status to trigger
125 * @param level Number of levels to recurse before stopping
127 public void triggerValidationStatus(final ValidationStatus triggerStatus, int level) {
134 switch (triggerStatus) {
136 l00StringField = "Legal " + this.getClass().getCanonicalName();
140 l00StringField = "aString";
144 l00StringField = "l00StringField";
155 l00L10Nested.triggerValidationStatus(triggerStatus, level);
156 l00LGenericNested.triggerValidationStatus(triggerStatus, level);
158 for (TestParametersLGeneric nestedParameterGroup : l00LGenericNestedMap.values()) {
159 nestedParameterGroup.triggerValidationStatus(triggerStatus, level);
165 public String getName() {
170 public GroupValidationResult validate() {
171 GroupValidationResult validationResult = new GroupValidationResult(this);
173 if (name == null || name.trim().length() == 0) {
174 validationResult.setResult("name", ValidationStatus.INVALID, "name must be a non-blank string");
177 if (l00StringField == null || l00StringField.trim().length() == 0) {
178 validationResult.setResult("l00StringField", ValidationStatus.INVALID,
179 "l00StringField must be a non-blank string");
180 } else if (l00StringField.equals("l00StringField")) {
181 validationResult.setResult("l00StringField", ValidationStatus.WARNING,
182 "using the field name for the parameter value is dangerous");
183 } else if (l00StringField.equals("aString")) {
184 validationResult.setResult("l00StringField", ValidationStatus.OBSERVATION,
185 "this value for name is unhelpful");
187 validationResult.setResult("l00StringField", ValidationStatus.CLEAN,
188 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
191 if (l00IntField < 0) {
192 validationResult.setResult("l00IntField", ValidationStatus.INVALID,
193 "l00IntField must be a positive integer");
194 } else if (l00IntField > 2) {
195 validationResult.setResult("l00IntField", ValidationStatus.WARNING,
196 "values greater than 2 are not recommended");
197 } else if (l00IntField == 2) {
198 validationResult.setResult("l00IntField", ValidationStatus.OBSERVATION, "this field has been set to 2");
200 validationResult.setResult("l00IntField", ValidationStatus.CLEAN,
201 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
204 validationResult.setResult("l00L10Nested", l00L10Nested.validate());
205 validationResult.setResult("l00LGenericNested", l00LGenericNested.validate());
207 for (Entry<String, TestParametersLGeneric> nestedGroupEntry : l00LGenericNestedMap.entrySet()) {
208 validationResult.setResult("l00LGenericNestedMap", nestedGroupEntry.getKey(),
209 nestedGroupEntry.getValue().validate());
212 return validationResult;