summaryrefslogtreecommitdiffstats
path: root/catalog-dao/src/test
diff options
context:
space:
mode:
authorTal Gitelman <tg851x@intl.att.com>2018-05-30 18:19:45 +0300
committerTal Gitelman <tg851x@intl.att.com>2018-05-30 18:22:06 +0300
commita108e8bce15c71acec55b2d20cff546c0ae0a647 (patch)
treea610dda58bd0acba8cef6b7945ae986b59830dfe /catalog-dao/src/test
parent5a0a74f55f9661b218faff2f2ba710dc9a4f5443 (diff)
new unit tests for sdc-dao
Change-Id: I734ad9a0ef636ed6a2d70ff68dd06036bf2447e3 Issue-ID: SDC-1333 Signed-off-by: Tal Gitelman <tg851x@intl.att.com>
Diffstat (limited to 'catalog-dao/src/test')
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/CollectionUtilsTest.java63
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java43
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ElasticSearchUtilTest.java19
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ImageQualityTest.java14
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ImageResizeUtilTest.java60
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/JsonUtilTest.java108
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/MapEntryTest.java31
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ArtifactDaoTest.java31
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/AuditingDaoTest.java23
9 files changed, 331 insertions, 61 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
new file mode 100644
index 0000000000..ef84f0e0eb
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/CollectionUtilsTest.java
@@ -0,0 +1,63 @@
+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;
+
+public class CollectionUtilsTest {
+
+ @Test
+ public void testMerge() throws Exception {
+ Set<T> source = null;
+ Set<T> target = null;
+ Set<T> result;
+
+ // test 1
+ target = null;
+ result = CollectionUtils.merge(source, target);
+ Assert.assertEquals(null, result);
+
+ // test 2
+ source = null;
+ result = CollectionUtils.merge(source, target);
+ Assert.assertEquals(null, result);
+ }
+
+ @Test
+ public void testMerge_1() throws Exception {
+ Map<String, String> source = new HashMap();
+ Map<String, String> target = new HashMap();
+ boolean override = false;
+ Map<String, String> result;
+
+ result = CollectionUtils.merge(source, target, override);
+ Assert.assertEquals(null, result);
+
+ // test 1
+ target = null;
+ result = CollectionUtils.merge(source, target, override);
+ Assert.assertEquals(null, result);
+
+ // test 2
+ source = null;
+ result = CollectionUtils.merge(source, target, override);
+ Assert.assertEquals(null, result);
+ }
+
+ @Test
+ public void testMerge_2() throws Exception {
+ List<T> source = new LinkedList<>();
+ List<T> target = new LinkedList<>();
+ List<T> result;
+
+ // test 1
+ result = CollectionUtils.merge(source, target);
+ Assert.assertEquals(target, result);
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000000..06437adb65
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java
@@ -0,0 +1,43 @@
+package org.openecomp.sdc.be.dao.utils;
+
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DaoUtilsTest {
+
+ @Test
+ public void testConvertToJson() throws Exception {
+ Object object = new Object();
+ String result;
+
+ // test 1
+ result = DaoUtils.convertToJson(object);
+ Assert.assertEquals("{}", result);
+
+ try {
+ result = DaoUtils.convertToJson(null);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testConvertFromJson() throws Exception {
+ Class clazz = Object.class;
+ String json = null;
+ Object result;
+
+ // default test
+ result = DaoUtils.convertFromJson(clazz, json);
+ Assert.assertEquals(null, result);
+
+ try {
+ result = DaoUtils.convertFromJson(null, json);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+} \ No newline at end of file
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ElasticSearchUtilTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ElasticSearchUtilTest.java
new file mode 100644
index 0000000000..f2c73f59f5
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ElasticSearchUtilTest.java
@@ -0,0 +1,19 @@
+package org.openecomp.sdc.be.dao.utils;
+
+import org.elasticsearch.action.search.SearchResponse;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ElasticSearchUtilTest {
+
+ @Test
+ public void testIsResponseEmpty() throws Exception {
+ SearchResponse searchResponse = null;
+ boolean result;
+
+ // test 1
+ searchResponse = null;
+ result = ElasticSearchUtil.isResponseEmpty(searchResponse);
+ Assert.assertEquals(true, result);
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000000..2dc8b52707
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ImageQualityTest.java
@@ -0,0 +1,14 @@
+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
new file mode 100644
index 0000000000..cb12203eed
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/ImageResizeUtilTest.java
@@ -0,0 +1,60 @@
+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
new file mode 100644
index 0000000000..955d55248c
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/JsonUtilTest.java
@@ -0,0 +1,108 @@
+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 org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import mockit.Deencapsulation;
+
+public class JsonUtilTest {
+
+ @Test
+ public void testGetOneObjectMapper() throws Exception {
+ ObjectMapper result;
+
+ // default test
+ result = Deencapsulation.invoke(JsonUtil.class, "getOneObjectMapper");
+ }
+
+ @Test
+ public void testReadObject() throws Exception {
+ String objectText = "{}";
+ Class objectClass = Object.class;
+ Object result;
+
+ // default test
+ 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 = "{}";
+ Object result;
+
+ // default test
+ result = JsonUtil.readObject(objectText);
+ }
+
+ @Test
+ public void testToMap() throws Exception {
+ String json = "{\"name\":\"mock\",\"age\":0}";
+ Map<String, Object> result;
+
+ // default test
+ result = JsonUtil.toMap(json);
+ }
+
+ @Test
+ public void testToMap_1() throws Exception {
+ String json = "{\"name\":\"mock\",\"age\":0}";
+ Class keyTypeClass = Object.class;
+ Class valueTypeClass = Object.class;
+ Map result;
+
+ // default test
+ result = JsonUtil.toMap(json, keyTypeClass, valueTypeClass);
+ }
+
+ @Test
+ public void testToArray() throws Exception {
+ String json = "[]";
+ Class valueTypeClass = Object.class;
+ Object[] result;
+
+ // default test
+ result = JsonUtil.toArray(json, valueTypeClass);
+ }
+
+ @Test
+ public void testToList() throws Exception {
+ String json = "[]";
+ Class clazz = Object.class;
+ List result;
+
+ // 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
index ee7f703187..39245bc028 100644
--- 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
@@ -1,39 +1,52 @@
package org.openecomp.sdc.be.dao.utils;
-import org.apache.tinkerpop.gremlin.structure.T;
-import org.elasticsearch.common.recycler.Recycler.V;
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;
- T key = null;
+ 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;
- V value = null;
+ Object value = null;
// default test
testSubject = createTestSubject();
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ArtifactDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ArtifactDaoTest.java
index 29d5d60870..cac21c8b34 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ArtifactDaoTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ArtifactDaoTest.java
@@ -52,17 +52,12 @@ import fj.data.Either;
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class }) // ,
// CassandraUnitTestExecutionListener.class})
-// @EmbeddedCassandra(host ="localhost", port=9042)
public class ArtifactDaoTest extends DAOConfDependentTest {
private static final String TEST_IMAGES_DIRECTORY = "src/test/resources/images";
@Resource
ElasticSearchClient esclient;
- /*
- * @Resource(name = "artifact-dao") private IArtifactDAO artifactDAO;
- */
-
@Resource(name = "resource-upload")
private IResourceUploader daoUploader;
ESArtifactData arData;
@@ -74,32 +69,6 @@ public class ArtifactDaoTest extends DAOConfDependentTest {
private static ConfigurationManager configurationManager;
- @Before
- public void before() {
- // try {
- // clearIndex(ICatalogDAO.RESOURCES_INDEX, ArtifactData.class);
- // clearIndex(ICatalogDAO.RESOURCES_INDEX, ServiceArtifactData.class);
- // } catch (InterruptedException e) {
- // e.printStackTrace();
- // }
-
- }
-
- /*@BeforeClass
- public static void setupBeforeClass() {
- ExternalConfiguration.setAppName("catalog-dao");
- String appConfigDir = "src/test/resources/config/catalog-dao";
- ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
- appConfigDir);
- configurationManager = new ConfigurationManager(configurationSource);
- }*/
-
- // @Before
- // public void createSchema(){
- // SdcSchemaBuilder.createSchema();
- // }
- //
-
@Test
public void testSaveNewArtifact() {
// daoUploader = new ArtifactUploader(artifactDAO);
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/AuditingDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/AuditingDaoTest.java
index 10e2c9ea86..c5249c877b 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/AuditingDaoTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/AuditingDaoTest.java
@@ -39,13 +39,10 @@ import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.junit.After;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mockito;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.Configuration.ElasticSearchConfig.IndicesTimeFrequencyEntry;
-import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
import org.openecomp.sdc.be.dao.impl.AuditingDao;
@@ -55,12 +52,10 @@ import org.openecomp.sdc.be.resources.data.auditing.DistributionStatusEvent;
import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
import org.openecomp.sdc.be.resources.data.auditing.UserAccessEvent;
import org.openecomp.sdc.be.resources.data.auditing.UserAdminEvent;
-import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.be.utils.DAOConfDependentTest;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
-import org.openecomp.sdc.common.impl.ExternalConfiguration;
-import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
@@ -76,7 +71,7 @@ import fj.data.Either;
@ContextConfiguration("classpath:application-context-test.xml")
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class })
-public class AuditingDaoTest {
+public class AuditingDaoTest extends DAOConfDependentTest{
private static Logger log = LoggerFactory.getLogger(AuditingDaoTest.class.getName());
@Resource(name = "elasticsearch-client")
private ElasticSearchClient esclient;
@@ -84,20 +79,6 @@ public class AuditingDaoTest {
@Resource(name = "auditingDao")
private AuditingDao auditingDao;
- private static ConfigurationManager configurationManager;
- // private static Map<AuditingFieldsKeysEnum, String> auditField2esField;
-
- @BeforeClass
- public static void setupBeforeClass() {
-
- ExternalConfiguration.setAppName("catalog-dao");
- String appConfigDir = "src/test/resources/config/catalog-dao";
- ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
- appConfigDir);
- configurationManager = new ConfigurationManager(configurationSource);
- // initAudit2EsMap();
- }
-
@After
public void tearDown() {
deleteOldIndexes();