aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/clamp/clds
diff options
context:
space:
mode:
authorxuegao <xg353y@intl.att.com>2020-05-04 15:33:06 +0200
committerxuegao <xg353y@intl.att.com>2020-05-05 10:05:53 +0200
commit28aa29f66de909223bd67da717fdd810df735afc (patch)
tree199508e6480cffc56b7d61b91f44a4c4f238b108 /src/test/java/org/onap/clamp/clds
parent0c29796f7489015913a5793f13b2586099493464 (diff)
Add unit test
Add unit tests to improve code coverage. Issue-ID: CLAMP-844 Change-Id: I7792212d476103086e063cf8fe4a9abed1294fd6 Signed-off-by: xuegao <xg353y@intl.att.com>
Diffstat (limited to 'src/test/java/org/onap/clamp/clds')
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateFieldTest.java69
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateTest.java30
2 files changed, 93 insertions, 6 deletions
diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateFieldTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateFieldTest.java
new file mode 100644
index 00000000..29f5a1da
--- /dev/null
+++ b/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateFieldTest.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.tosca.update;
+
+import junit.framework.TestCase;
+import org.onap.clamp.clds.tosca.update.templates.JsonTemplateField;
+
+public class JsonTemplateFieldTest extends TestCase {
+
+ JsonTemplateField field1 = new JsonTemplateField("type", "testType", true, true);
+ JsonTemplateField field2 = new JsonTemplateField("type");
+ JsonTemplateField field3 = new JsonTemplateField("type", "testType1", true, true);
+ JsonTemplateField field4 = new JsonTemplateField("type", "testType", false, true);
+ JsonTemplateField field5 = new JsonTemplateField("type", "testType", true, false);
+ JsonTemplateField field6 = new JsonTemplateField("type", "testType", true, true);
+
+ /**
+ * Test fieldsEqual method.
+ */
+ public void testFieldsEqualsMethod() {
+ assertFalse(JsonTemplateField.fieldsEquals(field1,field3));
+ assertFalse(JsonTemplateField.fieldsEquals(field1,field4));
+ assertFalse(JsonTemplateField.fieldsEquals(field1,field5));
+ assertTrue(JsonTemplateField.fieldsEquals(field1,field6));
+ }
+
+ /**
+ * Test equals method.
+ */
+ public void testEqualsMethod() {
+ assertTrue(field1.equals(field2));
+ assertTrue(field1.equals(field3));
+ assertTrue(field1.equals(field4));
+ assertTrue(field1.equals(field5));
+ assertTrue(field1.equals(field6));
+ }
+
+ /**
+ * Test compareWithField method.
+ */
+ public void testCompareWithFieldMethod() {
+ assertFalse(field1.compareWithField(field2));
+ assertFalse(field1.compareWithField(field3));
+ assertFalse(field1.compareWithField(field4));
+ assertFalse(field1.compareWithField(field5));
+ assertTrue(field1.equals(field6));
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateTest.java
index fab3030c..dc736a48 100644
--- a/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateTest.java
+++ b/src/test/java/org/onap/clamp/clds/tosca/update/JsonTemplateTest.java
@@ -32,20 +32,38 @@ import org.onap.clamp.clds.tosca.update.templates.JsonTemplateField;
public class JsonTemplateTest extends TestCase {
+ JsonTemplate toTest = new JsonTemplate("toTest");
+ List<JsonTemplateField>
+ jsonTemplateFields = new ArrayList<>(
+ Arrays.asList(new JsonTemplateField("type"), new JsonTemplateField("description"),
+ new JsonTemplateField(
+ "enum")));
+
/**
* Test check failed.
*/
public void testCheckFields() {
- JsonTemplate toTest = new JsonTemplate("toTest");
- List<JsonTemplateField>
- jsonTemplateFields = new ArrayList<>(
- Arrays.asList(new JsonTemplateField("type"), new JsonTemplateField("description"),
- new JsonTemplateField(
- "enum")));
toTest.setJsonTemplateFields(jsonTemplateFields);
JsonTemplate reference = new JsonTemplate("toTest");
reference.setJsonTemplateFields(jsonTemplateFields);
assertTrue(toTest.checkFields(reference));
}
+ /**
+ * Test other methods.
+ */
+ public void testOtherFields() {
+ toTest.setJsonTemplateFields(jsonTemplateFields);
+ toTest.addField(new JsonTemplateField("moreField"));
+ toTest.setVisibility("moreField", true);
+ toTest.setStatic("moreField", true);
+ toTest.updateValueField("moreField", "testValue");
+
+ assertTrue(toTest.isVisible("moreField"));
+ assertTrue(toTest.getSpecificField("moreField").getValue().equals("testValue"));
+ assertTrue(toTest.fieldStaticStatus("moreField"));
+ assertTrue(toTest.toString()
+ .equals(" templateFields : [type null null null, description null null null, "
+ + "enum null null null, moreField testValue true true]"));
+ }
} \ No newline at end of file