summaryrefslogtreecommitdiffstats
path: root/mso-catalog-db/src/test/java
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2018-01-18 10:08:08 +0000
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2018-01-18 10:08:08 +0000
commit89bf0b4f499c7fada8ad221defff5580d12331b6 (patch)
tree967e04c4fac616dbca84d3ed451df82b75d8077d /mso-catalog-db/src/test/java
parentbde8e855fa7177a8b230008b936f5457c5e5d94a (diff)
Improve UT for catalog DB
Impprove UT for catalog DB. Change-Id: I78a0525cd7775f4371efc5ccbc549ea410384491 Issue-ID: SO-360 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
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.java86
1 files changed, 83 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 ee12fe4eba..5b595a6720 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
@@ -1187,11 +1187,91 @@ public class CatalogDatabaseTest {
VnfResource vnfResource = cd.getVnfResource("vnf","3992");
}
- @Test(expected = Exception.class)
- public void getVnfResourceByModelCustomizationIdTestException() throws Exception{
- VnfResource ht = cd.getVnfResourceByModelCustomizationId("3992");
+ @Test
+ public void getVnfResourceByModelCustomizationIdTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() throws Exception {
+ 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 vnfResource = cd.getVnfResourceByModelCustomizationId("3992");
+ assertEquals("123-uuid",vnfResource.getModelUuid());
}
+ @Test(expected = NonUniqueResultException.class)
+ public void getVnfResourceByModelCustomizationIdNURExceptionTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() throws Exception {
+ 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 vnfResource = cd.getVnfResourceByModelCustomizationId("3992");
+ }
+
+ @Test(expected = HibernateException.class)
+ public void getVnfResourceByModelCustomizationIdHibernateExceptionTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() throws Exception {
+ 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 vnfResource = cd.getVnfResourceByModelCustomizationId("3992");
+ }
+
+
@Test(expected = Exception.class)
public void getServiceRecipeTest2Exception() throws Exception{
ServiceRecipe ht = cd.getServiceRecipe(1001,"3992");