summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipe.java19
-rw-r--r--adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipeTest.java25
2 files changed, 38 insertions, 6 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipe.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipe.java
index 8670b78e15..58a2e852f0 100644
--- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipe.java
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipe.java
@@ -22,6 +22,7 @@ package org.onap.so.adapters.catalogdb.catalogrest;
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.lang3.StringUtils;
import org.onap.so.db.catalog.beans.Recipe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,12 +57,18 @@ public class QueryResourceRecipe extends CatalogQuery{
@Override
public String JSON2(boolean isArray, boolean isEmbed) {
Map<String, String> valueMap = new HashMap<>();
- valueMap.put("id", null == resourceRecipe ? null :String.valueOf(resourceRecipe.getId()));
- valueMap.put("action", null == resourceRecipe ? null :resourceRecipe.getAction());
- valueMap.put("orchestrationUri", null == resourceRecipe ? null : resourceRecipe.getOrchestrationUri());
- valueMap.put("recipeTimeout", null == resourceRecipe ? null : String.valueOf(resourceRecipe.getRecipeTimeout()));
- valueMap.put("paramXSD", null == resourceRecipe ? null : resourceRecipe.getParamXsd());
- valueMap.put("description", null == resourceRecipe ? null : resourceRecipe.getDescription());
+ valueMap.put("id", null == resourceRecipe || null == resourceRecipe.getId()
+ ? StringUtils.EMPTY :String.valueOf(resourceRecipe.getId()));
+ valueMap.put("action", null == resourceRecipe || null == resourceRecipe.getAction()
+ ? StringUtils.EMPTY :resourceRecipe.getAction());
+ valueMap.put("orchestrationUri", null == resourceRecipe || null == resourceRecipe.getOrchestrationUri()
+ ? StringUtils.EMPTY : resourceRecipe.getOrchestrationUri());
+ valueMap.put("recipeTimeout", null == resourceRecipe || null == resourceRecipe.getRecipeTimeout()
+ ? StringUtils.EMPTY : String.valueOf(resourceRecipe.getRecipeTimeout()));
+ valueMap.put("paramXSD", null == resourceRecipe || null == resourceRecipe.getParamXsd()
+ ? StringUtils.EMPTY : resourceRecipe.getParamXsd());
+ valueMap.put("description", null == resourceRecipe || null == resourceRecipe.getDescription()
+ ? StringUtils.EMPTY : resourceRecipe.getDescription());
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
String jsonStr = "";
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipeTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipeTest.java
index 645714cc80..e403867c42 100644
--- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipeTest.java
+++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryResourceRecipeTest.java
@@ -21,11 +21,16 @@
package org.onap.so.adapters.catalogdb.catalogrest;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.onap.so.db.catalog.beans.ArRecipe;
+import org.onap.so.db.catalog.beans.NetworkRecipe;
import org.onap.so.db.catalog.beans.Recipe;
import org.onap.so.db.catalog.beans.ServiceRecipe;
+import org.onap.so.db.catalog.beans.VnfRecipe;
import org.onap.so.jsonpath.JsonPathUtil;
public class QueryResourceRecipeTest {
@@ -67,4 +72,24 @@ public class QueryResourceRecipeTest {
return recipe;
}
+ @Test
+ public void convertToJson() {
+ Recipe recipe = createRecipe();
+ QueryResourceRecipe queryResourceRecipe = new QueryResourceRecipe(recipe);
+ assertEquals("{\"orchestrationUri\":\"uriTest\",\"action\":\"actionTest\",\"description\":\"descrTest\",\"id\":\"123\",\"recipeTimeout\":\"100\",\"paramXSD\":\"paramsXsdTest\"}",
+ queryResourceRecipe.JSON2(false,false));
+ }
+
+ @Test
+ public void convertToJsonEmptyRecipe() {
+ QueryResourceRecipe vnfQueryRR = new QueryResourceRecipe(new VnfRecipe());
+ QueryResourceRecipe networkQueryRR = new QueryResourceRecipe(new NetworkRecipe());
+ QueryResourceRecipe arQueryRR = new QueryResourceRecipe(new ArRecipe());
+
+ String expected = "{\"orchestrationUri\":\"\",\"action\":\"\",\"description\":\"\",\"id\":\"\",\"recipeTimeout\":\"\",\"paramXSD\":\"\"}";
+ assertEquals(expected, vnfQueryRR.JSON2(false, false));
+ assertEquals(expected, networkQueryRR.JSON2(false,false));
+ assertEquals(expected, arQueryRR.JSON2(false,false));
+ }
+
}