[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / test / java / org / openecomp / sdc / translator / services / heattotosca / impl / nameextractor / NameExtractorNovaServerImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.translator.services.heattotosca.impl.nameextractor;
22
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.nameextractor.NameExtractorNovaServerImpl;
27 import org.openecomp.sdc.translator.services.heattotosca.impl.resourcetranslation.ResourceTranslationNovaServerImpl;
28
29 import java.util.Arrays;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34 import static org.junit.Assert.*;
35
36 /**
37  * @author SHIRIA
38  * @since December 20, 2016.
39  */
40 public class NameExtractorNovaServerImplTest {
41   @Test
42   public void shouldReturnNamePrefixIfPropertyNameMatchWithIndex() throws Exception {
43     Map<String, Object> propertiesMap = new HashMap();
44     propertiesMap.put("a", "sss");
45     HashMap imageMap = new HashMap();
46     String name = "avi_test_name_1";
47     imageMap.put("get_param", name);
48     propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
49     Resource resource = new Resource();
50     resource.setProperties(propertiesMap);
51     ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
52         new ResourceTranslationNovaServerImpl();
53     String localNodeType =
54         new NameExtractorNovaServerImpl().extractNodeTypeName(resource, "Ignore", "Ignore");
55     assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.avi_test"));
56   }
57
58   @Test
59   public void shouldReturnNamePrefixIfPropertyNameMatchWithListObjectInGetParamVal()
60       throws Exception {
61     Map<String, Object> propertiesMap = new HashMap();
62     propertiesMap.put("a", "sss");
63     HashMap imageMap = new HashMap();
64     List val = Arrays.asList("virc_vm_names", "2");
65     imageMap.put("get_param", val);
66     propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
67     Resource resource = new Resource();
68     resource.setProperties(propertiesMap);
69     ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
70         new ResourceTranslationNovaServerImpl();
71     String localNodeType =
72         new NameExtractorNovaServerImpl().extractNodeTypeName(resource, "Ignore", "Ignore");
73     assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.virc_vm"));
74   }
75
76   @Test
77   public void shouldReturnNamePrefixIfPropertyNameMatchWithListObjectInGetParamValAndGetParamAsGetParamVal()
78       throws Exception {
79     Map<String, Object> propertiesMap = new HashMap();
80     propertiesMap.put("a", "sss");
81     HashMap nameMap = new HashMap();
82     HashMap nameValMap = new HashMap();
83     nameValMap.put("get_param", "anyParam");
84     List val = Arrays.asList("virc_vm_names", nameValMap);
85     nameMap.put("get_param", val);
86     propertiesMap.put(Constants.NAME_PROPERTY_NAME, nameMap);
87     Resource resource = new Resource();
88     resource.setProperties(propertiesMap);
89     ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
90         new ResourceTranslationNovaServerImpl();
91     String localNodeType =
92         new NameExtractorNovaServerImpl().extractNodeTypeName(resource, "Ignore", "Ignore");
93     assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.virc_vm"));
94   }
95
96
97   @Test
98   public void shouldReturnNamePrefixIfPropertyNameMatchWithoutIndex() throws Exception {
99     Map<String, Object> propertiesMap = new HashMap();
100     propertiesMap.put("a", "sss");
101     HashMap imageMap = new HashMap();
102     String name = "avi_test_names";
103     imageMap.put("get_param", name);
104     propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
105     Resource resource = new Resource();
106     resource.setProperties(propertiesMap);
107     ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
108         new ResourceTranslationNovaServerImpl();
109     String localNodeType =
110         new NameExtractorNovaServerImpl().extractNodeTypeName(resource, "Ignore", "Ignore");
111     assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.avi_test"));
112   }
113
114   @Test
115   public void shouldReturnPrefixByPropertyOrder() throws Exception {
116     Map<String, Object> propertiesMap = new HashMap();
117     propertiesMap.put("a", "sss");
118     HashMap imageMap = new HashMap();
119     String name = "avi_test1_namesw";
120     imageMap.put("get_param", name);
121     propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
122     String flavor = "avi_test2_flavor_name";
123     imageMap = new HashMap();
124     imageMap.put("get_param", flavor);
125     propertiesMap.put("flavor", imageMap);
126     Resource resource = new Resource();
127     resource.setProperties(propertiesMap);
128     ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
129         new ResourceTranslationNovaServerImpl();
130     String localNodeType =
131         new NameExtractorNovaServerImpl().extractNodeTypeName(resource, "Ignore", "Ignore");
132     assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.avi_test2"));
133   }
134
135   @Test
136   public void shouldReturnEmptyIfPropertiesAreNotAsNamingConvention() throws Exception {
137     Map<String, Object> propertiesMap = new HashMap();
138     propertiesMap.put("a", "sss");
139     HashMap imageMap = new HashMap();
140     String name = "avi_test_namesw";
141     imageMap.put("get_param", name);
142     propertiesMap.put(Constants.NAME_PROPERTY_NAME, imageMap);
143     Resource resource = new Resource();
144     resource.setProperties(propertiesMap);
145     ResourceTranslationNovaServerImpl resourceTranslationNovaServer =
146         new ResourceTranslationNovaServerImpl();
147     String localNodeType =
148         new NameExtractorNovaServerImpl()
149             .extractNodeTypeName(resource, "this.is.test.resource", "this.is.test.resource");
150     assertTrue(localNodeType.equals("org.openecomp.resource.vfc.nodes.heat.this_is_test_resource"));
151   }
152
153 }