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 L00_INT_FIELD = "l00IntField";
34 private static final String L00_STRING_FIELD = "l00StringField";
36 private static final String A_CONSTANT = "A Constant";
38 private int l00IntField = 0;
39 private String l00StringField = "Legal " + this.getClass().getCanonicalName();
40 private TestParametersL10 l00L10Nested = new TestParametersL10("l00L10Nested");
41 private TestParametersLGeneric l00LGenericNested = new TestParametersLGeneric("l00LGenericNested");
42 private Map<String, TestParametersLGeneric> l00LGenericNestedMap = new LinkedHashMap<>();
43 private boolean isSomeFlag;
44 private boolean someNonIsFlag;
47 * Default constructor.
49 public TestParametersL00() {
54 * Create a test parameter group.
56 * @param name the parameter group name
58 public TestParametersL00(final String name) {
61 TestParametersLGeneric l00LGenericNestedMapVal0 = new TestParametersLGeneric("l00LGenericNestedMapVal0");
62 l00LGenericNestedMap.put(l00LGenericNestedMapVal0.getName(), l00LGenericNestedMapVal0);
63 TestParametersLGeneric l00LGenericNestedMapVal1 = new TestParametersLGeneric("l00LGenericNestedMapVal1");
64 l00LGenericNestedMap.put(l00LGenericNestedMapVal1.getName(), l00LGenericNestedMapVal1);
67 public int getL00IntField() {
71 public String getL00StringField() {
72 return l00StringField;
75 public TestParametersL10 getL00L10Nested() {
79 public TestParametersLGeneric getL00LGenericNested() {
80 return l00LGenericNested;
83 public Map<String, TestParametersLGeneric> getL00LGenericNestedMap() {
84 return l00LGenericNestedMap;
87 public boolean isSomeFlag() {
91 public boolean isSomeNonIsFlag() {
95 public void setSomeFlag(boolean isSomeFlag) {
96 this.isSomeFlag = isSomeFlag;
99 public void setL00IntField(int l00IntField) {
100 this.l00IntField = l00IntField;
103 public void setL00StringField(String l00StringField) {
104 this.l00StringField = l00StringField;
107 public void setL00L10Nested(TestParametersL10 l00l10Nested) {
108 l00L10Nested = l00l10Nested;
111 public void setL00LGenericNested(TestParametersLGeneric l00lGenericNested) {
112 l00LGenericNested = l00lGenericNested;
115 public void setL00LGenericNestedMap(Map<String, TestParametersLGeneric> l00lGenericNestedMap) {
116 l00LGenericNestedMap = l00lGenericNestedMap;
120 * Trigger a validation message.
122 * @param triggerStatus Validation status to trigger
123 * @param level Number of levels to recurse before stopping
125 public void triggerValidationStatus(final ValidationStatus triggerStatus, int level) {
132 switch (triggerStatus) {
134 l00StringField = "Legal " + this.getClass().getCanonicalName();
138 l00StringField = "aString";
142 l00StringField = L00_STRING_FIELD;
153 l00L10Nested.triggerValidationStatus(triggerStatus, level);
154 l00LGenericNested.triggerValidationStatus(triggerStatus, level);
156 for (TestParametersLGeneric nestedParameterGroup : l00LGenericNestedMap.values()) {
157 nestedParameterGroup.triggerValidationStatus(triggerStatus, level);
163 public GroupValidationResult validate() {
164 GroupValidationResult validationResult = super.validate();
166 if (getName() == null || getName().trim().length() == 0) {
167 validationResult.setResult("name", ValidationStatus.INVALID, "name must be a non-blank string");
170 if (l00StringField == null || l00StringField.trim().length() == 0) {
171 validationResult.setResult(L00_STRING_FIELD, ValidationStatus.INVALID,
172 "l00StringField must be a non-blank string");
173 } else if (l00StringField.equals(L00_STRING_FIELD)) {
174 validationResult.setResult(L00_STRING_FIELD, ValidationStatus.WARNING,
175 "using the field name for the parameter value is dangerous");
176 } else if (l00StringField.equals("aString")) {
177 validationResult.setResult(L00_STRING_FIELD, ValidationStatus.OBSERVATION,
178 "this value for name is unhelpful");
180 validationResult.setResult(L00_STRING_FIELD, ValidationStatus.CLEAN,
181 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
184 if (l00IntField < 0) {
185 validationResult.setResult(L00_INT_FIELD, ValidationStatus.INVALID,
186 "l00IntField must be a positive integer");
187 } else if (l00IntField > 2) {
188 validationResult.setResult(L00_INT_FIELD, ValidationStatus.WARNING,
189 "values greater than 2 are not recommended");
190 } else if (l00IntField == 2) {
191 validationResult.setResult(L00_INT_FIELD, ValidationStatus.OBSERVATION, "this field has been set to 2");
193 validationResult.setResult(L00_INT_FIELD, ValidationStatus.CLEAN,
194 ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
197 validationResult.setResult("l00L10Nested", l00L10Nested.validate());
198 validationResult.setResult("l00LGenericNested", l00LGenericNested.validate());
200 for (Entry<String, TestParametersLGeneric> nestedGroupEntry : l00LGenericNestedMap.entrySet()) {
201 validationResult.setResult("l00LGenericNestedMap", nestedGroupEntry.getKey(),
202 nestedGroupEntry.getValue().validate());
205 return validationResult;