summaryrefslogtreecommitdiffstats
path: root/common-parameters/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'common-parameters/src/test/java')
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java13
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationErrors.java26
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupMissingGetter.java56
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupPrivateGetter.java60
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java2
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL00.java40
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL10.java25
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersLGeneric.java8
8 files changed, 225 insertions, 5 deletions
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java
index fe750b2c..fb08d325 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java
@@ -31,6 +31,7 @@ import java.nio.file.Paths;
import org.junit.Test;
import org.onap.policy.common.parameters.testclasses.TestParametersL00;
+import org.onap.policy.common.parameters.testclasses.TestParametersL10;
public class TestValidation {
@Test
@@ -182,4 +183,16 @@ public class TestValidation {
assertTrue(validationResult.isValid());
assertEquals(null, validationResult.getResult());
}
+
+ @Test
+ public void testValidationEmptySubGroup() throws IOException {
+ TestParametersL10 l10Parameters = new TestParametersL10("l10Parameters");
+
+ l10Parameters.setL10LGenericNested0(null);
+
+ GroupValidationResult validationResult = l10Parameters.validate();
+ assertTrue(validationResult.isValid());
+
+ assertTrue(validationResult.getResult("", "", true).contains("UNDEFINED"));
+ }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationErrors.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationErrors.java
index a489cc3f..2c1e2f18 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationErrors.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationErrors.java
@@ -26,6 +26,8 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
+import org.onap.policy.common.parameters.testclasses.ParameterGroupMissingGetter;
+import org.onap.policy.common.parameters.testclasses.ParameterGroupPrivateGetter;
import org.onap.policy.common.parameters.testclasses.ParameterGroupWithArray;
import org.onap.policy.common.parameters.testclasses.ParameterGroupWithCollection;
import org.onap.policy.common.parameters.testclasses.ParameterGroupWithIllegalMapKey;
@@ -112,4 +114,28 @@ public class TestValidationErrors {
+ "map \"intMap\" is not a parameter group", e.getMessage());
}
}
+
+ @Test
+ public void testMissingGetter() {
+ ParameterGroupMissingGetter badGetterName = new ParameterGroupMissingGetter("BGN");
+ try {
+ badGetterName.isValid();
+ fail("test should throw an exception");
+ } catch (ParameterRuntimeException e) {
+ assertEquals("could not get getter method for parameter \"value\"", e.getMessage());
+ }
+
+ }
+
+ @Test
+ public void testPrivateGetter() {
+ ParameterGroupPrivateGetter privateGetter = new ParameterGroupPrivateGetter("privateGetter");
+ try {
+ privateGetter.isValid();
+ fail("test should throw an exception");
+ } catch (ParameterRuntimeException e) {
+ assertEquals("could not get getter method for parameter \"value\"", e.getMessage());
+ }
+
+ }
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupMissingGetter.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupMissingGetter.java
new file mode 100644
index 00000000..e05eea3f
--- /dev/null
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupMissingGetter.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.parameters.testclasses;
+
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterGroup;
+
+public class ParameterGroupMissingGetter implements ParameterGroup {
+ private String name;
+ private String value;
+
+ public ParameterGroupMissingGetter(final String name) {
+ this.name = name;
+ }
+
+ public String getTheValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ @Override
+ public GroupValidationResult validate() {
+ return new GroupValidationResult(this);
+ }
+}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupPrivateGetter.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupPrivateGetter.java
new file mode 100644
index 00000000..78a7c157
--- /dev/null
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupPrivateGetter.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.parameters.testclasses;
+
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterGroup;
+
+public class ParameterGroupPrivateGetter implements ParameterGroup {
+ private String name;
+ private String value;
+
+ public ParameterGroupPrivateGetter(final String name) {
+ this.name = name;
+ }
+
+ public String getTheValue() {
+ return getValue();
+ }
+
+ private String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ @Override
+ public GroupValidationResult validate() {
+ return new GroupValidationResult(this);
+ }
+}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java
index dadf7273..3966e49c 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java
@@ -42,7 +42,7 @@ public class ParameterGroupWithParameterGroupCollection implements ParameterGrou
parameterGroupArrayList.add(new TestParametersLGeneric("Generic2"));
}
- public List<ParameterGroup> getIntArrayList() {
+ public List<ParameterGroup> getParameterGroupArrayList() {
return parameterGroupArrayList;
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL00.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL00.java
index 6cd65603..b4a7e9c8 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL00.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL00.java
@@ -30,12 +30,16 @@ import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.parameters.ValidationStatus;
public class TestParametersL00 implements ParameterGroup {
- private String name;
+ private static final String A_CONSTANT = "A Constant";
+
+ private String name = A_CONSTANT;
private int l00IntField = 0;
private String l00StringField = "Legal " + this.getClass().getCanonicalName();
private TestParametersL10 l00L10Nested = new TestParametersL10("l00L10Nested");
private TestParametersLGeneric l00LGenericNested = new TestParametersLGeneric("l00LGenericNested");
private Map<String, TestParametersLGeneric> l00LGenericNestedMap = new LinkedHashMap<>();
+ private boolean isSomeFlag;
+ private boolean someNonIsFlag;
/**
* Default constructor.
@@ -43,7 +47,7 @@ public class TestParametersL00 implements ParameterGroup {
public TestParametersL00() {
// Default Cnstructor
}
-
+
/**
* Create a test parameter group.
*
@@ -58,6 +62,38 @@ public class TestParametersL00 implements ParameterGroup {
l00LGenericNestedMap.put(l00LGenericNestedMapVal1.getName(), l00LGenericNestedMapVal1);
}
+ public int getL00IntField() {
+ return l00IntField;
+ }
+
+ public String getL00StringField() {
+ return l00StringField;
+ }
+
+ public TestParametersL10 getL00L10Nested() {
+ return l00L10Nested;
+ }
+
+ public TestParametersLGeneric getL00LGenericNested() {
+ return l00LGenericNested;
+ }
+
+ public Map<String, TestParametersLGeneric> getL00LGenericNestedMap() {
+ return l00LGenericNestedMap;
+ }
+
+ public boolean isSomeFlag() {
+ return isSomeFlag;
+ }
+
+ public boolean isSomeNonIsFlag() {
+ return someNonIsFlag;
+ }
+
+ public void setSomeFlag(boolean isSomeFlag) {
+ this.isSomeFlag = isSomeFlag;
+ }
+
public void setName(String name) {
this.name = name;
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL10.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL10.java
index 6efddac0..f63ec3f9 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL10.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersL10.java
@@ -58,6 +58,26 @@ public class TestParametersL10 implements ParameterGroup {
l10LGenericNestedMap.put(l10LGenericNestedMapVal1.getName(), l10LGenericNestedMapVal1);
}
+ public int getL10IntField() {
+ return l10IntField;
+ }
+
+ public String getL10StringField() {
+ return l10StringField;
+ }
+
+ public TestParametersLGeneric getL10LGenericNested0() {
+ return l10LGenericNested0;
+ }
+
+ public TestParametersLGeneric getL10LGenericNested1() {
+ return l10LGenericNested1;
+ }
+
+ public Map<String, TestParametersLGeneric> getL10LGenericNestedMap() {
+ return l10LGenericNestedMap;
+ }
+
public void setName(String name) {
this.name = name;
}
@@ -160,8 +180,9 @@ public class TestParametersL10 implements ParameterGroup {
ParameterConstants.PARAMETER_HAS_STATUS_MESSAGE + ValidationStatus.CLEAN.toString());
}
-
- validationResult.setResult("l10LGenericNested0", l10LGenericNested0.validate());
+ if (l10LGenericNested0 != null) {
+ validationResult.setResult("l10LGenericNested0", l10LGenericNested0.validate());
+ }
validationResult.setResult("l10LGenericNested1", l10LGenericNested1.validate());
for (Entry<String, TestParametersLGeneric> nestedGroupEntry : l10LGenericNestedMap.entrySet()) {
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersLGeneric.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersLGeneric.java
index 2e678da0..2d263fc7 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersLGeneric.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/TestParametersLGeneric.java
@@ -46,6 +46,14 @@ public class TestParametersLGeneric implements ParameterGroup {
this.name = name;
}
+ public int getLgenericIntField() {
+ return lgenericIntField;
+ }
+
+ public String getLgenericStringField() {
+ return lgenericStringField;
+ }
+
public void setName(String name) {
this.name = name;
}