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/TestParameterService.java25
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java2
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationErrors.java10
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationResults.java38
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/EmptyParameterGroup.java5
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithArray.java9
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithCollection.java5
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapKey.java5
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapValue.java5
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullCollection.java9
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullMapValue.java9
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullSubGroup.java56
-rw-r--r--common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithParameterGroupCollection.java5
13 files changed, 170 insertions, 13 deletions
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestParameterService.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestParameterService.java
index 0b7e46ca..2dad4283 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestParameterService.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestParameterService.java
@@ -57,9 +57,34 @@ public class TestParameterService {
assertEquals("\"Empty Group\" already registered in parameter service", e.getMessage());
}
+ try {
+ ParameterService.register(new EmptyParameterGroup("Empty Group"), false);
+ fail("this test should throw an exception");
+ }
+ catch (ParameterRuntimeException e) {
+ assertEquals("\"Empty Group\" already registered in parameter service", e.getMessage());
+ }
+
+ ParameterService.register(new EmptyParameterGroup("Empty Group"), true);
+ assertTrue(ParameterService.contains("Empty Group"));
+
ParameterService.deregister("Empty Group");
assertFalse(ParameterService.contains("Empty Group"));
+ ParameterService.register(new EmptyParameterGroup("Empty Group"), true);
+ assertTrue(ParameterService.contains("Empty Group"));
+
+ ParameterService.deregister("Empty Group");
+ assertFalse(ParameterService.contains("Empty Group"));
+
+ EmptyParameterGroup epg = new EmptyParameterGroup("Empty Group");
+ ParameterService.register(epg);
+ assertTrue(ParameterService.contains("Empty Group"));
+ assertNotNull(ParameterService.get("Empty Group"));
+
+ ParameterService.deregister(epg);
+ assertFalse(ParameterService.contains("Empty Group"));
+
try {
ParameterService.deregister("Empty Group");
fail("this test should throw an exception");
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 2ca24a05..fe750b2c 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
@@ -39,6 +39,7 @@ public class TestValidation {
GroupValidationResult validationResult = l0Parameters.validate();
assertTrue(validationResult.isValid());
+ assertTrue(validationResult.isClean());
assertNull(validationResult.getResult());
assertEquals(l0Parameters, validationResult.getParameterGroup());
assertEquals(l0Parameters.getName(), validationResult.getName());
@@ -61,6 +62,7 @@ public class TestValidation {
GroupValidationResult validationResult = l0Parameters.validate();
assertTrue(validationResult.isValid());
+ assertFalse(validationResult.isClean());
assertEquals(expectedResult, validationResult.getResult().replaceAll("\\s+", ""));
l0Parameters.triggerValidationStatus(ValidationStatus.CLEAN, 3);
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 6b781472..a489cc3f 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
@@ -21,6 +21,7 @@
package org.onap.policy.common.parameters;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -31,6 +32,7 @@ import org.onap.policy.common.parameters.testclasses.ParameterGroupWithIllegalMa
import org.onap.policy.common.parameters.testclasses.ParameterGroupWithIllegalMapValue;
import org.onap.policy.common.parameters.testclasses.ParameterGroupWithNullCollection;
import org.onap.policy.common.parameters.testclasses.ParameterGroupWithNullMapValue;
+import org.onap.policy.common.parameters.testclasses.ParameterGroupWithNullSubGroup;
import org.onap.policy.common.parameters.testclasses.ParameterGroupWithParameterGroupCollection;
public class TestValidationErrors {
@@ -69,6 +71,14 @@ public class TestValidationErrors {
}
@Test
+ public void testMapNullSubGroupValidation() {
+ ParameterGroupWithNullSubGroup nullSub = new ParameterGroupWithNullSubGroup("Null sub group value");
+
+ nullSub.isValid();
+ assertNull(nullSub.getSubGroup());
+ }
+
+ @Test
public void testMapNullValueValidation() {
ParameterGroupWithNullMapValue nullMap = new ParameterGroupWithNullMapValue("Null Map value");
try {
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationResults.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationResults.java
index 8f22765b..f7451051 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationResults.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationResults.java
@@ -103,15 +103,11 @@ public class TestValidationResults {
result.setResult("nonExistantParameter", ValidationStatus.OBSERVATION, "Something was observed");
fail("test shold throw an exception here");
} catch (Exception e) {
- assertEquals("no regular parameter field exists for parameter: nonExistantParameter", e.getMessage());
+ assertEquals("no parameter field exists for parameter: nonExistantParameter", e.getMessage());
}
- try {
- result.setResult("l10LGenericNestedMap", ValidationStatus.OBSERVATION, "Something was observed");
- fail("test shold throw an exception here");
- } catch (Exception e) {
- assertEquals("parameter not a regular parameter: l10LGenericNestedMap", e.getMessage());
- }
+ result.setResult("l10IntField", ValidationStatus.OBSERVATION, "Something was observed");
+ assertTrue(result.isValid());
try {
result.setResult("nonExistantParameter", new GroupValidationResult(pg));
@@ -143,5 +139,33 @@ public class TestValidationResults {
} catch (Exception e) {
assertEquals("parameter is not a nested group map parameter: l10IntField", e.getMessage());
}
+
+ result.setResult("l10LGenericNestedMap", "l10LGenericNestedMapVal0", ValidationStatus.INVALID,
+ "This value is invalid");
+ assertEquals(ValidationStatus.INVALID, result.getStatus());
+
+ try {
+ result.setResult("l10IntField", "l10LGenericNestedMapVal0", ValidationStatus.INVALID,
+ "This value is invalid");
+ fail("test shold throw an exception here");
+ } catch (Exception e) {
+ assertEquals("parameter is not a nested group map parameter: l10IntField", e.getMessage());
+ }
+
+ try {
+ result.setResult("nonExistantParameter", "l10LGenericNestedMapVal0", ValidationStatus.INVALID,
+ "This value is invalid");
+ fail("test shold throw an exception here");
+ } catch (Exception e) {
+ assertEquals("no group map parameter field exists for parameter: nonExistantParameter", e.getMessage());
+ }
+
+ try {
+ result.setResult("l10LGenericNestedMap", "NonExistantKey", ValidationStatus.INVALID,
+ "This value is invalid");
+ fail("test shold throw an exception here");
+ } catch (Exception e) {
+ assertEquals("no entry with name \"NonExistantKey\" exists", e.getMessage());
+ }
}
}
diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/EmptyParameterGroup.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/EmptyParameterGroup.java
index 681eb693..505b2ce4 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/EmptyParameterGroup.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/EmptyParameterGroup.java
@@ -36,6 +36,11 @@ public class EmptyParameterGroup implements ParameterGroup {
}
@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/ParameterGroupWithArray.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithArray.java
index fcb2bb1b..c448cea1 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithArray.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithArray.java
@@ -34,12 +34,17 @@ public class ParameterGroupWithArray implements ParameterGroup {
public int[] getIntArray() {
return intArray;
}
-
+
@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/ParameterGroupWithCollection.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithCollection.java
index 75ae45b8..7f2c0ab5 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithCollection.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithCollection.java
@@ -53,6 +53,11 @@ public class ParameterGroupWithCollection implements ParameterGroup {
}
@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/ParameterGroupWithIllegalMapKey.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapKey.java
index ca441060..57a5a110 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapKey.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapKey.java
@@ -52,6 +52,11 @@ public class ParameterGroupWithIllegalMapKey implements ParameterGroup {
}
@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/ParameterGroupWithIllegalMapValue.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapValue.java
index 9253f158..39e35d9c 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapValue.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithIllegalMapValue.java
@@ -52,6 +52,11 @@ public class ParameterGroupWithIllegalMapValue implements ParameterGroup {
}
@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/ParameterGroupWithNullCollection.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullCollection.java
index 0d113dc6..9b661bd5 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullCollection.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullCollection.java
@@ -40,12 +40,17 @@ public class ParameterGroupWithNullCollection implements ParameterGroup {
public List<Integer> getNullList() {
return nullList;
}
-
+
@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/ParameterGroupWithNullMapValue.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullMapValue.java
index 9e1601c3..ac863a42 100644
--- a/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullMapValue.java
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullMapValue.java
@@ -40,12 +40,17 @@ public class ParameterGroupWithNullMapValue implements ParameterGroup {
public Map<String, Integer> getNullMap() {
return nullMap;
}
-
+
@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/ParameterGroupWithNullSubGroup.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullSubGroup.java
new file mode 100644
index 00000000..830c8117
--- /dev/null
+++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/testclasses/ParameterGroupWithNullSubGroup.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 ParameterGroupWithNullSubGroup implements ParameterGroup {
+ private String name;
+ private ParameterGroup subGroup = null;
+
+ /**
+ * Create a test parameter group.
+ * @param name the parameter group name
+ */
+ public ParameterGroupWithNullSubGroup(final String name) {
+ this.name = name;
+ }
+
+ public ParameterGroup getSubGroup() {
+ return subGroup;
+ }
+
+ @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 5ece07b4..dadf7273 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
@@ -52,6 +52,11 @@ public class ParameterGroupWithParameterGroupCollection implements ParameterGrou
}
@Override
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ @Override
public GroupValidationResult validate() {
return new GroupValidationResult(this);
}