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.onap.so.adapters.catalogdb.catalogrest;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.junit.Test;
27 import org.onap.so.db.catalog.beans.HeatEnvironment;
28 import org.onap.so.db.catalog.beans.VfModule;
29 import org.onap.so.db.catalog.beans.VfModuleCustomization;
30 import org.onap.so.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")).contains("true");
54 assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].vfModuleLabel"))
55 .contains(VF_MODEL_CUSTOMIZATION_LABEL);
56 assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].initialCount"))
57 .contains(String.valueOf(VF_MODEL_CUSTOMIZATION_INITIAL_COUNT));
58 assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].hasVolumeGroup"))
63 public void convertToJson_successful_hasVolumeGroupIsTrue() {
64 QueryVfModule testedObject = new QueryVfModule(createListWithHeatEnvironmentArtifactUuid());
65 String jsonResult = testedObject.JSON2(true, false);
66 assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vfModules[0].hasVolumeGroup"))
70 private List<VfModuleCustomization> createList() {
71 List<VfModuleCustomization> list = new ArrayList<>();
73 VfModule vfModule = new VfModule();
74 vfModule.setModelName(VF_MODULE_MODEL_NAME);
75 vfModule.setModelUUID(VF_MODEL_UUID);
76 vfModule.setModelInvariantUUID(VF_MODULE_INVARIANT_UUID);
77 vfModule.setModelVersion(VF_MODULE_VERSION);
78 vfModule.setIsBase(true);
80 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
81 vfModuleCustomization.setVfModule(vfModule);
82 vfModuleCustomization.setModelCustomizationUUID(VF_MODEL_CUSTOMIZATION_UUID);
83 vfModuleCustomization.setLabel(VF_MODEL_CUSTOMIZATION_LABEL);
84 vfModuleCustomization.setInitialCount(VF_MODEL_CUSTOMIZATION_INITIAL_COUNT);
85 list.add(vfModuleCustomization);
89 private List<VfModuleCustomization> createListWithHeatEnvironmentArtifactUuid() {
90 List<VfModuleCustomization> list = createList();
91 HeatEnvironment he = new HeatEnvironment();
92 he.setArtifactUuid("heatEnvTest");
93 list.get(0).setVolumeHeatEnv(he);