From ab3dd55d09241672cdfaf34652b01a593d630fc2 Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Wed, 17 Jan 2018 10:51:09 +0000 Subject: UT improvement for catalog db UT improvement for catalog db. Change-Id: Ie1a4554501ebc6e41a9a64b4613d72ae91e5ef03 Issue-ID: SO-360 Signed-off-by: subhash kumar singh --- .../mso/db/catalog/test/CatalogDatabaseTest.java | 55 ++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'mso-catalog-db/src/test/java') 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 d65928f508..2266392d9a 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 @@ -913,9 +913,58 @@ public class CatalogDatabaseTest { ServiceRecipe ht = cd.getServiceRecipe("123","tetwe"); } - @Test(expected = Exception.class) - public void getServiceRecipeByServiceModelUuidTestException() throws Exception{ - ServiceRecipe ht = cd.getServiceRecipeByServiceModelUuid("123","tetwe"); + @Test + public void getServiceRecipeByServiceModelUuidTest() { + MockUp mockUpQuery = new MockUp() { + @Mock + public List list() throws Exception { + 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(); + } + }; + ServiceRecipe serviceRecipe = cd.getServiceRecipeByServiceModelUuid("123","tetwe"); + assertEquals(1, serviceRecipe.getId()); + } + + @Test + public void getServiceRecipeByServiceModelUuidEmptyTest() { + MockUp mockUpQuery = new MockUp() { + @Mock + public List list() throws Exception { + 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(); + } + }; + ServiceRecipe serviceRecipe = cd.getServiceRecipeByServiceModelUuid("123","tetwe"); + assertEquals(null, serviceRecipe); } @Test(expected = Exception.class) -- cgit 1.2.3-korg