From c6fe4a8796faaa3ff85d7e47f6e5b8bce2d1b51f Mon Sep 17 00:00:00 2001 From: "Eran (ev672n), Vosk" Date: Thu, 1 Nov 2018 14:33:14 +0200 Subject: Adding more UTs Raising the code coverage in the project Change-Id: I4561f75db959bbea12310c08965bacb544cb1f7a Issue-ID: SDC-1872 Signed-off-by: Eran (ev672n), Vosk --- .../ruleeditor/ConditionDeserializerTest.java | 28 ++++++++++++++++ .../ruleeditor/DateFormatterActionTest.java | 28 ++++++++++++++++ .../restmodels/ruleeditor/MapActionTest.java | 27 +++++++++++++++ .../restmodels/ruleeditor/MappingRulesTest.java | 35 +++++++++++++++++-- .../restmodels/ruleeditor/RuleTest.java | 39 ++++++++++++++++++++++ 5 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionDeserializerTest.java create mode 100644 src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/DateFormatterActionTest.java create mode 100644 src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapActionTest.java create mode 100644 src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/RuleTest.java (limited to 'src') diff --git a/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionDeserializerTest.java b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionDeserializerTest.java new file mode 100644 index 0000000..42c2ecb --- /dev/null +++ b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionDeserializerTest.java @@ -0,0 +1,28 @@ +package org.onap.sdc.dcae.composition.restmodels.ruleeditor; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.junit.Test; + +import java.util.ArrayList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ConditionDeserializerTest { + + private Gson gson = new GsonBuilder().registerTypeAdapter(BaseCondition.class, new ConditionDeserializer()).create(); + + @Test + public void deserializerTest(){ + Condition condition = new Condition(); + condition.setLeft("map"); + condition.setRight(new ArrayList<>()); + condition.setOperator("test"); + condition.setEmptyIsAssigned(true); + String input = gson.toJson(condition); + BaseCondition res = gson.fromJson(input, BaseCondition.class); + assertEquals(gson.toJson(res), input); + assertTrue(res instanceof Condition); + } +} diff --git a/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/DateFormatterActionTest.java b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/DateFormatterActionTest.java new file mode 100644 index 0000000..defec7f --- /dev/null +++ b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/DateFormatterActionTest.java @@ -0,0 +1,28 @@ +package org.onap.sdc.dcae.composition.restmodels.ruleeditor; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class DateFormatterActionTest { + private DateFormatterAction classUnderTest = new DateFormatterAction(); + + @Test + public void checkEqualsTrueOther() { + DateFormatterAction dateFormatterAction = new DateFormatterAction(); + assertTrue(classUnderTest.equals(dateFormatterAction)); + } + + @Test + public void checkEqualsTrueSame() { + assertTrue(classUnderTest.equals(classUnderTest)); + } + + @Test + public void checkEqualsFalse() { + assertFalse(classUnderTest.equals(null)); + } + + +} diff --git a/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapActionTest.java b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapActionTest.java new file mode 100644 index 0000000..7a3c9a1 --- /dev/null +++ b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapActionTest.java @@ -0,0 +1,27 @@ +package org.onap.sdc.dcae.composition.restmodels.ruleeditor; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class MapActionTest { + private MapAction classUnderTest = new MapAction(); + + @Test + public void checkEqualsTrueOther() { + MapAction equalMapAction = new MapAction(); + assertTrue(classUnderTest.equals(equalMapAction)); + } + + @Test + public void checkEqualsTrueSame() { + assertTrue(classUnderTest.equals(classUnderTest)); + } + + @Test + public void checkEqualsFalse() { + assertFalse(classUnderTest.equals(null)); + } + +} diff --git a/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRulesTest.java b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRulesTest.java index 705ef6a..ae87b57 100644 --- a/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRulesTest.java +++ b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRulesTest.java @@ -5,8 +5,7 @@ import org.junit.Test; import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor; import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCodeFor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; public class MappingRulesTest { @@ -37,6 +36,38 @@ public class MappingRulesTest { assertEquals(NOTIFY_ID, classUnderTest.getNotifyId()); } + @Test + public void getRulesTest() { + classUnderTest.addOrReplaceRule(new Rule()); + assertEquals(1, classUnderTest.getRules().size()); + } + + @Test + public void containsRulesTest() { + Rule rule = new Rule(); + assertFalse(classUnderTest.ruleExists(rule)); + assertTrue(classUnderTest.isEmpty()); + classUnderTest.addOrReplaceRule(rule); + assertTrue(classUnderTest.ruleExists(rule)); + assertFalse(classUnderTest.isEmpty()); + } + + @Test + public void checkEqualsTrueOther() { + MappingRules equalMappingRules = new MappingRules(); + assertTrue(classUnderTest.equals(equalMappingRules)); + } + + @Test + public void checkEqualsTrueSame() { + assertTrue(classUnderTest.equals(classUnderTest)); + } + + @Test + public void checkEqualsFalse() { + assertFalse(classUnderTest.equals(null)); + } + @Test public void testHasValidConstructor() { assertThat(MappingRules.class, hasValidBeanConstructor()); diff --git a/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/RuleTest.java b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/RuleTest.java new file mode 100644 index 0000000..27f8185 --- /dev/null +++ b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/RuleTest.java @@ -0,0 +1,39 @@ +package org.onap.sdc.dcae.composition.restmodels.ruleeditor; + +import org.junit.Test; + +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor; +import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCodeFor; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public class RuleTest { + private Rule classUnderTest = new Rule(); + + @Test + public void checkEqualsTrueOther() { + Rule equalRule = new Rule(); + assertTrue(classUnderTest.equals(equalRule)); + } + + @Test + public void checkEqualsTrueSame() { + assertTrue(classUnderTest.equals(classUnderTest)); + } + + @Test + public void checkEqualsFalse() { + assertFalse(classUnderTest.equals(null)); + } + + @Test + public void testHasValidConstructor() { + assertThat(Rule.class, hasValidBeanConstructor()); + } + + @Test + public void checkHashCodeFor() { + assertThat(Rule.class, hasValidBeanHashCodeFor()); + } +} -- cgit 1.2.3-korg