summaryrefslogtreecommitdiffstats
path: root/mso-catalog-db
diff options
context:
space:
mode:
Diffstat (limited to 'mso-catalog-db')
-rw-r--r--mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java28
-rw-r--r--mso-catalog-db/src/test/java/org/openecomp/mso/db/catalog/test/CatalogDatabaseTest.java55
2 files changed, 66 insertions, 17 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 b5d8324872..ed30e61640 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
@@ -614,41 +614,41 @@ public class CatalogDatabase implements Closeable {
* @param action *
* @return ServiceRecipe object or null if none found
*/
- public ServiceRecipe getServiceRecipeByServiceModelUuid (String serviceModelUuid, String action) {
+ public ServiceRecipe getServiceRecipeByServiceModelUuid(String serviceModelUuid, String action) {
StringBuilder hql;
if(action == null){
- hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid");
+ hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid");
}else {
- hql = new StringBuilder ("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid AND action = :action ");
+ hql = new StringBuilder("FROM ServiceRecipe WHERE serviceModelUuid = :serviceModelUuid AND action = :action ");
}
long startTime = System.currentTimeMillis ();
- LOGGER.debug ("Catalog database - get Service recipe with serviceModelUuid " + serviceModelUuid
+ LOGGER.debug("Catalog database - get Service recipe with serviceModelUuid " + serviceModelUuid
+ " and action "
+ action
);
- Query query = getSession ().createQuery (hql.toString ());
- query.setParameter ("serviceModelUuid", serviceModelUuid);
+ Query query = getSession().createQuery(hql.toString());
+ query.setParameter("serviceModelUuid", serviceModelUuid);
if(action != null){
- query.setParameter (ACTION, action);
+ query.setParameter(ACTION, action);
}
@SuppressWarnings("unchecked")
- List <ServiceRecipe> resultList = query.list ();
+ List <ServiceRecipe> resultList = query.list();
- if (resultList.isEmpty ()) {
- LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", null);
+ if (resultList.isEmpty()) {
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully. Service recipe not found", "CatalogDB", "getServiceRecipe", 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", "getServiceRecipe", null);
- return resultList.get (0);
+ LOGGER.recordMetricEvent(startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "getServiceRecipe", null);
+ return resultList.get(0);
}
public List<ServiceRecipe> getServiceRecipes (String serviceModelUuid) {
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 d65928f508..2266392d9a 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
@@ -913,9 +913,58 @@ public class CatalogDatabaseTest {
ServiceRecipe ht = cd.getServiceRecipe("123","tetwe");
}
- @Test(expected = Exception.class)
- public void getServiceRecipeByServiceModelUuidTestException() throws Exception{
- ServiceRecipe ht = cd.getServiceRecipeByServiceModelUuid("123","tetwe");
+ @Test
+ public void getServiceRecipeByServiceModelUuidTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<ServiceRecipe> list() throws Exception {
+ ServiceRecipe serviceRecipe = new ServiceRecipe();
+ serviceRecipe.setId(1);
+ return Arrays.asList(serviceRecipe);
+ }
+ };
+
+ 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();
+ }
+ };
+ ServiceRecipe serviceRecipe = cd.getServiceRecipeByServiceModelUuid("123","tetwe");
+ assertEquals(1, serviceRecipe.getId());
+ }
+
+ @Test
+ public void getServiceRecipeByServiceModelUuidEmptyTest() {
+ MockUp<Query> mockUpQuery = new MockUp<Query>() {
+ @Mock
+ public List<ServiceRecipe> 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();
+ }
+ };
+ ServiceRecipe serviceRecipe = cd.getServiceRecipeByServiceModelUuid("123","tetwe");
+ assertEquals(null, serviceRecipe);
}
@Test(expected = Exception.class)