Add junit for project mso-catalog-db-adapter 93/47193/2
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Mon, 7 May 2018 08:34:43 +0000 (10:34 +0200)
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>
Fri, 11 May 2018 11:28:24 +0000 (13:28 +0200)
Change-Id: I7b28cc713929400b03b7e567bf9823d82631a1e9
Issue-ID: SO-617
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModule.java
adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModules.java [deleted file]
adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/CatalogQueryTest.java
adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipeTest.java [new file with mode: 0644]
adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceCsarTest.java [new file with mode: 0644]
adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModuleTest.java [new file with mode: 0644]

index a8969dd..9215c38 100644 (file)
@@ -80,8 +80,9 @@ public class QueryVfModule extends CatalogQuery {
     }
 
        @Override
-       public String JSON2(boolean isArray, boolean x) {
+       public String JSON2(boolean isArray, boolean isEmbed) {
                StringBuilder sb = new StringBuilder();
+               if (!isEmbed && isArray) sb.append("{ ");
                if (isArray) sb.append("\"vfModules\": [");
                Map<String, String> valueMap = new HashMap<>();
                String sep = "";
@@ -112,6 +113,7 @@ public class QueryVfModule extends CatalogQuery {
                }
                if (!first) sb.append("\n");
                if (isArray) sb.append("]");
+               if (!isEmbed && isArray) sb.append("}");
                return sb.toString();
        }
 }
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModules.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModules.java
deleted file mode 100644 (file)
index 001a9f4..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.openecomp.mso.adapters.catalogdb.catalogrest;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.openecomp.mso.db.catalog.beans.VfModule;
-import org.openecomp.mso.logger.MsoLogger;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-@XmlRootElement(name = "vfModules")
-public class QueryVfModules {
-       private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
-       private List<VfModule> vfModules;
-
-       public QueryVfModules() {
-               super();
-               vfModules = new ArrayList<>();
-       }
-       public QueryVfModules(List<VfModule> vlist) { 
-               LOGGER.debug ("QueryVfModules:");
-               vfModules = new ArrayList<>();
-               for (VfModule o : vlist) {
-                       LOGGER.debug ("-- o is a vfModules ----");
-                       LOGGER.debug (o.toString());
-                       vfModules.add(o);
-                       LOGGER.debug ("-------------------");
-               }
-       }
-
-       public List<VfModule> getVfModules(){ return this.vfModules; }
-
-       public void setVfModules(List<VfModule> v) { this.vfModules = v; }
-       
-       @Override
-       public String toString () {
-               StringBuilder sb = new StringBuilder();
-
-               boolean first = true;
-               int i = 1;
-               for (VfModule o : vfModules) {
-                       sb.append(i).append("\t");
-                       if (!first) sb.append("\n");
-                       first = false;
-                       sb.append(o);
-               }
-               return sb.toString();
-    }
-       
-       public String toJsonString() {
-               String jsonString = null;
-               try {
-                       ObjectMapper mapper = new ObjectMapper();
-                       jsonString = mapper.writeValueAsString(this);
-                       LOGGER.debug ("QueryVfModules jsonString: "+jsonString);
-               }
-               catch (Exception e) {
-                   LOGGER.debug ("Exception:", e);
-                       LOGGER.debug ("QueryVfModules jsonString exception:"+e.getMessage()); 
-               }
-               return jsonString;
-       }
-}
index ee2c8db..a4a5df7 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
 package org.openecomp.mso.adapters.catalogdb.catalogrest;
 
-import java.io.StringReader;
-import java.util.ArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
+
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
 
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
+public class CatalogQueryTest {
+       private static final String MAP_KEY = "keyTest";
+       private static final String VALUE_MAP = "valueTest";
+       private CatalogQuery testedObject;
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.openecomp.mso.db.catalog.beans.VnfResourceCustomization;
+       @Before
+       public void init() {
+               testedObject = new CatalogQueryForTesting();
+       }
 
-import static org.junit.Assert.*;
+       @Test
+       public void putStringValueToMap() {
+               Map<String, String> valueMap = new HashMap<>();
+               testedObject.put(valueMap, MAP_KEY, VALUE_MAP);
+               assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "\"valueTest\"");
+       }
 
+       @Test
+       public void putNullStringValueToMap() {
+               Map<String, String> valueMap = new HashMap<>();
+               String value = null;
+               testedObject.put(valueMap, MAP_KEY, value);
+               assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "null");
+       }
 
-@RunWith(MockitoJUnitRunner.class)
-public class CatalogQueryTest {
+       @Test
+       public void putIntegerValueToMap() {
+               Map<String, String> valueMap = new HashMap<>();
+               testedObject.put(valueMap, MAP_KEY, 1);
+               assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "1");
+       }
+
+       @Test
+       public void putNullIntegerValueToMap() {
+               Map<String, String> valueMap = new HashMap<>();
+               Integer value = null;
+               testedObject.put(valueMap, MAP_KEY, value);
+               assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "null");
+       }
+
+       @Test
+       public void putTrueBooleanValueToMap() {
+               Map<String, String> valueMap = new HashMap<>();
+               testedObject.put(valueMap, MAP_KEY, true);
+               assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "true");
+       }
+
+       @Test
+       public void putFalseBooleanValueToMap() {
+               Map<String, String> valueMap = new HashMap<>();
+               testedObject.put(valueMap, MAP_KEY, false);
+               assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "false");
+       }
+
+       @Test
+       public void putNullBooleanValueToMap() {
+               Map<String, String> valueMap = new HashMap<>();
+               Boolean value = null;
+               testedObject.put(valueMap, MAP_KEY, value);
+               assertThat(valueMap).hasSize(1).containsEntry(MAP_KEY, "null");
+       }
 
-       
        @Test
-       public void catalogQuerySetTemplateImpl_Test(){
-               CatalogQuery mockCatalogQuery = Mockito.mock(CatalogQuery.class);
-               Mockito.doCallRealMethod().when(mockCatalogQuery).setTemplate(Mockito.anyString(), Mockito.anyMapOf(String.class, String.class));
-               
-               Map<String,String> valueMap = new HashMap<>();
-               valueMap.put("somekey", "somevalue");
-               
-               String ret = mockCatalogQuery.setTemplate("<somekey>", valueMap);
-               
-               assertTrue(ret.equalsIgnoreCase("somevalue"));
-       }
-       
+       public void setTemplate_keyFindInMap() {
+               Map<String, String> valueMap = new HashMap<>();
+               valueMap.put(MAP_KEY, VALUE_MAP);
+               String template = "<keyTest>";
+               String result = testedObject.setTemplate(template, valueMap);
+               assertThat(result).isEqualTo(VALUE_MAP);
+       }
+
+       @Test
+       public void setTemplate_keyNotFindInMap() {
+               Map<String, String> valueMap = new HashMap<>();
+               String template = "<keyTest>";
+               String result = testedObject.setTemplate(template, valueMap);
+               assertThat(result).isEqualTo("\"TBD\"");
+       }
+
+       @Test
+       public void setTemplate_templateDoesNotMatch() {
+               Map<String, String> valueMap = new HashMap<>();
+               String template = "key";
+               String result = testedObject.setTemplate(template, valueMap);
+               assertThat(result).isEqualTo("key");
+       }
+
+       @Test
+       public void smartToJson(){
+               String expectedResult = "{\"s\":\"s1\"}";
+               assertThat(testedObject.smartToJSON()).isEqualTo(expectedResult);
+       }
+
+       @Test
+       public void toJsonString_withVersion1() {
+               String expectedResult = "{\"s\":\"s1\"}";
+               assertThat(testedObject.toJsonString("v1",true)).isEqualTo(expectedResult);
+       }
+
        @Test
-       public void smartToJson_Test()
-       {
-        List<VnfResourceCustomization> paramList = new ArrayList<>();
-        VnfResourceCustomization d1 = new VnfResourceCustomization();
-        d1.setModelCustomizationUuid("16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
-        d1.setModelInstanceName("RG_6-26_mog11 0");
-        d1.setVersion("v1");
-        paramList.add(d1);
-        
-        QueryServiceVnfs qryResp = new QueryServiceVnfs(paramList);
-        QueryServiceVnfs mockCatalogQuery = Mockito.spy(qryResp);
-        Mockito.doCallRealMethod().when(mockCatalogQuery).smartToJSON();
-               String ret = qryResp.smartToJSON();
-               // System.out.println(ret);
-               
-        JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", "")));
-        JsonObject respObj = reader.readObject();
-        reader.close();
-        JsonArray jArray = respObj.getJsonArray("serviceVnfs");
-               assertEquals(jArray.size(), 1);
-               assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
-       }       
-       
+       public void toJsonString_withVersion2() {
+               assertThat(testedObject.toJsonString("v2",true)).isEqualTo("json2");
+       }
+
        @Test
-       public void toJsonString_Test()
-       {
-               CatalogQueryExtendedTest mockCatalogQuery = Mockito.mock(CatalogQueryExtendedTest.class);
-               Mockito.doCallRealMethod().when(mockCatalogQuery).JSON2(Mockito.anyBoolean(), Mockito.anyBoolean());
-               String ret = mockCatalogQuery.JSON2(true, true);
-               
-               // System.out.println(ret);
-               
-        JsonReader reader = Json.createReader(new StringReader(ret.replaceAll("\r?\n", "")));
-        JsonObject respObj = reader.readObject();
-        reader.close();
-        JsonArray jArray = respObj.getJsonArray("serviceVnfs");
-               assertEquals(jArray.size(), 1);
-               assertEquals(jArray.getJsonObject(0).getString("modelCustomizationUuid"), "16ea3e56-a8ce-4ad7-8edd-4d2eae095391");
-               assertEquals(jArray.getJsonObject(0).getString("version"), "v2");
-       }       
-       
-       class CatalogQueryExtendedTest extends CatalogQuery{
+       public void toJsonString_withInvalidVersion() {
+               assertThat(testedObject.toJsonString("ver77",true)).isEqualTo("invalid version: ver77");
+       }
+
+       private class CatalogQueryForTesting extends CatalogQuery {
+
+               private String s = "s1";
+
+               public String getS() {
+                       return s;
+               }
+
                @Override
                public String JSON2(boolean isArray, boolean isEmbed) {
-                       return "{\"serviceVnfs\":[{\"version\":\"v2\",\"modelCustomizationUuid\":\"16ea3e56-a8ce-4ad7-8edd-4d2eae095391\",\"modelInstanceName\":\"ciVFOnboarded-FNAT-aab06c41 1\",\"created\":null,\"vnfResourceModelUuid\":null,\"vnfResourceModelUUID\":null,\"minInstances\":null,\"maxInstances\":null,\"availabilityZoneMaxCount\":null,\"vnfResource\":null,\"nfFunction\":null,\"nfType\":null,\"nfRole\":null,\"nfNamingCode\":null,\"multiStageDesign\":null,\"vfModuleCustomizations\":null,\"serviceResourceCustomizations\":null,\"creationTimestamp\":null}]}";
+                       return "json2";
                }
-               
-       }       
-       
+       }
+
 }
 
 
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipeTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipeTest.java
new file mode 100644 (file)
index 0000000..fa1a1fc
--- /dev/null
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.catalogdb.catalogrest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.mso.db.catalog.beans.Recipe;
+import org.openecomp.mso.jsonpath.JsonPathUtil;
+
+public class QueryResourceRecipeTest {
+
+    private static final int RECIPE_ID = 123;
+    private static final String RECIPE_ACTION = "actionTest";
+    private static final String RECIPE_URI = "uriTest";
+    private static final int RECIPE_TIMEOUT = 100;
+    private static final String RECIPE_PARAMS_XSD = "paramsXsdTest";
+    private static final String RECIPE_DESCRIPTION = "descrTest";
+
+    private QueryResourceRecipe testedObject;
+
+    @Before
+    public void init() {
+        testedObject = new QueryResourceRecipe(createRecipe());
+    }
+
+    @Test
+    public void convertingToJsonSuccessful() {
+        String jsonResult = testedObject.JSON2(true, true);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.id")).contains(String.valueOf(RECIPE_ID));
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.action")).contains(RECIPE_ACTION);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.orchestrationUri")).contains(RECIPE_URI);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.recipeTimeout"))
+                .contains(String.valueOf(RECIPE_TIMEOUT));
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.paramXSD")).contains(RECIPE_PARAMS_XSD);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.description")).contains(RECIPE_DESCRIPTION);
+    }
+
+    @Test
+    public void toString_properContent() {
+        assertThat(testedObject.toString()).contains("RECIPE: actionTest,uri=uriTest");
+    }
+
+    private Recipe createRecipe() {
+        Recipe recipe = new Recipe();
+        recipe.setId(RECIPE_ID);
+        recipe.setAction(RECIPE_ACTION);
+        recipe.setOrchestrationUri(RECIPE_URI);
+        recipe.setRecipeTimeout(RECIPE_TIMEOUT);
+        recipe.setParamXSD(RECIPE_PARAMS_XSD);
+        recipe.setDescription(RECIPE_DESCRIPTION);
+        return recipe;
+    }
+
+}
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceCsarTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceCsarTest.java
new file mode 100644 (file)
index 0000000..e9c947d
--- /dev/null
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.catalogdb.catalogrest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.mso.db.catalog.beans.ToscaCsar;
+import org.openecomp.mso.jsonpath.JsonPathUtil;
+
+public class QueryServiceCsarTest {
+
+    private static final String TOSCA_ARTIFACT_UUID = "artUuidTest";
+    private static final String TOSCA_NAME = "toscaNameTest";
+    private static final String TOSCA_VERSION = "v12";
+    private static final String TOSCA_ARTIFACT_CHECKSUM = "tosArtCheck";
+    private static final String TOSCA_URL = "tosUrl";
+    private static final String TOSCA_DESCRIPTION = "toscaDescr";
+
+    private QueryServiceCsar testedObject;
+
+    @Before
+    public void init() {
+        testedObject = new QueryServiceCsar(createToscaCsar());
+    }
+
+    @Test
+    public void convertToJson_successful() {
+        String jsonResult = testedObject.JSON2(true, true);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.artifactUUID")).contains(TOSCA_ARTIFACT_UUID);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.name")).contains(TOSCA_NAME);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.version")).contains(TOSCA_VERSION);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.artifactChecksum"))
+                .contains(String.valueOf(TOSCA_ARTIFACT_CHECKSUM));
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.url")).contains(TOSCA_URL);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.description")).contains(TOSCA_DESCRIPTION);
+    }
+
+    @Test
+    public void toString_properContent() {
+        assertThat(testedObject.toString()).contains(
+                "TOSCACSAR: artifactUUID=artUuidTest,name=toscaNameTest,version=v12,description=toscaDescr,artifactChecksum=tosArtCheck,url=tosUrl");
+    }
+
+    private ToscaCsar createToscaCsar() {
+        ToscaCsar toscaCsar = new ToscaCsar();
+        toscaCsar.setArtifactUUID(TOSCA_ARTIFACT_UUID);
+        toscaCsar.setName(TOSCA_NAME);
+        toscaCsar.setVersion(TOSCA_VERSION);
+        toscaCsar.setArtifactChecksum(TOSCA_ARTIFACT_CHECKSUM);
+        toscaCsar.setUrl(TOSCA_URL);
+        toscaCsar.setDescription(TOSCA_DESCRIPTION);
+        return toscaCsar;
+    }
+
+}
diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModuleTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryVfModuleTest.java
new file mode 100644 (file)
index 0000000..b00b5b7
--- /dev/null
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.catalogdb.catalogrest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.openecomp.mso.db.catalog.beans.VfModule;
+import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
+import org.openecomp.mso.jsonpath.JsonPathUtil;
+
+public class QueryVfModuleTest {
+
+    private static final String VF_MODULE_MODEL_NAME = "vfModelNameTest";
+    private static final String VF_MODEL_UUID = "vfModelUuidTest";
+    private static final String VF_MODULE_INVARIANT_UUID = "vfModuleInvUuid";
+    private static final String VF_MODULE_VERSION = "vfModuleVerTest";
+
+    private static final String VF_MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid";
+    private static final String VF_MODEL_CUSTOMIZATION_LABEL = "modelCustomizationLabel";
+    private static final int VF_MODEL_CUSTOMIZATION_INITIAL_COUNT = 1;
+
+    @Test
+    public void convertToJson_successful() {
+        QueryVfModule testedObject = new QueryVfModule(createList());
+        String jsonResult = testedObject.JSON2(true, false);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].modelInfo.modelName"))
+                .contains(VF_MODULE_MODEL_NAME);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].modelInfo.modelUuid"))
+                .contains(VF_MODEL_UUID);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].modelInfo.modelInvariantUuid"))
+                .contains(VF_MODULE_INVARIANT_UUID);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].isBase"))
+                .contains("true");
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].vfModuleLabel"))
+                .contains(VF_MODEL_CUSTOMIZATION_LABEL);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].initialCount"))
+                .contains(String.valueOf(VF_MODEL_CUSTOMIZATION_INITIAL_COUNT));
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].hasVolumeGroup"))
+                .contains("false");
+    }
+
+    @Test
+    public void convertToJson_successful_hasVolumeGroupIsTrue() {
+        QueryVfModule testedObject = new QueryVfModule(createListWithHeatEnvironmentArtifactUuid());
+        String jsonResult = testedObject.JSON2(true, false);
+        assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].hasVolumeGroup"))
+                .contains("true");
+    }
+
+    private List<VfModuleCustomization> createList() {
+        List<VfModuleCustomization> list = new ArrayList<>();
+
+        VfModule vfModule = new VfModule();
+        vfModule.setModelName(VF_MODULE_MODEL_NAME);
+        vfModule.setModelUUID(VF_MODEL_UUID);
+        vfModule.setModelInvariantUuid(VF_MODULE_INVARIANT_UUID);
+        vfModule.setVersion(VF_MODULE_VERSION);
+        vfModule.setIsBase(1);
+
+        VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
+        vfModuleCustomization.setVfModule(vfModule);
+        vfModuleCustomization.setModelCustomizationUuid(VF_MODEL_CUSTOMIZATION_UUID);
+        vfModuleCustomization.setLabel(VF_MODEL_CUSTOMIZATION_LABEL);
+        vfModuleCustomization.setInitialCount(VF_MODEL_CUSTOMIZATION_INITIAL_COUNT);
+        list.add(vfModuleCustomization);
+        return list;
+    }
+
+    private List<VfModuleCustomization> createListWithHeatEnvironmentArtifactUuid() {
+        List<VfModuleCustomization> list = createList();
+        list.get(0).setHeatEnvironmentArtifactUuid("heatEnvTest");
+        return list;
+    }
+
+}