c982f8beb174cad5a4e8f43e9cfde7e61a784522
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.onap.so.adapters.vdu.mapper;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24
25 import com.google.common.collect.Lists;
26 import java.util.List;
27 import org.junit.Test;
28 import org.onap.so.adapters.vdu.VduArtifact;
29 import org.onap.so.adapters.vdu.VduArtifact.ArtifactType;
30 import org.onap.so.adapters.vdu.VduModelInfo;
31 import org.onap.so.db.catalog.beans.HeatEnvironment;
32 import org.onap.so.db.catalog.beans.HeatFiles;
33 import org.onap.so.db.catalog.beans.HeatTemplate;
34 import org.onap.so.db.catalog.beans.VfModule;
35 import org.onap.so.db.catalog.beans.VfModuleCustomization;
36
37 public class VfModuleCustomizationToVduMapperTest {
38
39     private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUUID";
40     private static final String HEAT_ENV_NAME = "heatEnvName";
41     private static final String HEAT_ENV_CONTENT = "heatEnvContent";
42     private static final String MODULE_HEAT_TEMPLATE_NAME = "moduleHeatTemplateName";
43     private static final String MODULE_HEAT_TEMPLATE_BODY = "moduleHeatTemplateBody";
44     private static final String NESTED_TEMPLATE_NAME = "nestedTemplateName";
45     private static final String NESTED_TEMPLATE_BODY = "nestedTemplateBody";
46     private static final int TIMEOUT_IN_MIN = 66;
47     private static final String VF_MODULE_MODEL_INVARIANT_UUID = "vfModuleModelInvariantUUID";
48     private static final String CLOUD_FILE_NAME = "cloudFileName";
49     private static final String CLOUD_FILE_BODY = "cloudFileBody";
50
51
52     @Test
53     public void mapVfModuleCustomizationToVdu_successful() {
54         // GIVEN
55         VfModuleCustomization vfModuleCustomization = createVfModuleCustomization();
56         vfModuleCustomization.setHeatEnvironment(createHeatEnvironment(HEAT_ENV_NAME, HEAT_ENV_CONTENT));
57         VfModule vfModule = createVfModule();
58         vfModule.setModuleHeatTemplate(createHeatTemplate(
59             MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY,
60             NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY));
61         vfModuleCustomization.setVfModule(vfModule);
62
63         // WHEN
64         VduModelInfo vduModelInfo = new VfModuleCustomizationToVduMapper()
65             .mapVfModuleCustomizationToVdu(vfModuleCustomization);
66
67         // THEN
68         assertThat(vduModelInfo.getModelCustomizationUUID()).isEqualTo(MODEL_CUSTOMIZATION_UUID);
69         assertThat(vduModelInfo.getTimeoutMinutes()).isEqualTo(TIMEOUT_IN_MIN);
70         assertThat(vduModelInfo.getArtifacts()).containsExactlyElementsOf(createExpectedVduArtifacts());
71     }
72
73     @Test
74     public void mapVfModuleCustVolumeToVdu_successful() {
75         // GIVEN
76         VfModuleCustomization vfModuleCustomization = createVfModuleCustomization();
77         vfModuleCustomization.setVolumeHeatEnv(createHeatEnvironment(HEAT_ENV_NAME, HEAT_ENV_CONTENT));
78         VfModule vfModule = createVfModule();
79         vfModule.setVolumeHeatTemplate(createHeatTemplate(
80             MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY,
81             NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY));
82         vfModuleCustomization.setVfModule(vfModule);
83
84         // WHEN
85         VduModelInfo vduModelInfo = new VfModuleCustomizationToVduMapper()
86             .mapVfModuleCustVolumeToVdu(vfModuleCustomization);
87
88         // THEN
89         assertThat(vduModelInfo.getModelCustomizationUUID()).isEqualTo(MODEL_CUSTOMIZATION_UUID);
90         assertThat(vduModelInfo.getTimeoutMinutes()).isEqualTo(TIMEOUT_IN_MIN);
91         assertThat(vduModelInfo.getArtifacts()).containsExactlyElementsOf(createExpectedVduArtifacts());
92     }
93
94     private VfModuleCustomization createVfModuleCustomization() {
95         VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
96         vfModuleCustomization.setModelCustomizationUUID(MODEL_CUSTOMIZATION_UUID);
97         return vfModuleCustomization;
98     }
99
100     private HeatEnvironment createHeatEnvironment(String volHeatEnvName, String volHeatEnvContent) {
101         HeatEnvironment heatEnvironment = new HeatEnvironment();
102         heatEnvironment.setName(volHeatEnvName);
103         heatEnvironment.setEnvironment(volHeatEnvContent);
104         return heatEnvironment;
105     }
106
107     private VfModule createVfModule() {
108         VfModule vfModule = new VfModule();
109         vfModule.setModelInvariantUUID(VF_MODULE_MODEL_INVARIANT_UUID);
110         vfModule.setHeatFiles(createHeatFiles(CLOUD_FILE_NAME, CLOUD_FILE_BODY));
111         return vfModule;
112     }
113
114     private List<HeatFiles> createHeatFiles(String fileName, String fileBody) {
115         HeatFiles heatFiles = new HeatFiles();
116         heatFiles.setFileName(fileName);
117         heatFiles.setFileBody(fileBody);
118         return Lists.newArrayList(heatFiles);
119     }
120
121     private HeatTemplate createHeatTemplate(String moduleHeatTemplateName, String moduleHeatTemplateBody,
122         String childTemplateName, String childTemplateBody) {
123         HeatTemplate heatTemplate = new HeatTemplate();
124         heatTemplate.setTemplateName(moduleHeatTemplateName);
125         heatTemplate.setTemplateBody(moduleHeatTemplateBody);
126         heatTemplate.setTimeoutMinutes(TIMEOUT_IN_MIN);
127         heatTemplate.setChildTemplates(createChildHeatTemplate(childTemplateName, childTemplateBody));
128         return heatTemplate;
129     }
130
131     private List<HeatTemplate> createChildHeatTemplate(String moduleHeatTemplateName, String moduleHeatTemplateBody) {
132         HeatTemplate heatTemplate = new HeatTemplate();
133         heatTemplate.setTemplateName(moduleHeatTemplateName);
134         heatTemplate.setTemplateBody(moduleHeatTemplateBody);
135         return Lists.newArrayList(heatTemplate);
136     }
137
138     private List<VduArtifact> createExpectedVduArtifacts() {
139         return Lists.newArrayList(
140             new VduArtifact(MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY.getBytes(),
141                 ArtifactType.MAIN_TEMPLATE),
142             new VduArtifact(NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY.getBytes(), ArtifactType.NESTED_TEMPLATE),
143             new VduArtifact(CLOUD_FILE_NAME, CLOUD_FILE_BODY.getBytes(), ArtifactType.TEXT_FILE),
144             new VduArtifact(HEAT_ENV_NAME, HEAT_ENV_CONTENT.getBytes(), ArtifactType.ENVIRONMENT));
145     }
146 }