aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java
blob: 2c0cf0b1aa8b550900411a07ab9f1fdf34d74b42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package org.openecomp.sdc.heat.datatypes.model;

import org.openecomp.core.utilities.yaml.YamlUtil;
import org.junit.Test;

import java.io.InputStream;

public class EnvironmentTest {

  @Test
  public void testYamlToServiceTemplateObj() {
    YamlUtil yamlUtil = new YamlUtil();
    InputStream yamlFile = yamlUtil.loadYamlFileIs("/mock/model/envSettings.env");
    Environment envVars = yamlUtil.yamlToObject(yamlFile, Environment.class);
    envVars.toString();
  }

  @Test
  public void test() {
    String heatResourceName = "server_abc_0u";
    String novaServerPrefix = "server_";
    if (heatResourceName.startsWith(novaServerPrefix)) {
      heatResourceName = heatResourceName.substring(novaServerPrefix.length());
    }
    int lastIndexOfUnderscore = heatResourceName.lastIndexOf("_");
    if (heatResourceName.length() == lastIndexOfUnderscore) {
      System.out.println(heatResourceName);
    } else {
      String heatResourceNameSuffix = heatResourceName.substring(lastIndexOfUnderscore + 1);
      try {
        Integer.parseInt(heatResourceNameSuffix);
        System.out.println(heatResourceName.substring(0, lastIndexOfUnderscore));
      } catch (NumberFormatException ignored) {
        System.out.println(heatResourceName);
      }
    }
  }
}