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.Assert;
24 import org.junit.Test;
25 import org.openecomp.sdc.heat.datatypes.model.Resource;
27 import java.util.HashMap;
32 * @since December 21, 2016.
34 public class NameExtractorContrailComputeImplTest{
38 public void testStaticGetComputeNodeTypeId() throws Exception {
39 Resource serviceTemplateResource = new Resource();
40 serviceTemplateResource.setProperties(new HashMap<>());
41 serviceTemplateResource.getProperties().put("image_name", "aaaa");
42 String computeNodeTypeId =
43 new NameExtractorContrailComputeImpl().extractNodeTypeName(serviceTemplateResource, "123", "123");
44 Assert.assertEquals("org.openecomp.resource.vfc.nodes.heat.compute_123", computeNodeTypeId);
48 public void testComputeNodeTypeIdIsTakingFlavorNameIfImageNameIsNotAsNamingConvention()
50 Resource serviceTemplateResource = new Resource();
51 serviceTemplateResource.setProperties(new HashMap<>());
52 serviceTemplateResource.getProperties().put("image_name", "aaaa");
53 Map flavor = new HashMap<>();
54 flavor.put("get_param", "bbb_flavor_name");
55 serviceTemplateResource.getProperties().put("flavor", flavor);
56 String computeNodeTypeId =
57 new NameExtractorContrailComputeImpl().extractNodeTypeName(serviceTemplateResource, "123", "123");
58 Assert.assertEquals("org.openecomp.resource.vfc.nodes.heat.bbb", computeNodeTypeId);
62 public void testStaticGetComputeNodeTypeIdByFlavor() throws Exception {
63 Resource serviceTemplateResource = new Resource();
64 serviceTemplateResource.setProperties(new HashMap<>());
65 serviceTemplateResource.getProperties().put("image_name", "aaaa");
66 serviceTemplateResource.getProperties().put("flavor", "aaaa_flavor_name");
67 String computeNodeTypeId =
68 new NameExtractorContrailComputeImpl().extractNodeTypeName(serviceTemplateResource, "123", "123");
69 Assert.assertEquals("org.openecomp.resource.vfc.nodes.heat.compute_123", computeNodeTypeId);
74 public void testNamingConventionGetComputeNodeTypeId() throws Exception {
75 Resource serviceTemplateResource = new Resource();
76 serviceTemplateResource.setProperties(new HashMap<>());
77 Map image = new HashMap<>();
78 image.put("get_param", "bbb_image_name");
79 serviceTemplateResource.getProperties().put("image_name", image);
80 String computeNodeTypeId =
81 new NameExtractorContrailComputeImpl().extractNodeTypeName(serviceTemplateResource, "123", "123");
82 Assert.assertEquals(computeNodeTypeId, "org.openecomp.resource.vfc.nodes.heat.bbb");
86 public void testNoNamingConventionGetComputeNodeTypeId() throws Exception {
87 Resource serviceTemplateResource = new Resource();
88 serviceTemplateResource.setProperties(new HashMap<>());
89 Map image = new HashMap<>();
90 image.put("get_file", "bbb_image");
91 serviceTemplateResource.getProperties().put("image_name", image);
92 String computeNodeTypeId =
93 new NameExtractorContrailComputeImpl().extractNodeTypeName(serviceTemplateResource, "123", "123");
94 Assert.assertEquals(computeNodeTypeId, "org.openecomp.resource.vfc.nodes.heat.compute_123");