From 91293d4807d0f2946971dd066b1a5cb0f1d0e06e Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Mon, 15 Jan 2018 11:46:46 +0000 Subject: Improve TC for catalog database Improve TC for catalog database class. Change-Id: I5f4044e2e4151ba0382e914287ab03381962743f Issue-ID: SO-360 Signed-off-by: subhash kumar singh --- .../mso/db/catalog/test/CatalogDatabaseTest.java | 83 +++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) (limited to 'mso-catalog-db/src/test/java/org') 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 f59dc5db2d..84e697b20c 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 @@ -384,9 +384,88 @@ public class CatalogDatabaseTest { HeatTemplate ht = cd.getHeatTemplateByArtifactUuidRegularQuery("123-uuid"); } + @Test + public void getParametersForHeatTemplateTest(){ + + MockUp mockUpQuery = new MockUp() { + @Mock + public List list() { + HeatTemplate heatTemplate = new HeatTemplate(); + heatTemplate.setAsdcUuid("1234-uuid"); + return Arrays.asList(heatTemplate); + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + List htList = cd.getParametersForHeatTemplate("12l3"); + assertEquals(1, htList.size()); + } + + @Test(expected = HibernateException.class) + public void getParametersForHeatTemplateHibernateExceptionTest(){ + + MockUp mockUpQuery = new MockUp() { + @Mock + public List list() { + throw new HibernateException("hibernate exception"); + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + List htList = cd.getParametersForHeatTemplate("12l3"); + } + @Test(expected = Exception.class) - public void getParametersForHeatTemplateTestException(){ - List ht = cd.getParametersForHeatTemplate("123"); + public void getParametersForHeatTemplateExceptionTest(){ + + MockUp mockUpQuery = new MockUp() { + @Mock + public List list() throws Exception { + throw new Exception(); + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + List htList = cd.getParametersForHeatTemplate("12l3"); } @Test(expected = Exception.class) -- cgit 1.2.3-korg