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 TestParametersL00 extends ParameterGroupImpl {
33 private static final String A_CONSTANT = "A Constant";
35 private int l00IntField = 0;
36 private String l00StringField = "Legal " + this.getClass().getCanonicalName();
37 private TestParametersL10 l00L10Nested = new TestParametersL10("l00L10Nested");
38 private TestParametersLGeneric l00LGenericNested = new TestParametersLGeneric("l00LGenericNested");
39 private Map<String, TestParametersLGeneric> l00LGenericNestedMap = new LinkedHashMap<>();
40 private boolean isSomeFlag;
41 private boolean someNonIsFlag;
44 * Default constructor.
46 public TestParametersL00() {
51 * Create a test parameter group.
53 * @param name the parameter group name
55 public TestParametersL00(final String name) {
58 TestParametersLGeneric l00LGenericNestedMapVal0 = new TestParametersLGeneric("l00LGenericNestedMapVal0");
59 l00LGenericNestedMap.put(l00LGenericNestedMapVal0.getName(), l00LGenericNestedMapVal0);
60 TestParametersLGeneric l00LGenericNestedMapVal1 = new TestParametersLGeneric("l00LGenericNestedMapVal1");
61 l00LGenericNestedMap.put(l00LGenericNestedMapVal1.getName(), l00LGenericNestedMapVal1);
64 public int getL00IntField() {
68 public String getL00StringField() {
69 return l00StringField;
72 public TestParametersL10 getL00L10Nested() {
76 public TestParametersLGeneric getL00LGenericNested() {
77 return l00LGenericNested;
80 public Map<String, TestParametersLGeneric> getL00LGenericNestedMap() {
81 return l00LGenericNestedMap;
84 public boolean isSomeFlag() {
88 public boolean isSomeNonIsFlag() {
92 public void setSomeFlag(boolean isSomeFlag) {
93 this.isSomeFlag = isSomeFlag;
96 public void setL00IntField(int l00IntField) {
97 this.l00IntField = l00IntField;
100 public void setL00StringField(String l00StringField) {
101 this.l00StringField = l00StringField;
104 public void setL00L10Nested(TestParametersL10 l00l10Nested) {
105 l00L10Nested = l00l10Nested;
108 public void setL00LGenericNested(TestParametersLGeneric l00lGenericNested) {
109 l00LGenericNested = l00lGenericNested;
112 public void setL00LGenericNestedMap(Map<String, TestParametersLGeneric> l00lGenericNestedMap) {
113 l00LGenericNestedMap = l00lGenericNestedMap;
117 * Trigger a validation message.
119 * @param triggerStatus Validation status to trigger
120 * @param level Number of levels to recurse before stopping
122 public void triggerValidationStatus(final ValidationStatus triggerStatus, int level) {
129 switch (triggerStatus) {
131 l00StringField = "Legal " + this.getClass().getCanonicalName();
135 l00StringField = "aString";
139 l00StringField = "l00StringField";
150 l00L10Nested.triggerValidationStatus(triggerStatus, level);
151 l00LGenericNested.triggerValidationStatus(triggerStatus, level);
153 for (TestParametersLGeneric nestedParameterGroup : l00LGenericNestedMap.values()) {
154 nestedParameterGroup.triggerValidationStatus(triggerStatus, level);
160 public GroupValidationResult validate() {
161 GroupValidationResult validationResult = super.validate();
163 if (getName() == null || getName().trim().length() == 0) {
164 validationResult.setResult("name", ValidationStatus.INVALID, "name must be a non-blank string");
167 if (l00StringField == null || l00StringField.trim().length() == 0) {
168 validationResult.setResult("l00StringField", ValidationStatus.INVALID,
169 "l00StringField must be a non-blank string");
170 } else if (l00StringField.equals("l00StringField")) {
171 validationResult.setResult("l00StringField", ValidationStatus.WARNING,
172 "using the field name for the parameter value is dangerous");
173 } else if (l00StringField.equals("aString")) {
174 validationResult.setResult("l00StringField", ValidationStatus.OBSERVATION,
175 "this value for name is unhelpful");
177 validationResult.setResult("l00StringField", ValidationStatus.CLEAN,
178 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
181 if (l00IntField < 0) {
182 validationResult.setResult("l00IntField", ValidationStatus.INVALID,
183 "l00IntField must be a positive integer");
184 } else if (l00IntField > 2) {
185 validationResult.setResult("l00IntField", ValidationStatus.WARNING,
186 "values greater than 2 are not recommended");
187 } else if (l00IntField == 2) {
188 validationResult.setResult("l00IntField", ValidationStatus.OBSERVATION, "this field has been set to 2");
190 validationResult.setResult("l00IntField", ValidationStatus.CLEAN,
191 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
194 validationResult.setResult("l00L10Nested", l00L10Nested.validate());
195 validationResult.setResult("l00LGenericNested", l00LGenericNested.validate());
197 for (Entry<String, TestParametersLGeneric> nestedGroupEntry : l00LGenericNestedMap.entrySet()) {
198 validationResult.setResult("l00LGenericNestedMap", nestedGroupEntry.getKey(),
199 nestedGroupEntry.getValue().validate());
202 return validationResult;