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;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
32 import java.util.Optional;
34 import static org.junit.Assert.assertEquals;
38 * @since December 21, 2016.
40 public class ContrailTranslationHelperTest {
43 public void testgetComputeNodeTypeId()
45 Resource serviceTemplate = new Resource();
46 serviceTemplate.setProperties(new HashMap<>());
47 serviceTemplate.getProperties().put("image_name", "aaaa");
48 Map flavor = new HashMap<>();
49 flavor.put("get_param", "bbb_flavor_name");
50 serviceTemplate.getProperties().put("flavor", flavor);
51 String computeNodeTypeId =
52 new ContrailTranslationHelper()
53 .getComputeNodeTypeId(serviceTemplate, "123", "123", new TranslationContext());
54 Assert.assertEquals("org.openecomp.resource.vfc.nodes.heat.bbb", computeNodeTypeId);
58 public void testTranslateFnSplitFunctionExp1() {
59 // property value = { "Fn::Split" : [ ",", "management,left,right,other" ] }
60 Map propertyValue = new HashMap();
61 List funcListVal = new ArrayList<>();
63 funcListVal.add("management,left,right,other");
64 propertyValue.put("Fn::Split", funcListVal);
65 Optional<List<Map<String, List>>> translatedFun =
66 new ContrailTranslationHelper().translateFnSplitFunction(propertyValue, 4, false);
68 assertEquals(true, translatedFun.isPresent());
69 if (translatedFun.isPresent()) {
70 assertEquals(4, translatedFun.get().size());
71 for (int i = 0; i < translatedFun.get().size(); i++) {
72 assertEquals("management,left,right,other", translatedFun.get().get(i).get("token").get(0));
73 assertEquals(",", translatedFun.get().get(i).get("token").get(1));
74 assertEquals(i, translatedFun.get().get(i).get("token").get(2));
80 public void testTranslateFnSplitFunctionBoolean() {
81 // property value = { "Fn::Split" : [ ";", "n;false;false;false" ] }
82 Map propertyValue = new HashMap();
83 List funcListVal = new ArrayList<>();
85 funcListVal.add("n;false;false;false");
86 propertyValue.put("Fn::Split", funcListVal);
87 Optional<List<Map<String, List>>> translatedFun =
88 new ContrailTranslationHelper().translateFnSplitFunction(propertyValue, 4, true);
90 assertEquals(true, translatedFun.isPresent());
91 if (translatedFun.isPresent()) {
92 assertEquals(4, translatedFun.get().size());
93 for (int i = 0; i < translatedFun.get().size(); i++) {
94 assertEquals("false;false;false;false", translatedFun.get().get(i).get("token").get(0));
95 assertEquals(";", translatedFun.get().get(i).get("token").get(1));
96 assertEquals(i, translatedFun.get().get(i).get("token").get(2));
102 public void testTranslateFnSplitFunctionExp2() {
103 // property value = { "Fn::Split" : [ ";", "n;false;false;false" ] }
104 Map propertyValue = new HashMap();
105 List funcListVal = new ArrayList<>();
106 funcListVal.add(";");
107 funcListVal.add("n;false;false;false");
108 propertyValue.put("Fn::Split", funcListVal);
109 Optional<List<Map<String, List>>> translatedFun =
110 new ContrailTranslationHelper().translateFnSplitFunction(propertyValue, 4, false);
112 assertEquals(true, translatedFun.isPresent());
113 if (translatedFun.isPresent()) {
114 assertEquals(4, translatedFun.get().size());
115 for (int i = 0; i < translatedFun.get().size(); i++) {
116 assertEquals("n;false;false;false", translatedFun.get().get(i).get("token").get(0));
117 assertEquals(";", translatedFun.get().get(i).get("token").get(1));
118 assertEquals(i, translatedFun.get().get(i).get("token").get(2));
124 public void testTranslateFnSplitFunctionWithParam() {
125 // property value = { "Fn::Split" : [ ",", Ref: st_shared_ip_list ] }
126 Map propertyValue = new HashMap();
127 List funcListVal = new ArrayList<>();
128 funcListVal.add(",");
129 Map innerMap = new HashMap();
130 innerMap.put("Ref", "st_shared_ip_list");
131 funcListVal.add(innerMap);
132 propertyValue.put("Fn::Split", funcListVal);
133 Optional<List<Map<String, List>>> translatedFun =
134 new ContrailTranslationHelper().translateFnSplitFunction(propertyValue, 5, false);
136 assertEquals(true, translatedFun.isPresent());
137 if (translatedFun.isPresent()) {
138 assertEquals(5, translatedFun.get().size());
139 for (int i = 0; i < translatedFun.get().size(); i++) {
140 assertEquals("st_shared_ip_list",
142 ((Map) translatedFun.get().get(i).get("token").get(0)).get("get_input"));
143 assertEquals(",", translatedFun.get().get(i).get("token").get(1));
144 assertEquals(i, translatedFun.get().get(i).get("token").get(2));