2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia
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.vdu.mapper;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import com.google.common.collect.Lists;
25 import java.util.List;
26 import org.junit.Test;
27 import org.onap.so.adapters.vdu.VduArtifact;
28 import org.onap.so.adapters.vdu.VduArtifact.ArtifactType;
29 import org.onap.so.adapters.vdu.VduModelInfo;
30 import org.onap.so.db.catalog.beans.HeatEnvironment;
31 import org.onap.so.db.catalog.beans.HeatFiles;
32 import org.onap.so.db.catalog.beans.HeatTemplate;
33 import org.onap.so.db.catalog.beans.VfModule;
34 import org.onap.so.db.catalog.beans.VfModuleCustomization;
36 public class VfModuleCustomizationToVduMapperTest {
38 private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUUID";
39 private static final String HEAT_ENV_NAME = "heatEnvName";
40 private static final String HEAT_ENV_CONTENT = "heatEnvContent";
41 private static final String MODULE_HEAT_TEMPLATE_NAME = "moduleHeatTemplateName";
42 private static final String MODULE_HEAT_TEMPLATE_BODY = "moduleHeatTemplateBody";
43 private static final String NESTED_TEMPLATE_NAME = "nestedTemplateName";
44 private static final String NESTED_TEMPLATE_BODY = "nestedTemplateBody";
45 private static final int TIMEOUT_IN_MIN = 66;
46 private static final String VF_MODULE_MODEL_INVARIANT_UUID = "vfModuleModelInvariantUUID";
47 private static final String CLOUD_FILE_NAME = "cloudFileName";
48 private static final String CLOUD_FILE_BODY = "cloudFileBody";
52 public void mapVfModuleCustomizationToVdu_successful() {
54 VfModuleCustomization vfModuleCustomization = createVfModuleCustomization();
55 vfModuleCustomization.setHeatEnvironment(createHeatEnvironment(HEAT_ENV_NAME, HEAT_ENV_CONTENT));
56 VfModule vfModule = createVfModule();
57 vfModule.setModuleHeatTemplate(createHeatTemplate(MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY,
58 NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY));
59 vfModuleCustomization.setVfModule(vfModule);
62 VduModelInfo vduModelInfo =
63 new VfModuleCustomizationToVduMapper().mapVfModuleCustomizationToVdu(vfModuleCustomization);
66 assertThat(vduModelInfo.getModelCustomizationUUID()).isEqualTo(MODEL_CUSTOMIZATION_UUID);
67 assertThat(vduModelInfo.getTimeoutMinutes()).isEqualTo(TIMEOUT_IN_MIN);
68 assertThat(vduModelInfo.getArtifacts()).containsExactlyElementsOf(createExpectedVduArtifacts());
72 public void mapVfModuleCustVolumeToVdu_successful() {
74 VfModuleCustomization vfModuleCustomization = createVfModuleCustomization();
75 vfModuleCustomization.setVolumeHeatEnv(createHeatEnvironment(HEAT_ENV_NAME, HEAT_ENV_CONTENT));
76 VfModule vfModule = createVfModule();
77 vfModule.setVolumeHeatTemplate(createHeatTemplate(MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY,
78 NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY));
79 vfModuleCustomization.setVfModule(vfModule);
82 VduModelInfo vduModelInfo =
83 new VfModuleCustomizationToVduMapper().mapVfModuleCustVolumeToVdu(vfModuleCustomization);
86 assertThat(vduModelInfo.getModelCustomizationUUID()).isEqualTo(MODEL_CUSTOMIZATION_UUID);
87 assertThat(vduModelInfo.getTimeoutMinutes()).isEqualTo(TIMEOUT_IN_MIN);
88 assertThat(vduModelInfo.getArtifacts()).containsExactlyElementsOf(createExpectedVduArtifacts());
91 private VfModuleCustomization createVfModuleCustomization() {
92 VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
93 vfModuleCustomization.setModelCustomizationUUID(MODEL_CUSTOMIZATION_UUID);
94 return vfModuleCustomization;
97 private HeatEnvironment createHeatEnvironment(String volHeatEnvName, String volHeatEnvContent) {
98 HeatEnvironment heatEnvironment = new HeatEnvironment();
99 heatEnvironment.setName(volHeatEnvName);
100 heatEnvironment.setEnvironment(volHeatEnvContent);
101 return heatEnvironment;
104 private VfModule createVfModule() {
105 VfModule vfModule = new VfModule();
106 vfModule.setModelInvariantUUID(VF_MODULE_MODEL_INVARIANT_UUID);
107 vfModule.setHeatFiles(createHeatFiles(CLOUD_FILE_NAME, CLOUD_FILE_BODY));
111 private List<HeatFiles> createHeatFiles(String fileName, String fileBody) {
112 HeatFiles heatFiles = new HeatFiles();
113 heatFiles.setFileName(fileName);
114 heatFiles.setFileBody(fileBody);
115 return Lists.newArrayList(heatFiles);
118 private HeatTemplate createHeatTemplate(String moduleHeatTemplateName, String moduleHeatTemplateBody,
119 String childTemplateName, String childTemplateBody) {
120 HeatTemplate heatTemplate = new HeatTemplate();
121 heatTemplate.setTemplateName(moduleHeatTemplateName);
122 heatTemplate.setTemplateBody(moduleHeatTemplateBody);
123 heatTemplate.setTimeoutMinutes(TIMEOUT_IN_MIN);
124 heatTemplate.setChildTemplates(createChildHeatTemplate(childTemplateName, childTemplateBody));
128 private List<HeatTemplate> createChildHeatTemplate(String moduleHeatTemplateName, String moduleHeatTemplateBody) {
129 HeatTemplate heatTemplate = new HeatTemplate();
130 heatTemplate.setTemplateName(moduleHeatTemplateName);
131 heatTemplate.setTemplateBody(moduleHeatTemplateBody);
132 return Lists.newArrayList(heatTemplate);
135 private List<VduArtifact> createExpectedVduArtifacts() {
136 return Lists.newArrayList(
137 new VduArtifact(MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY.getBytes(),
138 ArtifactType.MAIN_TEMPLATE),
139 new VduArtifact(NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY.getBytes(), ArtifactType.NESTED_TEMPLATE),
140 new VduArtifact(CLOUD_FILE_NAME, CLOUD_FILE_BODY.getBytes(), ArtifactType.TEXT_FILE),
141 new VduArtifact(HEAT_ENV_NAME, HEAT_ENV_CONTENT.getBytes(), ArtifactType.ENVIRONMENT));