aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-01-19 05:46:18 +0000
committerGerrit Code Review <gerrit@onap.org>2018-01-19 05:46:18 +0000
commitf9dc5780551a99937b997cd98e8ee5cc70638863 (patch)
tree4e26c73007a5ab7f0ebaa11738991d9efdb388ee
parent811a3665fcbd19f7e6682ffe9eb9293212a26770 (diff)
parent89bf0b4f499c7fada8ad221defff5580d12331b6 (diff)
Merge "Improve UT for catalog DB"
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java18
-rw-r--r--mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java86
2 files changed, 92 insertions, 12 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 af4d28d3ba..0804d3c162 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
@@ -807,22 +807,22 @@ public class CatalogDatabase implements Closeable {
* @param modelCustomizationId
* @return VnfResource object or null if none found
*/
- public VnfResource getVnfResourceByModelCustomizationId (String modelCustomizationId) {
+ public VnfResource getVnfResourceByModelCustomizationId(String modelCustomizationId) {
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId);
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get VNF resource with modelCustomizationId " + modelCustomizationId);
String hql = "SELECT vr "
+ "FROM VnfResource as vr JOIN vr.vnfResourceCustomizations as vrc "
+ "WHERE vrc.modelCustomizationUuid = :modelCustomizationId";
- Query query = getSession ().createQuery (hql);
- query.setParameter ("modelCustomizationId", modelCustomizationId);
+ Query query = getSession().createQuery(hql);
+ query.setParameter("modelCustomizationId", modelCustomizationId);
VnfResource resource = null;
try {
- resource = (VnfResource) query.uniqueResult ();
- } catch (org.hibernate.NonUniqueResultException nure) {
+ 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: modelCustomizationUuid='" + modelCustomizationId + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for modelCustomizationUuid=" + modelCustomizationId, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for modelCustomizationId=" + modelCustomizationId);
@@ -839,9 +839,9 @@ public class CatalogDatabase implements Closeable {
throw e;
}
if (resource == null) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
} else {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVnfResourceByModelCustomizationId", null);
}
return resource;
}
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");