aboutsummaryrefslogtreecommitdiffstats
path: root/mso-catalog-db
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2018-01-18 10:25:40 +0000
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2018-01-18 10:25:40 +0000
commit1d09928e0a228efe36fc4249ac47191ea5f78036 (patch)
tree31e66e74fee5d0e01b2e45e0b3cf2c91d8840bc7 /mso-catalog-db
parent2c83c8aefe45d0dd5a3486482f296de1da67b2dc (diff)
Improve UT for catalog db
Improve UT for catalog DB Change-Id: I08d5a565d409cc00f32677918f4e8645cecf6754 Issue-ID: SO-360 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'mso-catalog-db')
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java15
-rw-r--r--mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java104
2 files changed, 111 insertions, 8 deletions
diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java
index b65b6670ff..0219e304cb 100644
--- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java
+++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java
@@ -885,22 +885,23 @@ public class CatalogDatabase implements Closeable {
/**
* Return the newest version of a specific VNF resource (queried by modelInvariantId).
*
- * @param version
+ * @param modelInvariantUuid model invariant ID
+ * @param modelVersion model version
* @return VnfResource object or null if none found
*/
public VnfResource getVnfResourceByModelInvariantId(String modelInvariantUuid, String modelVersion) {
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get VNF resource with modelInvariantUuid " + modelInvariantUuid);
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get VNF resource with modelInvariantUuid " + modelInvariantUuid);
String hql = "FROM VnfResource WHERE modelInvariantUuid = :modelInvariantUuid and version = :serviceVersion";
- Query query = getSession ().createQuery (hql);
- query.setParameter ("modelInvariantUuid", modelInvariantUuid);
- query.setParameter ("serviceVersion", modelVersion);
+ Query query = getSession().createQuery(hql);
+ query.setParameter("modelInvariantUuid", modelInvariantUuid);
+ query.setParameter("serviceVersion", modelVersion);
VnfResource resource = null;
try {
- resource = (VnfResource) query.uniqueResult ();
+ resource = (VnfResource) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - the Catalog Database does not match a unique row - data integrity error: modelInvariantUuid='" + modelInvariantUuid + "', serviceVersion='" + modelVersion + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelInvariantUuid=" + modelInvariantUuid + " and serviceVersion=" + modelVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelInvariantUuid=" + modelInvariantUuid);
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");
}