ConfigUtils { public static Properties loadProperties(String fileName) { return loadProperties(fileName, false, false); } private  ConfigUtils(); static boolean isNotEmpty(String value); static boolean isEmpty(String value); static boolean isDefault(String value); static List<String> mergeValues(Class<?> type, String cfg, List<String> def); static String replaceProperty(String expression, Map<String, String> params); static Properties getProperties(); static void setProperties(Properties properties); static void addProperties(Properties properties); static String getProperty(String key); @SuppressWarnings({"unchecked", "rawtypes"}) static String getProperty(String key, String defaultValue); static String getSystemProperty(String key); static Properties loadProperties(String fileName); static Properties loadProperties(String fileName, boolean allowMultiFile); static Properties loadProperties(String fileName, boolean allowMultiFile, boolean optional); static int getPid(); @SuppressWarnings("deprecation") static int getServerShutdownTimeout();  }
@Test public void testLoadPropertiesNoFile() throws Exception { Properties p = ConfigUtils.loadProperties("notExisted", true); Properties expected = new Properties(); assertEquals(expected, p); p = ConfigUtils.loadProperties("notExisted", false); assertEquals(expected, p); }
@Test public void testLoadProperties() throws Exception { Properties p = ConfigUtils.loadProperties("dubbo.properties"); assertThat((String)p.get("dubbo"), equalTo("properties")); }
@Test public void testLoadPropertiesOneFile() throws Exception { Properties p = ConfigUtils.loadProperties("properties.load", false); Properties expected = new Properties(); expected.put("a", "12"); expected.put("b", "34"); expected.put("c", "56"); assertEquals(expected, p); }
@Test public void testLoadPropertiesOneFileAllowMulti() throws Exception { Properties p = ConfigUtils.loadProperties("properties.load", true); Properties expected = new Properties(); expected.put("a", "12"); expected.put("b", "34"); expected.put("c", "56"); assertEquals(expected, p); }
@Test public void testLoadPropertiesOneFileNotRootPath() throws Exception { Properties p = ConfigUtils.loadProperties("META-INF/dubbo/internal/com.alibaba.dubbo.common.threadpool.ThreadPool", false); Properties expected = new Properties(); expected.put("fixed", "com.alibaba.dubbo.common.threadpool.support.fixed.FixedThreadPool"); expected.put("cached", "com.alibaba.dubbo.common.threadpool.support.cached.CachedThreadPool"); expected.put("limited", "com.alibaba.dubbo.common.threadpool.support.limited.LimitedThreadPool"); expected.put("eager", "com.alibaba.dubbo.common.threadpool.support.eager.EagerThreadPool"); assertEquals(expected, p); }
@Ignore("see http: @Test public void testLoadPropertiesMultiFileNotRootPathException() throws Exception { try { ConfigUtils.loadProperties("META-INF/services/com.alibaba.dubbo.common.status.StatusChecker", false); Assert.fail(); } catch (IllegalStateException expected) { assertThat(expected.getMessage(), containsString("only 1 META-INF/services/com.alibaba.dubbo.common.status.StatusChecker file is expected, but 2 dubbo.properties files found on class path:")); } }
@Test public void testLoadPropertiesMultiFileNotRootPath() throws Exception { Properties p = ConfigUtils.loadProperties("META-INF/dubbo/internal/com.alibaba.dubbo.common.status.StatusChecker", true); Properties expected = new Properties(); expected.put("memory", "com.alibaba.dubbo.common.status.support.MemoryStatusChecker"); expected.put("load", "com.alibaba.dubbo.common.status.support.LoadStatusChecker"); expected.put("aa", "12"); assertEquals(expected, p); }