diff options
author | subhash kumar singh <subhash.kumar.singh@huawei.com> | 2018-01-17 10:29:30 +0000 |
---|---|---|
committer | subhash kumar singh <subhash.kumar.singh@huawei.com> | 2018-01-17 10:29:30 +0000 |
commit | ec3394aa110893362424cc3b4518da0b5f6415c9 (patch) | |
tree | c9843366838104983c62fd6ca3065cff82776f3a /mso-catalog-db/src/test | |
parent | 89f89afa5bf730f359e18c3672682a8fb0970e85 (diff) |
Unit test improvement for catalog db
unit test improvement for catalog db.
Change-Id: Iff84fb58e973120d9dcaddc4ab3dba6e6ce34975
Issue-ID: SO-360
Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'mso-catalog-db/src/test')
-rw-r--r-- | mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java | 59 |
1 files changed, 56 insertions, 3 deletions
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 dadedfb389..46c175c9fb 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 @@ -793,9 +793,62 @@ public class CatalogDatabaseTest { assertEquals("123-uuid", service.getModelUUID()); } - @Test(expected = Exception.class) - public void getServiceByModelNameTestException(){ - Service ht = cd.getServiceByModelName("123"); + @Test + public void getServiceByModelNameTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<Service> list() throws Exception { + Service service = new Service(); + service.setModelUUID("123-uuid"); + return Arrays.asList(service); + } + }; + + 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(); + } + }; + + Service service = cd.getServiceByModelName("123"); + assertEquals("123-uuid", service.getModelUUID()); + } + + @Test + public void getServiceByModelNameEmptyTest(){ + + MockUp<Query> mockUpQuery = new MockUp<Query>() { + @Mock + public List<Service> list() throws Exception { + return Arrays.asList(); + } + }; + + 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(); + } + }; + + Service service = cd.getServiceByModelName("123"); + assertEquals(null, service); } @Test(expected = Exception.class) |