aboutsummaryrefslogtreecommitdiffstats
path: root/mso-catalog-db
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2018-01-17 12:03:49 +0000
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2018-01-17 12:03:49 +0000
commitbde8e855fa7177a8b230008b936f5457c5e5d94a (patch)
treefc86cac95d27d8de2012f63b2e47e4f701a6ee3d /mso-catalog-db
parent487482d147a46e237b6f4f8c1ae07762e3f49b05 (diff)
Improve UT for catalog db
Improve UT for catalog db. Change-Id: If3c86e76b36c69bd99c1f6536fb3f2d787e6ed0d Issue-ID: SO-360 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'mso-catalog-db')
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java14
-rw-r--r--mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java106
2 files changed, 111 insertions, 9 deletions
diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java
index 079d105dd4..af4d28d3ba 100644
--- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java
+++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java
@@ -759,22 +759,22 @@ public class CatalogDatabase implements Closeable {
* Return the newest version of a specific VNF resource (queried by Name).
*
* @param vnfType
- * @param version
+ * @param serviceVersion
* @return VnfResource object or null if none found
*/
public VnfResource getVnfResource (String vnfType, String serviceVersion) {
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get VNF resource with model_name " + vnfType + " and version=" + serviceVersion);
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get VNF resource with model_name " + vnfType + " and version=" + serviceVersion);
String hql = "FROM VnfResource WHERE modelName = :vnfName and version = :serviceVersion";
- Query query = getSession ().createQuery (hql);
- query.setParameter ("vnfName", vnfType);
- query.setParameter ("serviceVersion", serviceVersion);
+ Query query = getSession().createQuery(hql);
+ query.setParameter("vnfName", vnfType);
+ query.setParameter("serviceVersion", serviceVersion);
VnfResource resource = null;
try {
- resource = (VnfResource) query.uniqueResult ();
+ resource = (VnfResource) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: vnfType='" + vnfType + "', serviceVersion='" + serviceVersion + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for vnfType=" + vnfType + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for vnfType=" + vnfType);
diff --git a/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java b/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java
index cad4093936..ee12fe4eba 100644
--- a/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java
+++ b/mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java
@@ -1080,9 +1080,111 @@ public class CatalogDatabaseTest {
assertEquals(null, vnfResource);
}
+ @Test
+ public void getVnfResourceByTypeTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ VnfResource vnfResource = new VnfResource();
+ vnfResource.setModelUuid("123-uuid");
+ return vnfResource;
+ }
+ };
+
+ MockUp<Session> mockedSession = new MockUp<Session>() {
+ @Mock
+ public Query createQuery(String hql) {
+ return mockUpQuery.getMockInstance();
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ private Session getSession() {
+ return mockedSession.getMockInstance();
+ }
+ };
+ VnfResource vnfResource = cd.getVnfResource("vnf","3992");
+ assertEquals("123-uuid", vnfResource.getModelUuid());
+ }
+
+ @Test(expected = NonUniqueResultException.class)
+ public void getVnfResourceNURExceptionTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ throw new NonUniqueResultException(-1);
+ }
+ };
+
+ MockUp<Session> mockedSession = new MockUp<Session>() {
+ @Mock
+ public Query createQuery(String hql) {
+ return mockUpQuery.getMockInstance();
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ private Session getSession() {
+ return mockedSession.getMockInstance();
+ }
+ };
+ VnfResource vnfResource = cd.getVnfResource("vnf","3992");
+ }
+
+ @Test(expected = HibernateException.class)
+ public void getVnfResourceHibernateExceptionTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ throw new HibernateException("hibernate exception");
+ }
+ };
+
+ MockUp<Session> mockedSession = new MockUp<Session>() {
+ @Mock
+ public Query createQuery(String hql) {
+ return mockUpQuery.getMockInstance();
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ private Session getSession() {
+ return mockedSession.getMockInstance();
+ }
+ };
+ VnfResource vnfResource = cd.getVnfResource("vnf","3992");
+ }
+
@Test(expected = Exception.class)
- public void getVnfResource2TestException() throws Exception{
- VnfResource ht = cd.getVnfResource("vnf","3992");
+ public void getVnfResourceExceptionTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() throws Exception {
+ throw new Exception();
+ }
+ };
+
+ MockUp<Session> mockedSession = new MockUp<Session>() {
+ @Mock
+ public Query createQuery(String hql) {
+ return mockUpQuery.getMockInstance();
+ }
+ };
+
+ new MockUp<CatalogDatabase>() {
+ @Mock
+ private Session getSession() {
+ return mockedSession.getMockInstance();
+ }
+ };
+ VnfResource vnfResource = cd.getVnfResource("vnf","3992");
}
@Test(expected = Exception.class)