diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2018-01-19 05:46:28 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-01-19 05:46:28 +0000 |
commit | 832ba43773fb16bb1eee1df5f0ecf31f09050d5d (patch) | |
tree | f9660e0f7f9c8fab6b9530538fe77567b71243a8 /mso-catalog-db/src/test/java | |
parent | d41ceec907809356784f6324d965f0b37a9a32a4 (diff) | |
parent | 1d09928e0a228efe36fc4249ac47191ea5f78036 (diff) |
Merge "Improve UT for catalog db"
Diffstat (limited to 'mso-catalog-db/src/test/java')
-rw-r--r-- | mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java | 104 |
1 files changed, 103 insertions, 1 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 53ce265709..219e70ea87 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 @@ -1331,8 +1331,110 @@ public class CatalogDatabaseTest { assertEquals(null, vnf); } + @Test + public void getVnfResourceByModelInvariantIdTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult(){ + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelUuid("123-uuid"); + return vnfResource; + } + }; + + 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(); + } + }; + VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); + assertEquals("123-uuid", vnf.getModelUuid()); + } + + @Test(expected = NonUniqueResultException.class) + public void getVnfResourceByModelInvariantIdNURExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult(){ + throw new NonUniqueResultException(-1); + } + }; + + 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(); + } + }; + VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); + } + + @Test(expected = HibernateException.class) + public void getVnfResourceByModelInvariantIdHibernateExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult(){ + throw new HibernateException("hibernate exception"); + } + }; + + 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(); + } + }; + VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); + } + @Test(expected = Exception.class) - public void getVnfResourceByModelInvariantIdTestException(){ + public void getVnfResourceByModelInvariantIdExceptionTest(){ + MockUp<Query> mockUpQuery = new MockUp<Query>() { + + @Mock + public Object uniqueResult() throws Exception { + throw new Exception(); + } + }; + + 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(); + } + }; VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); } |