@Test public void testGetCfg() { ZebraShardingConfiguration cfg = new ZebraShardingConfiguration(); Map<String, ZebraShardingDataSourceCfg> cfgMap = new HashMap<>(); ZebraShardingDataSourceCfg shardingCfg = new ZebraShardingDataSourceCfg(); shardingCfg.setSharding(new ZebraShardingRuleConfiguration()); ZebraShardingDataSourceCfg masterSlaveCfg = new ZebraShardingDataSourceCfg(); masterSlaveCfg.setMasterslave(new ZebraMasterSlaveRuleConfiguration()); cfgMap.put("shardingDs1", shardingCfg); cfgMap.put("masterSlaveDs1", masterSlaveCfg); cfg.setShardingcfg(cfgMap); new Expectations() { { ApplicationContextUtil.getEnvironment(); result = environment; } { Binder.get(environment); result = binder; } { @SuppressWarnings("unchecked") Bindable<ZebraShardingConfiguration> bindable = (Bindable<ZebraShardingConfiguration>) any; binder.bind("zebra.database", bindable); result = bindResult; } { bindResult.isBound(); result = true; } { bindResult.get(); result = cfg; } }; ZebraShardingConfiguration result = ZebraShardingConfigurationUtil.getZebraShardingConfiguration(); assertThat(result, is(not(nullValue()))); Map<String, ZebraShardingDataSourceCfg> resultCfg = result.getShardingcfg(); assertThat(resultCfg, is(not(anEmptyMap()))); ZebraShardingDataSourceCfg resultShardingCfg = resultCfg.get("shardingDs1"); assertThat(resultShardingCfg.getType(), is(ZebraShardingDataSourceCfg.Type.SHARDING)); ZebraShardingDataSourceCfg resultMasterSlaveCfg = resultCfg.get("masterSlaveDs1"); assertThat(resultMasterSlaveCfg.getType(), is(ZebraShardingDataSourceCfg.Type.MASTER_SLAVE)); assertThat(resultMasterSlaveCfg.getMasterslave().getName(), is("masterSlaveDs1")); }
public static ZebraShardingConfiguration getZebraShardingConfiguration() { Environment environment = ApplicationContextUtil.getEnvironment(); BindResult<ZebraShardingConfiguration> bindResult = Binder.get(environment) .bind(ZEBRA_SHARDING_CONF_PREFIX, Bindable.of(ZebraShardingConfiguration.class)); ZebraShardingConfiguration cfg = bindResult.isBound() ? bindResult.get() : null; if (cfg != null) { setType(cfg); setNameIfMasterSlave(cfg); fillDefaultCfgOfShardingIfNotCfg(cfg); } return cfg; }
ZebraShardingConfigurationUtil { public static ZebraShardingConfiguration getZebraShardingConfiguration() { Environment environment = ApplicationContextUtil.getEnvironment(); BindResult<ZebraShardingConfiguration> bindResult = Binder.get(environment) .bind(ZEBRA_SHARDING_CONF_PREFIX, Bindable.of(ZebraShardingConfiguration.class)); ZebraShardingConfiguration cfg = bindResult.isBound() ? bindResult.get() : null; if (cfg != null) { setType(cfg); setNameIfMasterSlave(cfg); fillDefaultCfgOfShardingIfNotCfg(cfg); } return cfg; } }
ZebraShardingConfigurationUtil { public static ZebraShardingConfiguration getZebraShardingConfiguration() { Environment environment = ApplicationContextUtil.getEnvironment(); BindResult<ZebraShardingConfiguration> bindResult = Binder.get(environment) .bind(ZEBRA_SHARDING_CONF_PREFIX, Bindable.of(ZebraShardingConfiguration.class)); ZebraShardingConfiguration cfg = bindResult.isBound() ? bindResult.get() : null; if (cfg != null) { setType(cfg); setNameIfMasterSlave(cfg); fillDefaultCfgOfShardingIfNotCfg(cfg); } return cfg; } private  ZebraShardingConfigurationUtil(); }
ZebraShardingConfigurationUtil { public static ZebraShardingConfiguration getZebraShardingConfiguration() { Environment environment = ApplicationContextUtil.getEnvironment(); BindResult<ZebraShardingConfiguration> bindResult = Binder.get(environment) .bind(ZEBRA_SHARDING_CONF_PREFIX, Bindable.of(ZebraShardingConfiguration.class)); ZebraShardingConfiguration cfg = bindResult.isBound() ? bindResult.get() : null; if (cfg != null) { setType(cfg); setNameIfMasterSlave(cfg); fillDefaultCfgOfShardingIfNotCfg(cfg); } return cfg; } private  ZebraShardingConfigurationUtil(); static ZebraShardingConfiguration getZebraShardingConfiguration(); }
ZebraShardingConfigurationUtil { public static ZebraShardingConfiguration getZebraShardingConfiguration() { Environment environment = ApplicationContextUtil.getEnvironment(); BindResult<ZebraShardingConfiguration> bindResult = Binder.get(environment) .bind(ZEBRA_SHARDING_CONF_PREFIX, Bindable.of(ZebraShardingConfiguration.class)); ZebraShardingConfiguration cfg = bindResult.isBound() ? bindResult.get() : null; if (cfg != null) { setType(cfg); setNameIfMasterSlave(cfg); fillDefaultCfgOfShardingIfNotCfg(cfg); } return cfg; } private  ZebraShardingConfigurationUtil(); static ZebraShardingConfiguration getZebraShardingConfiguration();  }