Improve UT for catalog db

Improve UT for catalog db

Change-Id: Ib9c5dad03c0107778c554c54d1586e0ddd79c297
Issue-ID: SO-360
Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
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 0efcb48..0048a34 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
@@ -982,19 +982,19 @@
         return resultList.get(0);
     }
 
-    public VfModule getVfModuleModelName (String modelName, String model_version) {
+    public VfModule getVfModuleModelName(String modelName, String model_version) {
 
-        long startTime = System.currentTimeMillis ();
-        LOGGER.debug ("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
+        long startTime = System.currentTimeMillis();
+        LOGGER.debug("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
 
         String hql = "FROM VfModule WHERE Name = :model_name and version = :model_version";
-        Query query = getSession ().createQuery (hql);
-        query.setParameter ("modelName", modelName);
-        query.setParameter ("model_version", model_version);
+        Query query = getSession().createQuery(hql);
+        query.setParameter("modelName", modelName);
+        query.setParameter("model_version", model_version);
 
         VfModule module = null;
         try {
-        	module = (VfModule) query.uniqueResult ();
+            module = (VfModule) 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: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
         	LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
@@ -1012,9 +1012,9 @@
         	throw e;
         }
         if (module == null) {
-        	LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
+            LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
         } else {
-        	LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
+            LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
         }
         return module;
     }
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 2ec75d7..9ea1ef8 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
@@ -1497,11 +1497,116 @@
         assertEquals(null, vfModule);
     }
 
-    @Test(expected = Exception.class)
-    public void getVfModuleModelName2TestException(){
-        VfModule vnf = cd.getVfModuleModelName("tetes","4kidsl");
+    @Test
+    public void getVfModuleModelNameTest() {
+        MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+            @Mock
+            public Object uniqueResult() {
+                VfModule vfModule = new VfModule();
+                vfModule.setModelUUID("123-uuid");
+                return vfModule;
+            }
+        };
+
+        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();
+            }
+        };
+
+        VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl");
+        assertEquals("123-uuid", vfModule.getModelUUID());
     }
 
+    @Test(expected = NonUniqueResultException.class)
+    public void getVfModuleModelNameNURExceptionTest() {
+        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();
+            }
+        };
+
+        VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl");
+    }
+
+    @Test(expected = HibernateException.class)
+    public void getVfModuleModelNameHibernateExceptionTest() {
+        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();
+            }
+        };
+
+        VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl");
+    }
+
+    @Test(expected = Exception.class)
+    public void getVfModuleModelNameGenericExceptionTest() {
+        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();
+            }
+        };
+
+        VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl");
+    }
     @Test(expected = Exception.class)
     public void ggetVfModuleCustomizationByModelNameTestException(){
         VfModuleCustomization vnf = cd.getVfModuleCustomizationByModelName("tetes");