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.impl.nameextractor;
23 import org.junit.Test;
24 import org.openecomp.sdc.heat.datatypes.model.Resource;
25 import org.openecomp.sdc.translator.services.heattotosca.Constants;
26 import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.ResourceTranslationNovaServerImpl;
28 import java.util.Arrays;
29 import java.util.HashMap;
30 import java.util.List;
33 import static org.junit.Assert.assertTrue;
37 * @since December 20, 2016.
39 public class NameExtractorNovaServerImplTest {
41 public void shouldReturnNamePrefixIfPropertyNameMatchWithIndex() throws Exception {
42 Map<String, Object> propertiesMap = new HashMap();
43 propertiesMap.put("a", "sss");
44 HashMap imageMap = new HashMap();
45 String name = "avi_test_name_1";
46 imageMap.put("get_param", name);
47 propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
48 Resource resource = new Resource();
49 resource.setProperties(propertiesMap);
50 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
51 new ResourceTranslationNovaServerImpl();
52 String localNodeType =
53 new NameExtractorNovaServerImpl().extractNodeTypeName(resource, "Ignore", "Ignore");
54 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.avi_test"));
58 public void shouldReturnNamePrefixIfPropertyNameMatchWithListObjectInGetParamVal()
60 Map<String, Object> propertiesMap = new HashMap();
61 propertiesMap.put("a", "sss");
62 HashMap imageMap = new HashMap();
63 List val = Arrays.asList("virc_vm_names", "2");
64 imageMap.put("get_param", val);
65 propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
66 Resource resource = new Resource();
67 resource.setProperties(propertiesMap);
68 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
69 new ResourceTranslationNovaServerImpl();
70 String localNodeType =
71 new NameExtractorNovaServerImpl().extractNodeTypeName(resource, "Ignore", "Ignore");
72 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.virc_vm"));
76 public void shouldReturnNamePrefixIfPropertyNameMatchWithListObjectInGetParamValAndGetParamAsGetParamVal()
78 Map<String, Object> propertiesMap = new HashMap();
79 propertiesMap.put("a", "sss");
80 HashMap nameMap = new HashMap();
81 HashMap nameValMap = new HashMap();
82 nameValMap.put("get_param", "anyParam");
83 List val = Arrays.asList("virc_vm_names", nameValMap);
84 nameMap.put("get_param", val);
85 propertiesMap.put(Constants.NAME_PROPERTY_NAME, nameMap);
86 Resource resource = new Resource();
87 resource.setProperties(propertiesMap);
88 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
89 new ResourceTranslationNovaServerImpl();
90 String localNodeType =
91 new NameExtractorNovaServerImpl().extractNodeTypeName(resource, "Ignore", "Ignore");
92 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.virc_vm"));
97 public void shouldReturnNamePrefixIfPropertyNameMatchWithoutIndex() throws Exception {
98 Map<String, Object> propertiesMap = new HashMap();
99 propertiesMap.put("a", "sss");
100 HashMap imageMap = new HashMap();
101 String name = "avi_test_names";
102 imageMap.put("get_param", name);
103 propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
104 Resource resource = new Resource();
105 resource.setProperties(propertiesMap);
106 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
107 new ResourceTranslationNovaServerImpl();
108 String localNodeType =
109 new NameExtractorNovaServerImpl().extractNodeTypeName(resource, "Ignore", "Ignore");
110 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.avi_test"));
114 public void shouldReturnPrefixByPropertyOrder() throws Exception {
115 Map<String, Object> propertiesMap = new HashMap();
116 propertiesMap.put("a", "sss");
117 HashMap imageMap = new HashMap();
118 String name = "avi_test1_namesw";
119 imageMap.put("get_param", name);
120 propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
121 String flavor = "avi_test2_flavor_name";
122 imageMap = new HashMap();
123 imageMap.put("get_param", flavor);
124 propertiesMap.put("flavor", imageMap);
125 Resource resource = new Resource();
126 resource.setProperties(propertiesMap);
127 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
128 new ResourceTranslationNovaServerImpl();
129 String localNodeType =
130 new NameExtractorNovaServerImpl().extractNodeTypeName(resource, "Ignore", "Ignore");
131 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.avi_test2"));
135 public void shouldReturnEmptyIfPropertiesAreNotAsNamingConvention() throws Exception {
136 Map<String, Object> propertiesMap = new HashMap();
137 propertiesMap.put("a", "sss");
138 HashMap imageMap = new HashMap();
139 String name = "avi_test_namesw";
140 imageMap.put("get_param", name);
141 propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
142 Resource resource = new Resource();
143 resource.setProperties(propertiesMap);
144 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
145 new ResourceTranslationNovaServerImpl();
146 String localNodeType =
147 new NameExtractorNovaServerImpl()
148 .extractNodeTypeName(resource, "this.is.test.resource", "this.is.test.resource");
149 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.this_is_test_resource"));