Merge "Reorder modifiers"
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / openecomp / mso / 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.openecomp.mso.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 import org.junit.Test;
28 import org.openecomp.mso.db.catalog.beans.VfModule;
29 import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
30 import org.openecomp.mso.jsonpath.JsonPathUtil;
31
32 public class QueryVfModuleTest {
33
34     private static final String VF_MODULE_MODEL_NAME = "vfModelNameTest";
35     private static final String VF_MODEL_UUID = "vfModelUuidTest";
36     private static final String VF_MODULE_INVARIANT_UUID = "vfModuleInvUuid";
37     private static final String VF_MODULE_VERSION = "vfModuleVerTest";
38
39     private static final String VF_MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid";
40     private static final String VF_MODEL_CUSTOMIZATION_LABEL = "modelCustomizationLabel";
41     private static final int VF_MODEL_CUSTOMIZATION_INITIAL_COUNT = 1;
42
43     @Test
44     public void convertToJson_successful() {
45         QueryVfModule testedObject = new QueryVfModule(createList());
46         String jsonResult = testedObject.JSON2(true, false);
47         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].modelInfo.modelName"))
48                 .contains(VF_MODULE_MODEL_NAME);
49         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].modelInfo.modelUuid"))
50                 .contains(VF_MODEL_UUID);
51         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].modelInfo.modelInvariantUuid"))
52                 .contains(VF_MODULE_INVARIANT_UUID);
53         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].isBase"))
54                 .contains("true");
55         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].vfModuleLabel"))
56                 .contains(VF_MODEL_CUSTOMIZATION_LABEL);
57         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].initialCount"))
58                 .contains(String.valueOf(VF_MODEL_CUSTOMIZATION_INITIAL_COUNT));
59         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].hasVolumeGroup"))
60                 .contains("false");
61     }
62
63     @Test
64     public void convertToJson_successful_hasVolumeGroupIsTrue() {
65         QueryVfModule testedObject = new QueryVfModule(createListWithHeatEnvironmentArtifactUuid());
66         String jsonResult = testedObject.JSON2(true, false);
67         assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].hasVolumeGroup"))
68                 .contains("true");
69     }
70
71     private List<VfModuleCustomization> createList() {
72         List<VfModuleCustomization> list = new ArrayList<>();
73
74         VfModule vfModule = new VfModule();
75         vfModule.setModelName(VF_MODULE_MODEL_NAME);
76         vfModule.setModelUUID(VF_MODEL_UUID);
77         vfModule.setModelInvariantUuid(VF_MODULE_INVARIANT_UUID);
78         vfModule.setVersion(VF_MODULE_VERSION);
79         vfModule.setIsBase(1);
80
81         VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
82         vfModuleCustomization.setVfModule(vfModule);
83         vfModuleCustomization.setModelCustomizationUuid(VF_MODEL_CUSTOMIZATION_UUID);
84         vfModuleCustomization.setLabel(VF_MODEL_CUSTOMIZATION_LABEL);
85         vfModuleCustomization.setInitialCount(VF_MODEL_CUSTOMIZATION_INITIAL_COUNT);
86         list.add(vfModuleCustomization);
87         return list;
88     }
89
90     private List<VfModuleCustomization> createListWithHeatEnvironmentArtifactUuid() {
91         List<VfModuleCustomization> list = createList();
92         list.get(0).setHeatEnvironmentArtifactUuid("heatEnvTest");
93         return list;
94     }
95
96 }