2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.adapters.catalogdb.catalogrest;
23 import static org.assertj.core.api.Assertions.assertThat;
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;
32 public class QueryVfModuleTest {
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";
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;
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"))
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"))
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"))
71 private List<VfModuleCustomization> createList() {
72 List<VfModuleCustomization> list = new ArrayList<>();
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);
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);
90 private List<VfModuleCustomization> createListWithHeatEnvironmentArtifactUuid() {
91 List<VfModuleCustomization> list = createList();
92 list.get(0).setHeatEnvironmentArtifactUuid("heatEnvTest");