aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-01-19 05:45:45 +0000
committerGerrit Code Review <gerrit@onap.org>2018-01-19 05:45:45 +0000
commit91688f6679e357eb6a1c9bccb1683fbbd3ad32c7 (patch)
tree18d58491103aba0a374c7fbbdb55b553174cabc2
parentb52a8c3ad952a185ce87195affbaea923afb8e41 (diff)
parentec3394aa110893362424cc3b4518da0b5f6415c9 (diff)
Merge "Unit test improvement for catalog db"
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java42
-rw-r--r--mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java59
2 files changed, 77 insertions, 24 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 d27de9828f..7d59d2e0ae 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
@@ -462,25 +462,25 @@ public class CatalogDatabase implements Closeable {
LOGGER.debug ("Catalog database - get service modelUUID with id " + serviceNameVersionId);
String hql = "FROM Service WHERE MODEL_UUID = :MODEL_UUID and http_method = :http_method";
- query = getSession ().createQuery (hql);
- query.setParameter ("MODEL_UUID", serviceNameVersionId);
+ query = getSession().createQuery(hql);
+ query.setParameter("MODEL_UUID", serviceNameVersionId);
} else {
serviceId = map.get("serviceId");
serviceVersion = map.get("serviceVersion");
- LOGGER.debug ("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion);
+ LOGGER.debug("Catalog database - get serviceId with id " + serviceId + " and serviceVersion with " + serviceVersion);
String hql = "FROM Service WHERE service_id = :service_id and service_version = :service_version and http_method = :http_method";
- query = getSession ().createQuery (hql);
- query.setParameter ("service_id", serviceId);
- query.setParameter ("service_version", serviceVersion);
+ query = getSession().createQuery(hql);
+ query.setParameter("service_id", serviceId);
+ query.setParameter("service_version", serviceVersion);
}
- query.setParameter ("http_method", httpMethod);
+ query.setParameter("http_method", httpMethod);
- long startTime = System.currentTimeMillis ();
+ long startTime = System.currentTimeMillis();
Service service = null;
try {
- service = (Service) query.uniqueResult ();
+ service = (Service) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException nure) {
LOGGER.debug("Non Unique Result Exception - data integrity error: service_id='" + serviceId + "', serviceVersion='" + serviceVersion + "'");
LOGGER.error(MessageEnum.GENERAL_EXCEPTION, " non unique result for service_id=" + serviceId + " and serviceVersion=" + serviceVersion, "", "", MsoLogger.ErrorCode.DataError, "Non unique result for service_id=" + serviceId);
@@ -511,28 +511,28 @@ public class CatalogDatabase implements Closeable {
* @param modelName
* @return Service object or null if none found
*/
- public Service getServiceByModelName (String modelName){
+ public Service getServiceByModelName(String modelName){
- long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get service with name " + modelName);
+ long startTime = System.currentTimeMillis();
+ LOGGER.debug("Catalog database - get service with name " + modelName);
String hql = "FROM Service WHERE modelName = :MODEL_NAME";
- Query query = getSession ().createQuery (hql);
- query.setParameter ("MODEL_NAME", modelName);
+ Query query = getSession().createQuery(hql);
+ query.setParameter("MODEL_NAME", modelName);
@SuppressWarnings("unchecked")
- List <Service> resultList = query.list ();
+ List <Service> resultList = query.list();
// See if something came back.
- if (resultList.isEmpty ()) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByModelName", null);
+ if (resultList.isEmpty()) {
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service not found", "CatalogDB", "getServiceByModelName", null);
return null;
}
- Collections.sort (resultList, new MavenLikeVersioningComparator ());
- Collections.reverse (resultList);
+ Collections.sort(resultList, new MavenLikeVersioningComparator ());
+ Collections.reverse(resultList);
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelName", null);
- return resultList.get (0);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceByModelName", null);
+ return resultList.get(0);
}
public Service getServiceByVersionAndInvariantId(String modelInvariantId, String modelVersion) throws Exception {
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 dadedfb389..46c175c9fb 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
@@ -793,9 +793,62 @@ public class CatalogDatabaseTest {
assertEquals("123-uuid", service.getModelUUID());
}
- @Test(expected = Exception.class)
- public void getServiceByModelNameTestException(){
- Service ht = cd.getServiceByModelName("123");
+ @Test
+ public void getServiceByModelNameTest(){
+
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<Service> list() throws Exception {
+ Service service = new Service();
+ service.setModelUUID("123-uuid");
+ return Arrays.asList(service);
+ }
+ };
+
+ 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();
+ }
+ };
+
+ Service service = cd.getServiceByModelName("123");
+ assertEquals("123-uuid", service.getModelUUID());
+ }
+
+ @Test
+ public void getServiceByModelNameEmptyTest(){
+
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<Service> list() throws Exception {
+ return Arrays.asList();
+ }
+ };
+
+ 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();
+ }
+ };
+
+ Service service = cd.getServiceByModelName("123");
+ assertEquals(null, service);
}
@Test(expected = Exception.class)