98e90c828c27785b9afc9261fa4122c4ef8f323d
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / onap / so / adapters / catalogdb / catalogrest / QueryVfModuleTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.catalogdb.catalogrest;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.junit.Test;
29 import org.onap.so.db.catalog.beans.HeatEnvironment;
30 import org.onap.so.db.catalog.beans.VfModule;
31 import org.onap.so.db.catalog.beans.VfModuleCustomization;
32 import org.onap.so.jsonpath.JsonPathUtil;
33
34 public class QueryVfModuleTest {
35
36     private static final String VF_MODULE_MODEL_NAME = "vfModelNameTest";
37     private static final String VF_MODEL_UUID = "vfModelUuidTest";
38     private static final String VF_MODULE_INVARIANT_UUID = "vfModuleInvUuid";
39     private static final String VF_MODULE_VERSION = "vfModuleVerTest";
40
41     private static final String VF_MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid";
42     private static final String VF_MODEL_CUSTOMIZATION_LABEL = "modelCustomizationLabel";
43     private static final int VF_MODEL_CUSTOMIZATION_INITIAL_COUNT = 1;
44
45     @Test
46     public void convertToJson_successful() {
47         QueryVfModule testedObject = new QueryVfModule(createList());
48         String jsonResult = testedObject.JSON2(true, false);
49         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].modelInfo.modelName"))
50                 .contains(VF_MODULE_MODEL_NAME);
51         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].modelInfo.modelUuid"))
52                 .contains(VF_MODEL_UUID);
53         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].modelInfo.modelInvariantUuid"))
54                 .contains(VF_MODULE_INVARIANT_UUID);
55         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].isBase"))
56                 .contains("true");
57         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].vfModuleLabel"))
58                 .contains(VF_MODEL_CUSTOMIZATION_LABEL);
59         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].initialCount"))
60                 .contains(String.valueOf(VF_MODEL_CUSTOMIZATION_INITIAL_COUNT));
61         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].hasVolumeGroup"))
62                 .contains("false");
63     }
64
65     @Test
66     public void convertToJson_successful_hasVolumeGroupIsTrue() {
67         QueryVfModule testedObject = new QueryVfModule(createListWithHeatEnvironmentArtifactUuid());
68         String jsonResult = testedObject.JSON2(true, false);
69         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].hasVolumeGroup"))
70                 .contains("true");
71     }
72
73     private List<VfModuleCustomization> createList() {
74         List<VfModuleCustomization> list = new ArrayList<>();
75
76         VfModule vfModule = new VfModule();
77         vfModule.setModelName(VF_MODULE_MODEL_NAME);
78         vfModule.setModelUUID(VF_MODEL_UUID);
79         vfModule.setModelInvariantUUID(VF_MODULE_INVARIANT_UUID);
80         vfModule.setModelVersion(VF_MODULE_VERSION);
81         vfModule.setIsBase(true);
82
83         VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
84         vfModuleCustomization.setVfModule(vfModule);
85         vfModuleCustomization.setModelCustomizationUUID(VF_MODEL_CUSTOMIZATION_UUID);
86         vfModuleCustomization.setLabel(VF_MODEL_CUSTOMIZATION_LABEL);
87         vfModuleCustomization.setInitialCount(VF_MODEL_CUSTOMIZATION_INITIAL_COUNT);
88         list.add(vfModuleCustomization);
89         return list;
90     }
91
92     private List<VfModuleCustomization> createListWithHeatEnvironmentArtifactUuid() {
93         List<VfModuleCustomization> list = createList();
94         HeatEnvironment he = new HeatEnvironment();
95         he.setArtifactUuid("heatEnvTest");
96         list.get(0).setVolumeHeatEnv(he);
97         return list;
98     }
99
100 }