From 8954cade997f94979ea69c2bd463e0f4714dc5c5 Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Mon, 15 Jan 2018 09:17:30 +0000 Subject: Add test case for CatalogDatabase Add test case for getHeatTemplateByArtifactUuid(). Change-Id: I1ce9908cc01baeb7b5d6b58ba2b7a5f28262a5d6 Issue-ID: SO-360 Signed-off-by: subhash kumar singh --- .../mso/db/catalog/test/CatalogDatabaseTest.java | 174 +++++++++++++++------ 1 file changed, 124 insertions(+), 50 deletions(-) (limited to 'mso-catalog-db/src/test') 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 e19c67f7d0..f59dc5db2d 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 @@ -20,59 +20,12 @@ package org.openecomp.mso.db.catalog.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.Serializable; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.Connection; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - import mockit.Mock; import mockit.MockUp; -import org.hibernate.CacheMode; -import org.hibernate.Criteria; -import org.hibernate.Filter; -import org.hibernate.FlushMode; import org.hibernate.HibernateException; -import org.hibernate.IdentifierLoadAccess; -import org.hibernate.LobHelper; -import org.hibernate.LockMode; -import org.hibernate.LockOptions; -import org.hibernate.NaturalIdLoadAccess; +import org.hibernate.NonUniqueResultException; import org.hibernate.Query; -import org.hibernate.ReplicationMode; -import org.hibernate.SQLQuery; -import org.hibernate.ScrollMode; -import org.hibernate.ScrollableResults; import org.hibernate.Session; -import org.hibernate.SessionEventListener; -import org.hibernate.SessionFactory; -import org.hibernate.SharedSessionBuilder; -import org.hibernate.SimpleNaturalIdLoadAccess; -import org.hibernate.Transaction; -import org.hibernate.TypeHelper; -import org.hibernate.UnknownProfileException; -import org.hibernate.jdbc.ReturningWork; -import org.hibernate.jdbc.Work; -import org.hibernate.metamodel.source.annotations.xml.mocker.MockHelper; -import org.hibernate.procedure.ProcedureCall; -import org.hibernate.stat.SessionStatistics; -import org.hibernate.transform.ResultTransformer; -import org.hibernate.type.Type; import org.junit.Before; import org.junit.Test; import org.openecomp.mso.db.catalog.CatalogDatabase; @@ -99,6 +52,17 @@ import org.openecomp.mso.db.catalog.beans.VnfResource; import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization; import org.openecomp.mso.db.catalog.utils.RecordNotFoundException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + public class CatalogDatabaseTest { CatalogDatabase cd = null; @@ -305,9 +269,119 @@ public class CatalogDatabaseTest { assertEquals("123-uuid", ht.getAsdcUuid()); } + @Test + public void getHeatTemplateByArtifactUuidTest(){ + + MockUp mockUpQuery = new MockUp() { + + @Mock + public Object uniqueResult() { + HeatTemplate heatTemplate = new HeatTemplate(); + heatTemplate.setAsdcUuid("123-uuid"); + return heatTemplate; + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + HeatTemplate ht = cd.getHeatTemplateByArtifactUuidRegularQuery("123-uuid"); + assertEquals("123-uuid", ht.getAsdcUuid()); + } + + @Test(expected = HibernateException.class) + public void getHeatTemplateByArtifactUuidHibernateErrorTest(){ + + 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(); + } + }; + + HeatTemplate ht = cd.getHeatTemplateByArtifactUuidRegularQuery("123-uuid"); + } + + @Test(expected = NonUniqueResultException.class) + public void getHeatTemplateByArtifactUuidNonUniqueResultTest(){ + + MockUp mockUpQuery = new MockUp() { + + @Mock + public Object uniqueResult() { + throw new NonUniqueResultException(2); + } + }; + + MockUp mockedSession = new MockUp() { + @Mock + public Query createQuery(String hql) { + return mockUpQuery.getMockInstance(); + } + }; + + new MockUp() { + @Mock + private Session getSession() { + return mockedSession.getMockInstance(); + } + }; + + HeatTemplate ht = cd.getHeatTemplateByArtifactUuidRegularQuery("123-uuid"); + } + @Test(expected = Exception.class) - public void getHeatTemplateByArtifactUuidRegularQueryException(){ - HeatTemplate ht = cd.getHeatTemplateByArtifactUuidRegularQuery("123"); + public void getHeatTemplateByArtifactUuidGenericExceptionTest(){ + + 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(); + } + }; + + HeatTemplate ht = cd.getHeatTemplateByArtifactUuidRegularQuery("123-uuid"); } @Test(expected = Exception.class) -- cgit 1.2.3-korg