From 402f8dc916e938a55dd54f721b3ce3928a7409a0 Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Wed, 23 Jan 2019 16:42:13 +0530 Subject: Fix get of operationType OperationType should return empty from db request instead of "null". Change-Id: I5df3df5aead6008c4e14961ee385cafe64c37959 Issue-ID: SO-1417 Signed-off-by: subhash kumar singh --- .../catalogdb/catalogrest/QueryResourceRecipe.java | 19 ++++++++++------ .../catalogrest/QueryResourceRecipeTest.java | 25 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) (limited to 'adapters') 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 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)); + } + } -- cgit 1.2.3-korg