2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.be.plugins.etsi.nfv.nsd.tosca.yaml;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.core.Is.is;
25 import com.google.common.collect.ImmutableList;
26 import com.google.common.collect.ImmutableMap;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.List;
31 import org.junit.jupiter.api.Test;
32 import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
33 import org.openecomp.sdc.be.tosca.model.ToscaProperty;
34 import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintValidValues;
35 import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
37 class ToscaTemplateYamlGeneratorTest {
40 void testGenerateYamlWithImportsKey() {
42 final ToscaTemplate toscaTemplate = new ToscaTemplate("tosca_simple_yaml_1_1");
43 final List<Map<String, Map<String, String>>> importList =
45 ImmutableMap.of("etsi_nfv_sol001_nsd_2_7_1_types",
46 ImmutableMap.of("file", "etsi_nfv_sol001_nsd_2_7_1_types.yaml")
48 ImmutableMap.of("anotherImport",
49 ImmutableMap.of("file", "anotherImport.yaml")
52 toscaTemplate.setImports(importList);
53 final ToscaTemplateYamlGenerator toscaTemplateYamlGenerator = new ToscaTemplateYamlGenerator(toscaTemplate);
55 final String toscaTemplateYamlString = toscaTemplateYamlGenerator.parseToYamlString();
58 final String expectedImports = "imports:\n"
59 + "- file: etsi_nfv_sol001_nsd_2_7_1_types.yaml\n"
60 + "- file: anotherImport.yaml";
61 assertThat("Imports format should be as expected", toscaTemplateYamlString.contains(expectedImports), is(true));
65 void testGenerateYamlWithToscaProperty() {
67 final ToscaTemplate toscaTemplate = new ToscaTemplate("tosca_simple_yaml_1_1");
69 final Map<String, ToscaProperty> toscaPropertyMap = new HashMap<>();
70 final ToscaProperty toscaProperty = new ToscaProperty();
71 final String defaultpValue = "defaultpValue";
72 toscaProperty.setDefaultp(defaultpValue);
73 ToscaPropertyConstraintValidValues toscaPropertyConstraintValidValues =
74 new ToscaPropertyConstraintValidValues(Collections.singletonList(defaultpValue));
75 toscaProperty.setConstraints(Collections.singletonList(toscaPropertyConstraintValidValues));
76 final String propertyName = "aProperty";
77 toscaPropertyMap.put(propertyName, toscaProperty);
79 final Map<String, ToscaNodeType> toscaNodeMap = new HashMap<>();
80 final ToscaNodeType toscaNodeType = new ToscaNodeType();
81 toscaNodeType.setProperties(toscaPropertyMap);
82 toscaNodeMap.put("aNode", toscaNodeType);
83 toscaTemplate.setNode_types(toscaNodeMap);
84 final ToscaTemplateYamlGenerator toscaTemplateYamlGenerator = new ToscaTemplateYamlGenerator(toscaTemplate);
86 final String toscaTemplateYamlString = toscaTemplateYamlGenerator.parseToYamlString();
88 final String expectedProperty = String.format("%s:\n"
91 + " - valid_values:\n"
93 propertyName, defaultpValue, defaultpValue);
95 assertThat("Property format should be as expected",
96 toscaTemplateYamlString.contains(expectedProperty), is(true));