From 5621e24fe7336f978666e1a5bdae0adf75f4d144 Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Wed, 17 Jan 2018 11:43:47 +0000 Subject: Improve UT for catalog db Impove UT for catalog db. Change-Id: Iacbcb9de5ec92f929bfce8cfaac298e4a9ccf8b9 Issue-ID: SO-360 Signed-off-by: subhash kumar singh --- .../mso/db/catalog/test/CatalogDatabaseTest.java | 53 +++++++++++++++++++++- 1 file changed, 51 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 2266392d9a..445ca12892 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 @@ -967,9 +967,58 @@ public class CatalogDatabaseTest { assertEquals(null, serviceRecipe); } - @Test(expected = Exception.class) + @Test public void getServiceRecipesTestException() throws Exception{ - List ht = cd.getServiceRecipes("123"); + MockUp mockUpQuery = new MockUp() { + @Mock + public List list() { + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setId(1); + return Arrays.asList(serviceRecipe); + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + List serviceRecipes = cd.getServiceRecipes("123"); + assertEquals(1, serviceRecipes.size()); + } + + @Test + public void getServiceRecipesEmptyTest() throws Exception{ + MockUp mockUpQuery = new MockUp() { + @Mock + public List list() { + return Arrays.asList(); + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + List serviceRecipes = cd.getServiceRecipes("123"); + assertEquals(0, serviceRecipes.size()); } @Test(expected = Exception.class) -- cgit 1.2.3-korg