1 package org.openecomp.sdc.translator.services.heattotosca.helper.impl;
3 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
4 import org.openecomp.sdc.translator.services.heattotosca.Constants;
5 import org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerImpl;
8 import java.util.Arrays;
9 import java.util.HashMap;
10 import java.util.List;
13 import static org.junit.Assert.assertTrue;
17 * @since August 04, 2016
19 public class NameExtractorServiceImplTest {
21 public void shouldReturnNamePrefixIfPropertyNameMatchWithIndex() throws Exception {
22 Map<String, Object> propertiesMap = new HashMap();
23 propertiesMap.put("a", "sss");
24 HashMap imageMap = new HashMap();
25 String name = "avi_test_name_1";
26 imageMap.put("get_param", name);
27 propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
28 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
29 new ResourceTranslationNovaServerImpl();
30 String localNodeType = resourceTranslationNovaServer
31 .createLocalNodeType(new ServiceTemplate(), propertiesMap, "Ignore");
32 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.avi_test"));
36 public void shouldReturnNamePrefixIfPropertyNameMatchWithListObjectInGetParamVal()
38 Map<String, Object> propertiesMap = new HashMap();
39 propertiesMap.put("a", "sss");
40 HashMap imageMap = new HashMap();
41 List val = Arrays.asList("virc_vm_names", "2");
42 imageMap.put("get_param", val);
43 propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
44 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
45 new ResourceTranslationNovaServerImpl();
46 String localNodeType = resourceTranslationNovaServer
47 .createLocalNodeType(new ServiceTemplate(), propertiesMap, "Ignore");
48 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.virc_vm"));
52 public void shouldReturnNamePrefixIfPropertyNameMatchWithListObjectInGetParamValAndGetParamAsGetParamVal()
54 Map<String, Object> propertiesMap = new HashMap();
55 propertiesMap.put("a", "sss");
56 HashMap nameMap = new HashMap();
57 HashMap nameValMap = new HashMap();
58 nameValMap.put("get_param", "anyParam");
59 List val = Arrays.asList("virc_vm_names", nameValMap);
60 nameMap.put("get_param", val);
61 propertiesMap.put(Constants.NAME_PROPERTY_NAME, nameMap);
62 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
63 new ResourceTranslationNovaServerImpl();
64 String localNodeType = resourceTranslationNovaServer
65 .createLocalNodeType(new ServiceTemplate(), propertiesMap, "Ignore");
66 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.virc_vm"));
71 public void shouldReturnNamePrefixIfPropertyNameMatchWithoutIndex() throws Exception {
72 Map<String, Object> propertiesMap = new HashMap();
73 propertiesMap.put("a", "sss");
74 HashMap imageMap = new HashMap();
75 String name = "avi_test_names";
76 imageMap.put("get_param", name);
77 propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
78 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
79 new ResourceTranslationNovaServerImpl();
80 String localNodeType = resourceTranslationNovaServer
81 .createLocalNodeType(new ServiceTemplate(), propertiesMap, "Ignore");
82 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.avi_test"));
86 public void shouldReturnPrefixByPropertyOrder() throws Exception {
87 Map<String, Object> propertiesMap = new HashMap();
88 propertiesMap.put("a", "sss");
89 HashMap imageMap = new HashMap();
90 String name = "avi_test1_namesw";
91 imageMap.put("get_param", name);
92 propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
93 String flavor = "avi_test2_flavor_name";
94 imageMap = new HashMap();
95 imageMap.put("get_param", flavor);
96 propertiesMap.put("flavor", imageMap);
97 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
98 new ResourceTranslationNovaServerImpl();
99 String localNodeType = resourceTranslationNovaServer
100 .createLocalNodeType(new ServiceTemplate(), propertiesMap, "Ignore");
101 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.avi_test2"));
105 public void shouldReturnEmptyIfPropertiesAreNotAsNamingConvention() throws Exception {
106 Map<String, Object> propertiesMap = new HashMap();
107 propertiesMap.put("a", "sss");
108 HashMap imageMap = new HashMap();
109 String name = "avi_test_namesw";
110 imageMap.put("get_param", name);
111 propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
112 ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
113 new ResourceTranslationNovaServerImpl();
114 String localNodeType = resourceTranslationNovaServer
115 .createLocalNodeType(new ServiceTemplate(), propertiesMap, "this.is.test.resource");
116 assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.this_is_test_resource"));