summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-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
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopTemplateLoopElementModelTest.java106
-rw-r--r--src/test/java/org/onap/clamp/policy/pdpgroup/PolicyModelKeyTest.java55
4 files changed, 254 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 000000000..29f5a1da8
--- /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 fab3030ca..dc736a48b 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
diff --git a/src/test/java/org/onap/clamp/loop/LoopTemplateLoopElementModelTest.java b/src/test/java/org/onap/clamp/loop/LoopTemplateLoopElementModelTest.java
new file mode 100644
index 000000000..e5b64c99c
--- /dev/null
+++ b/src/test/java/org/onap/clamp/loop/LoopTemplateLoopElementModelTest.java
@@ -0,0 +1,106 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * 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.loop;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+import org.onap.clamp.loop.template.LoopElementModel;
+import org.onap.clamp.loop.template.LoopTemplate;
+import org.onap.clamp.loop.template.LoopTemplateLoopElementModel;
+import org.onap.clamp.loop.template.PolicyModel;
+
+
+public class LoopTemplateLoopElementModelTest {
+
+ private LoopElementModel loopElementModel = getLoopElementModel("yaml", "microService1",
+ getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1"));
+ private LoopTemplate loopTemplate = getLoopTemplate("templateName", "yaml", "svg", 1);
+
+ private LoopElementModel getLoopElementModel(String yaml, String name, PolicyModel policyModel) {
+ LoopElementModel model = new LoopElementModel();
+ model.setBlueprint(yaml);
+ model.setName(name);
+ model.addPolicyModel(policyModel);
+ model.setLoopElementType("OPERATIONAL_POLICY");
+ return model;
+ }
+
+ private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym,
+ String policyVariant) {
+ return new PolicyModel(policyType, policyModelTosca, version, policyAcronym);
+ }
+
+ private LoopTemplate getLoopTemplate(String name, String blueprint, String svgRepresentation,
+ Integer maxInstancesAllowed) {
+ LoopTemplate template = new LoopTemplate(name, blueprint, svgRepresentation, maxInstancesAllowed, null);
+ template.addLoopElementModel(loopElementModel);
+ return template;
+ }
+
+ /**
+ * This tests compareTo method.
+ */
+ @Test
+ public void compareToTest() {
+ LoopTemplateLoopElementModel model1 = new LoopTemplateLoopElementModel();
+ LoopTemplateLoopElementModel model2 = new LoopTemplateLoopElementModel();
+ assertThat(model1.compareTo(model2)).isEqualTo(1);
+
+ model1.setFlowOrder(2);
+ assertThat(model1.compareTo(model2)).isEqualTo(-1);
+
+ model2.setFlowOrder(3);
+ assertThat(model1.compareTo(model2)).isEqualTo(1);
+ }
+
+ /**
+ * This tests equals method.
+ */
+ @Test
+ public void equalsTest() {
+ LoopTemplateLoopElementModel model1 = new LoopTemplateLoopElementModel();
+ LoopTemplateLoopElementModel model2 = new LoopTemplateLoopElementModel();
+
+ assertThat(model1.equals(model2)).isTrue();
+
+ model1.setLoopTemplate(loopTemplate);
+ assertThat(model1.equals(model2)).isFalse();
+ model2.setLoopTemplate(loopTemplate);
+ assertThat(model1.equals(model2)).isTrue();
+
+ model1.setLoopElementModel(loopElementModel);
+ assertThat(model1.equals(model2)).isFalse();
+ model2.setLoopElementModel(loopElementModel);
+ assertThat(model1.equals(model2)).isTrue();
+
+ model1.setFlowOrder(1);
+ assertThat(model1.equals(model2)).isTrue();
+ model2.setFlowOrder(2);
+ assertThat(model1.equals(model2)).isTrue();
+ }
+
+}
diff --git a/src/test/java/org/onap/clamp/policy/pdpgroup/PolicyModelKeyTest.java b/src/test/java/org/onap/clamp/policy/pdpgroup/PolicyModelKeyTest.java
new file mode 100644
index 000000000..413ce60ab
--- /dev/null
+++ b/src/test/java/org/onap/clamp/policy/pdpgroup/PolicyModelKeyTest.java
@@ -0,0 +1,55 @@
+/*-
+ * ============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.policy.pdpgroup;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import org.junit.Test;
+
+public class PolicyModelKeyTest {
+
+ @Test
+ public void testEqualsMethod() throws IOException {
+ PolicyModelKey key1 = new PolicyModelKey("name1","1.0.0");
+ PolicyModelKey key2 = new PolicyModelKey(null,"1.0.0");
+ PolicyModelKey key3 = new PolicyModelKey("name1",null);
+
+ assertThat(key1.equals(null)).isFalse();
+ assertThat(key1.equals("key2")).isFalse();
+
+ assertThat(key2.equals(key1)).isFalse();
+ assertThat(key3.equals(key1)).isFalse();
+
+ PolicyModelKey key4 = new PolicyModelKey("name2","1.0.0");
+ PolicyModelKey key5 = new PolicyModelKey("name1","2.0.0");
+ assertThat(key1.equals(key4)).isFalse();
+ assertThat(key1.equals(key5)).isFalse();
+
+ PolicyModelKey key6 = new PolicyModelKey("name(.*)","1.0.0");
+ PolicyModelKey key7 = new PolicyModelKey("name1","1.0.0");
+ assertThat(key1.equals(key6)).isTrue();
+ assertThat(key1.equals(key7)).isTrue();
+ }
+}