summaryrefslogtreecommitdiffstats
path: root/mso-catalog-db/src
diff options
context:
space:
mode:
Diffstat (limited to 'mso-catalog-db/src')
-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.java111
2 files changed, 117 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 0efcb484cb..0048a34d6c 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
@@ -982,19 +982,19 @@ public class CatalogDatabase implements Closeable {
return resultList.get(0);
}
- public VfModule getVfModuleModelName (String modelName, String model_version) {
+ public VfModule getVfModuleModelName(String modelName, String model_version) {
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get vfModuleModelName with type='" + modelName + "' and asdc_service_model_version='" + model_version + "'");
String hql = "FROM VfModule WHERE Name = :model_name and version = :model_version";
- Query query = getSession ().createQuery (hql);
- query.setParameter ("modelName", modelName);
- query.setParameter ("model_version", model_version);
+ Query query = getSession().createQuery(hql);
+ query.setParameter("modelName", modelName);
+ query.setParameter("model_version", model_version);
VfModule module = null;
try {
- module = (VfModule) query.uniqueResult ();
+ module = (VfModule) 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: type='" + modelName + "', asdc_service_model_version='" + model_version + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for type=" + modelName + " and version=" + model_version, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for type=" + modelName);
@@ -1012,9 +1012,9 @@ public class CatalogDatabase implements Closeable {
throw e;
}
if (module == null) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "NotFound", "CatalogDB", "getVfModuleModelName", null);
} else {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getVfModuleModelName", null);
}
return module;
}
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 2ec75d7582..9ea1ef8bd4 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
@@ -1497,12 +1497,117 @@ public class CatalogDatabaseTest {
assertEquals(null, vfModule);
}
- @Test(expected = Exception.class)
- public void getVfModuleModelName2TestException(){
- VfModule vnf = cd.getVfModuleModelName("tetes","4kidsl");
+ @Test
+ public void getVfModuleModelNameTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+
+ @Mock
+ public Object uniqueResult() {
+ VfModule vfModule = new VfModule();
+ vfModule.setModelUUID("123-uuid");
+ return vfModule;
+ }
+ };
+
+ 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();
+ }
+ };
+
+ VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl");
+ assertEquals("123-uuid", vfModule.getModelUUID());
+ }
+
+ @Test(expected = NonUniqueResultException.class)
+ public void getVfModuleModelNameNURExceptionTest() {
+ 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();
+ }
+ };
+
+ VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl");
+ }
+
+ @Test(expected = HibernateException.class)
+ public void getVfModuleModelNameHibernateExceptionTest() {
+ 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();
+ }
+ };
+
+ VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl");
}
@Test(expected = Exception.class)
+ public void getVfModuleModelNameGenericExceptionTest() {
+ 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();
+ }
+ };
+
+ VfModule vfModule = cd.getVfModuleModelName("tetes","4kidsl");
+ }
+ @Test(expected = Exception.class)
public void ggetVfModuleCustomizationByModelNameTestException(){
VfModuleCustomization vnf = cd.getVfModuleCustomizationByModelName("tetes");
}