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;
25 import java.util.ArrayList;
26 import java.util.List;
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;
34 public class QueryVfModuleTest {
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";
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;
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"))
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"))
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"))
73 private List<VfModuleCustomization> createList() {
74 List<VfModuleCustomization> list = new ArrayList<>();
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);
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);
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);