From 1d09928e0a228efe36fc4249ac47191ea5f78036 Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Thu, 18 Jan 2018 10:25:40 +0000 Subject: Improve UT for catalog db Improve UT for catalog DB Change-Id: I08d5a565d409cc00f32677918f4e8645cecf6754 Issue-ID: SO-360 Signed-off-by: subhash kumar singh --- .../mso/db/catalog/test/CatalogDatabaseTest.java | 104 ++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) (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 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 mockUpQuery = new MockUp() { + + @Mock + public Object uniqueResult(){ + VnfResource vnfResource = new VnfResource(); + vnfResource.setModelUuid("123-uuid"); + return vnfResource; + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @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 mockUpQuery = new MockUp() { + + @Mock + public Object uniqueResult(){ + throw new NonUniqueResultException(-1); + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); + } + + @Test(expected = HibernateException.class) + public void getVnfResourceByModelInvariantIdHibernateExceptionTest(){ + MockUp mockUpQuery = new MockUp() { + + @Mock + public Object uniqueResult(){ + 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(); + } + }; + VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); + } + @Test(expected = Exception.class) - public void getVnfResourceByModelInvariantIdTestException(){ + public void getVnfResourceByModelInvariantIdExceptionTest(){ + MockUp mockUpQuery = new MockUp() { + + @Mock + public Object uniqueResult() 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(); + } + }; VnfResource vnf = cd.getVnfResourceByModelInvariantId("test", "test234"); } -- cgit 1.2.3-korg