##### Coverage Report - com.ctrip.framework.apollo.biz.eureka.ApolloEurekaClientConfig

Classes in this File | Line Coverage | Branch Coverage | Complexity
ApolloEurekaClientConfig |
87% | 7/8
75% | 3/4
| 5.0;5

1 |  |
     package com.ctrip.framework.apollo.biz.eureka;
2 |  |
3 |  |
     import com.google.common.base.Splitter;
4 |  |
     import com.google.common.base.Strings;
5 |  |
6 |  |
     import com.ctrip.framework.apollo.biz.service.ServerConfigService;
7 |  |
8 |  |
     import org.springframework.beans.factory.annotation.Autowired;
9 |  |
     import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
10 |  |
     import org.springframework.context.annotation.Primary;
11 |  |
     import org.springframework.core.env.Environment;
12 |  |
     import org.springframework.stereotype.Component;
13 |  |
14 |  |
     import java.util.List;
15 |  |
16 |  |
     @Component
17 |  |
     @Primary
18 | 3 |
     public class ApolloEurekaClientConfig extends EurekaClientConfigBean {
19 |  |
       static final String EUREKA_URL_CONFIG = "eureka.service.url";
20 | 1 |
       private static final Splitter URL_SPLITTER = Splitter.on(",").omitEmptyStrings();
21 |  |
22 |  |
       @Autowired
23 |  |
       private ServerConfigService serverConfigService;
24 |  |
25 |  |
       @Autowired
26 |  |
       private Environment environment;
27 |  |
28 |  |
       /**
29 |  |
        * Assert only one zone: defaultZone, but multiple environments.
30 |  |
        */
31 |  |
       public List<String> getEurekaServerServiceUrls(String myZone) {
32 |  |
         //First check if there is any system property override
33 | 2 |
         if (!Strings.isNullOrEmpty(environment.getProperty(EUREKA_URL_CONFIG))) {
34 | 1 |
           return URL_SPLITTER.splitToList(environment.getProperty(EUREKA_URL_CONFIG));
35 |  |
         }
36 |  |
37 |  |
         //Second check if it is configured in database
38 | 1 |
         String eurekaUrl = serverConfigService.getValue(EUREKA_URL_CONFIG);
39 |  |
40 | 1 |
         if (!Strings.isNullOrEmpty(eurekaUrl)) {
41 | 1 |
           return URL_SPLITTER.splitToList(eurekaUrl);
42 |  |
43 |  |
         }
44 |  |
45 |  |
         //fallback to default
46 | 0 |
         return super.getEurekaServerServiceUrls(myZone);
47 |  |
       }
48 |  |
49 |  |
     }