diff options
Diffstat (limited to 'catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils')
9 files changed, 65 insertions, 216 deletions
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/CollectionUtilsTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/CollectionUtilsTest.java index ef84f0e0eb..04dc0591cf 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/CollectionUtilsTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/CollectionUtilsTest.java @@ -1,15 +1,11 @@ package org.openecomp.sdc.be.dao.utils; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.apache.tinkerpop.gremlin.structure.T; import org.junit.Assert; import org.junit.Test; +import java.util.*; + public class CollectionUtilsTest { @Test diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java index 06437adb65..3a915bcc71 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java @@ -1,9 +1,10 @@ package org.openecomp.sdc.be.dao.utils; -import org.apache.tinkerpop.gremlin.structure.T; import org.junit.Assert; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + public class DaoUtilsTest { @Test @@ -15,12 +16,7 @@ public class DaoUtilsTest { result = DaoUtils.convertToJson(object); Assert.assertEquals("{}", result); - try { - result = DaoUtils.convertToJson(null); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + assertThatThrownBy(()->DaoUtils.convertToJson(null)).isInstanceOf(RuntimeException.class); } @Test diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ImageQualityTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ImageQualityTest.java deleted file mode 100644 index 2dc8b52707..0000000000 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ImageQualityTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.openecomp.sdc.be.dao.utils; - -import org.junit.Test; - -public class ImageQualityTest { - - @Test - public void testGetSize() throws Exception { - int result; - - // default test - result = ImageQuality.QUALITY_128.getSize(); - } -}
\ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ImageResizeUtilTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ImageResizeUtilTest.java deleted file mode 100644 index cb12203eed..0000000000 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ImageResizeUtilTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.openecomp.sdc.be.dao.utils; - -import java.awt.image.BufferedImage; - -import org.junit.Test; - -import mockit.Deencapsulation; - -public class ImageResizeUtilTest { - - @Test - public void testResizeImage() throws Exception { - BufferedImage originalImage = new BufferedImage(1, 1, 1); - int width = 1; - int height = 1; - boolean preserveDimensions = false; - BufferedImage result; - - // default test - result = ImageResizeUtil.resizeImage(originalImage, width, height, preserveDimensions); - } - - @Test - public void testResizeImageWithHint() throws Exception { - BufferedImage originalImage = new BufferedImage(1, 1, 1); - int width = 1; - int height = 1; - boolean preserveDimensions = false; - BufferedImage result; - - // default test - result = ImageResizeUtil.resizeImageWithHint(originalImage, width, height, preserveDimensions); - } - - @Test - public void testResizeImage_1() throws Exception { - BufferedImage originalImage = new BufferedImage(1, 1, 1); - int width = 1; - int height = 1; - boolean preserveDimensions = true; - boolean enableHighQuality = false; - BufferedImage result; - - // default test - result = Deencapsulation.invoke(ImageResizeUtil.class, "resizeImage", - originalImage, width, height, preserveDimensions, enableHighQuality); - } - - @Test - public void testComputeDimensions() throws Exception { - int width = 0; - int height = 0; - int originalWidth = 0; - int originalHeight = 0; - int[] result; - - // default test - result = ImageResizeUtil.computeDimensions(width, height, originalWidth, originalHeight); - } -}
\ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/JsonUtilTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/JsonUtilTest.java index 955d55248c..b098cc6a17 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/JsonUtilTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/JsonUtilTest.java @@ -1,19 +1,14 @@ package org.openecomp.sdc.be.dao.utils; -import java.io.BufferedInputStream; -import java.io.InputStream; -import java.util.List; -import java.util.Map; - -import org.apache.cassandra.utils.vint.EncodedDataInputStream; -import org.apache.tinkerpop.gremlin.structure.T; +import com.fasterxml.jackson.databind.ObjectMapper; +import mockit.Deencapsulation; import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; -import com.fasterxml.jackson.databind.ObjectMapper; - -import mockit.Deencapsulation; +import java.io.InputStream; +import java.util.List; +import java.util.Map; public class JsonUtilTest { @@ -35,17 +30,6 @@ public class JsonUtilTest { result = JsonUtil.readObject(objectText, objectClass); } - @Ignore - @Test - public void testReadObject_1() throws Exception { - InputStream jsonStream = Mockito.mock(InputStream.class); - Class objectClass = Object.class; - Object result; - - // default test - result = JsonUtil.readObject(jsonStream, objectClass); - } - @Test public void testReadObject_2() throws Exception { String objectText = "{}"; @@ -94,15 +78,4 @@ public class JsonUtilTest { // default test result = JsonUtil.toList(json, clazz); } - - @Test - public void testToList_1() throws Exception { - String json = "[]"; - Class elementClass = List.class;; - Class elementGenericClass = List.class;; - List result; - - // default test - result = JsonUtil.toList(json, elementClass, elementGenericClass); - } }
\ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapEntryTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapEntryTest.java deleted file mode 100644 index 39245bc028..0000000000 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapEntryTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.openecomp.sdc.be.dao.utils; - -import org.junit.Test; - -public class MapEntryTest { - - private MapEntry createTestSubject() { - return new MapEntry(); - } - - @Test - public void testCtor() throws Exception { - new MapEntry(new Object(), new Object()); - } - - @Test - public void testGetKey() throws Exception { - MapEntry testSubject; - Object result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getKey(); - } - - @Test - public void testSetKey() throws Exception { - MapEntry testSubject; - Object key = null; - - // default test - testSubject = createTestSubject(); - testSubject.setKey(key); - } - - @Test - public void testGetValue() throws Exception { - MapEntry testSubject; - Object result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getValue(); - } - - @Test - public void testSetValue() throws Exception { - MapEntry testSubject; - Object value = null; - - // default test - testSubject = createTestSubject(); - testSubject.setValue(value); - } -}
\ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapUtilTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapUtilTest.java index ed2f3134d2..1f85a290e9 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapUtilTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapUtilTest.java @@ -1,17 +1,48 @@ package org.openecomp.sdc.be.dao.utils; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import com.google.common.collect.ImmutableMap; +import org.junit.Test; + +import java.util.*; import java.util.function.Function; -import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.openecomp.sdc.be.dao.utils.MapUtil.mergeMaps; public class MapUtilTest { - @Test + @Test + public void mergeMaps_whenBothMapsAreNull_returnEmptyMap() { + assertThat(mergeMaps(null, null)).isEmpty(); + } + + @Test + public void mergeMaps_whenFirstMapIsNull_returnSecondMap() { + ImmutableMap<String, String> second = ImmutableMap.of("a", "b", "c", "d"); + assertThat(mergeMaps(null, second)) + .isNotSameAs(second) + .containsAllEntriesOf(second); + } + + @Test + public void mergeMaps_whenSecondMapsIsNull_returnFirstMap() { + ImmutableMap<String, String> first = ImmutableMap.of("a", "b", "c", "d"); + assertThat(mergeMaps(first, null)) + .isNotSameAs(first) + .containsAllEntriesOf(first); + } + + @Test + public void mergeMaps_avoidDuplications_takeValFromFirstMap() { + ImmutableMap<String, String> first = ImmutableMap.of("key1", "val1", "key2", "val2"); + ImmutableMap<String, String> second = ImmutableMap.of("key1", "val11", "key3", "val3"); + assertThat(mergeMaps(first, second)) + .containsEntry("key1", "val1") + .containsEntry("key2", "val2") + .containsEntry("key3", "val3"); + } + @Test public void testGet() throws Exception { Map<String, ? extends Object> map = null; String path = ""; @@ -67,43 +98,30 @@ public class MapUtilTest { @Test public void testNewHashMap() throws Exception { - String[] keys = new String[] { "mock" }; - String[] values = new String[] { "mock" }; + final String[] keys1 = new String[] { "mock" }; + final String[] values1 = new String[] { "mock" }; Map<String, String> result; // test 1 - result = MapUtil.newHashMap(keys, values); - //Assert.assertEquals(null, result); + result = MapUtil.newHashMap(keys1, values1); // test 2 - keys = new String[] { "mock" }; - values = null; - try { - result = MapUtil.newHashMap(keys, values); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + final String[] keys2 = new String[] { "mock" }; + final String[] values2 = null; + assertThatThrownBy(() -> MapUtil.newHashMap(keys2, values2)) + .isInstanceOf(IllegalArgumentException.class); // test 3 - values = null; - keys = null; - try { - result = MapUtil.newHashMap(keys, values); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - //Assert.assertEquals(null, result); + final String[] keys3 = null; + final String[] values3 = null; + assertThatThrownBy(() -> MapUtil.newHashMap(keys3, values3)) + .isInstanceOf(IllegalArgumentException.class); // test 4 - values = new String[] { "mock" }; - keys = null; - try { - result = MapUtil.newHashMap(keys, values); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + final String[] values4 = new String[] { "mock" }; + final String[] keys4 = null; + assertThatThrownBy(() -> MapUtil.newHashMap(keys4, values4)) + .isInstanceOf(IllegalArgumentException.class); + } }
\ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/TypeMapTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/TypeMapTest.java index 1909a16e60..186b4eb8ea 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/TypeMapTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/TypeMapTest.java @@ -1,11 +1,7 @@ package org.openecomp.sdc.be.dao.utils; -import java.util.Map; - import org.junit.Test; -import mockit.Deencapsulation; - public class TypeMapTest { private TypeMap createTestSubject() { diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/UserStatusEnumTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/UserStatusEnumTest.java index 46e35bf228..c5688e414c 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/UserStatusEnumTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/UserStatusEnumTest.java @@ -1,10 +1,9 @@ package org.openecomp.sdc.be.dao.utils; +import fj.data.Either; import org.junit.Test; import org.openecomp.sdc.common.util.MethodActivationStatusEnum; -import fj.data.Either; - public class UserStatusEnumTest { @Test |