##### Coverage Report - com.ctrip.apollo.core.MetaDomainConsts

Classes in this File | Line Coverage | Branch Coverage | Complexity
MetaDomainConsts |
94% | 18/19
N/A | N/A
| 1.0;1

1 |  |
     package com.ctrip.apollo.core;
2 |  |
3 |  |
     import java.util.HashMap;
4 |  |
     import java.util.Map;
5 |  |
     import java.util.Properties;
6 |  |
7 |  |
     import com.ctrip.apollo.core.enums.Env;
8 |  |
     import com.ctrip.apollo.core.utils.ResourceUtils;
9 |  |
10 |  |
     /**
11 |  |
      * The meta domain will load the meta server from System environment first, if not exist, will load
12 |  |
      * from apollo-env.properties. If neither exists, will load the default meta url.
13 |  |
      *
14 |  |
      * Currently, apollo supports local/dev/fat/uat/lpt/pro environments.
15 |  |
      */
16 | 0 |
     public class MetaDomainConsts {
17 |  |
18 | 1 |
       private static Map<Env, Object> domains = new HashMap<>();
19 |  |
20 |  |
       public static final String DEFAULT_META_URL = "http://localhost:8080";
21 |  |
22 |  |
       static {
23 | 1 |
         Properties prop = new Properties();
24 | 1 |
         prop = ResourceUtils.readConfigFile("apollo-env.properties", prop);
25 | 1 |
         Properties env = System.getProperties();
26 | 2 |
         domains.put(Env.LOCAL,
27 | 1 |
             env.getProperty("local_meta", prop.getProperty("local.meta", DEFAULT_META_URL)));
28 | 2 |
         domains.put(Env.DEV,
29 | 1 |
             env.getProperty("dev_meta", prop.getProperty("dev.meta", DEFAULT_META_URL)));
30 | 2 |
         domains.put(Env.FAT,
31 | 1 |
             env.getProperty("fat_meta", prop.getProperty("fat.meta", DEFAULT_META_URL)));
32 | 2 |
         domains.put(Env.UAT,
33 | 1 |
             env.getProperty("uat_meta", prop.getProperty("uat.meta", DEFAULT_META_URL)));
34 | 2 |
         domains.put(Env.LPT,
35 | 1 |
             env.getProperty("lpt_meta", prop.getProperty("lpt.meta", DEFAULT_META_URL)));
36 | 2 |
         domains.put(Env.PRO,
37 | 1 |
             env.getProperty("pro_meta", prop.getProperty("pro.meta", DEFAULT_META_URL)));
38 | 1 |
       }
39 |  |
40 |  |
       public static String getDomain(Env env) {
41 | 3 |
         return String.valueOf(domains.get(env));
42 |  |
       }
43 |  |
     }