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.openecomp.sdc.translator.services.heattotosca.helper;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.openecomp.sdc.heat.datatypes.model.Resource;
26 import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
30 import static org.junit.Assert.assertEquals;
34 * @since December 21, 2016.
36 public class ContrailTranslationHelperTest {
39 public void testgetComputeNodeTypeId()
41 Resource serviceTemplate = new Resource();
42 serviceTemplate.setProperties(new HashMap<>());
43 serviceTemplate.getProperties().put("image_name", "aaaa");
44 Map flavor = new HashMap<>();
45 flavor.put("get_param", "bbb_flavor_name");
46 serviceTemplate.getProperties().put("flavor", flavor);
47 String computeNodeTypeId =
48 new ContrailTranslationHelper()
49 .getComputeNodeTypeId(serviceTemplate, "123", "123", new TranslationContext());
50 Assert.assertEquals("org.openecomp.resource.vfc.nodes.heat.bbb", computeNodeTypeId);
54 public void testTranslateFnSplitFunctionExp1() {
55 // property value = { "Fn::Split" : [ ",", "management,left,right,other" ] }
56 Map propertyValue = new HashMap();
57 List funcListVal = new ArrayList();
59 funcListVal.add("management,left,right,other");
60 propertyValue.put("Fn::Split", funcListVal);
61 Optional<List<Map<String, List>>> translatedFun =
62 new ContrailTranslationHelper().translateFnSplitFunction(propertyValue, 4, false);
64 assertEquals(true, translatedFun.isPresent());
65 if (translatedFun.isPresent()) {
66 assertEquals(4, translatedFun.get().size());
67 for (int i = 0; i < translatedFun.get().size(); i++) {
68 assertEquals("management,left,right,other", translatedFun.get().get(i).get("token").get(0));
69 assertEquals(",", translatedFun.get().get(i).get("token").get(1));
70 assertEquals(i, translatedFun.get().get(i).get("token").get(2));
76 public void testTranslateFnSplitFunctionBoolean() {
77 // property value = { "Fn::Split" : [ ";", "n;false;false;false" ] }
78 Map propertyValue = new HashMap();
79 List funcListVal = new ArrayList<>();
81 funcListVal.add("n;false;false;false");
82 propertyValue.put("Fn::Split", funcListVal);
83 Optional<List<Map<String, List>>> translatedFun =
84 new ContrailTranslationHelper().translateFnSplitFunction(propertyValue, 4, true);
86 assertEquals(true, translatedFun.isPresent());
87 if (translatedFun.isPresent()) {
88 assertEquals(4, translatedFun.get().size());
89 for (int i = 0; i < translatedFun.get().size(); i++) {
90 assertEquals("false;false;false;false", translatedFun.get().get(i).get("token").get(0));
91 assertEquals(";", translatedFun.get().get(i).get("token").get(1));
92 assertEquals(i, translatedFun.get().get(i).get("token").get(2));
98 public void testTranslateFnSplitFunctionExp2() {
99 // property value = { "Fn::Split" : [ ";", "n;false;false;false" ] }
100 Map propertyValue = new HashMap();
101 List funcListVal = new ArrayList<>();
102 funcListVal.add(";");
103 funcListVal.add("n;false;false;false");
104 propertyValue.put("Fn::Split", funcListVal);
105 Optional<List<Map<String, List>>> translatedFun =
106 new ContrailTranslationHelper().translateFnSplitFunction(propertyValue, 4, false);
108 assertEquals(true, translatedFun.isPresent());
109 if (translatedFun.isPresent()) {
110 assertEquals(4, translatedFun.get().size());
111 for (int i = 0; i < translatedFun.get().size(); i++) {
112 assertEquals("n;false;false;false", translatedFun.get().get(i).get("token").get(0));
113 assertEquals(";", translatedFun.get().get(i).get("token").get(1));
114 assertEquals(i, translatedFun.get().get(i).get("token").get(2));
120 public void testTranslateFnSplitFunctionWithParam() {
121 // property value = { "Fn::Split" : [ ",", Ref: st_shared_ip_list ] }
122 Map propertyValue = new HashMap();
123 List funcListVal = new ArrayList<>();
124 funcListVal.add(",");
125 Map innerMap = new HashMap();
126 innerMap.put("Ref", "st_shared_ip_list");
127 funcListVal.add(innerMap);
128 propertyValue.put("Fn::Split", funcListVal);
129 Optional<List<Map<String, List>>> translatedFun =
130 new ContrailTranslationHelper().translateFnSplitFunction(propertyValue, 5, false);
132 assertEquals(true, translatedFun.isPresent());
133 if (translatedFun.isPresent()) {
134 assertEquals(5, translatedFun.get().size());
135 for (int i = 0; i < translatedFun.get().size(); i++) {
136 assertEquals("st_shared_ip_list",
138 ((Map) translatedFun.get().get(i).get("token").get(0)).get("get_input"));
139 assertEquals(",", translatedFun.get().get(i).get("token").get(1));
140 assertEquals(i, translatedFun.get().get(i).get("token").get(2));