Add test case for getHeatTemplate 49/28149/2
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>
Mon, 15 Jan 2018 06:47:58 +0000 (06:47 +0000)
committersubhash kumar singh <subhash.kumar.singh@huawei.com>
Mon, 15 Jan 2018 06:55:52 +0000 (06:55 +0000)
Add test case for getHeatTemplage body.

Change-Id: Iabcefa9d27b6b146921b50c99413e56273a21b3b
Issue-ID: SO-360
Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java
mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java

index 9445ccc..b9a69e7 100644 (file)
@@ -266,10 +266,10 @@ public class CatalogDatabase implements Closeable {
      *
      * @param artifactUuid
      * @return HeatTemplate object or null if none found
-     */    
+     */
     public HeatTemplate getHeatTemplateByArtifactUuidRegularQuery(String artifactUuid) {
-       long startTime = System.currentTimeMillis ();
-        LOGGER.debug ("Catalog database - get Heat template (regular query) with artifactUuid " + artifactUuid);
+        long startTime = System.currentTimeMillis();
+        LOGGER.debug("Catalog database - get Heat template (regular query) with artifactUuid " + artifactUuid);
 
         String hql = "FROM HeatTemplate WHERE artifactUuid = :artifactUuidValue";
         HashMap<String, String> variables = new HashMap<>();
@@ -277,9 +277,9 @@ public class CatalogDatabase implements Closeable {
         HeatTemplate template = (HeatTemplate) this.executeQuerySingleRow(hql, variables, true);
 
         if (template == null) {
-               LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
+            LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
         } else {
-               LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
+            LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getHeatTemplateByArtifactUuidRegularQuery", null);
         }
         return template;
     }
index 5e6ccc4..e19c67f 100644 (file)
@@ -282,9 +282,27 @@ public class CatalogDatabaseTest {
         assertEquals(null, ht);
     }
 
-    @Test(expected = Exception.class)
+    @Test
     public void getHeatTemplateByArtifactUuidException(){
+
+        MockUp<Session> mockedSession = new MockUp<Session>() {
+            @Mock
+            public Object get(Class cls, Serializable id) {
+                HeatTemplate heatTemplate = new HeatTemplate();
+                heatTemplate.setAsdcUuid("123-uuid");
+                return heatTemplate;
+            }
+        };
+
+        new MockUp<CatalogDatabase>() {
+            @Mock
+            private Session getSession() {
+                return mockedSession.getMockInstance();
+            }
+        };
+
         HeatTemplate ht = cd.getHeatTemplateByArtifactUuid("123");
+        assertEquals("123-uuid", ht.getAsdcUuid());
     }
 
     @Test(expected = Exception.class)