001
014
015 package com.liferay.portal.util.test;
016
017 import com.liferay.portal.kernel.util.ListUtil;
018
019 import java.io.InputStream;
020
021 import java.util.Collections;
022 import java.util.Enumeration;
023 import java.util.List;
024 import java.util.Properties;
025
026
029 public class TestPropsUtil {
030
031 public static String get(String key) {
032 return _instance._get(key);
033 }
034
035 public static Properties getProperties() {
036 return _instance._props;
037 }
038
039 public static void printProperties() {
040 _instance._printProperties(true);
041 }
042
043 public static void set(String key, String value) {
044 _instance._set(key, value);
045 }
046
047 private TestPropsUtil() {
048 try {
049 ClassLoader classLoader = ClassLoader.getSystemClassLoader();
050
051 InputStream is = classLoader.getResourceAsStream(
052 "test-portal-impl.properties");
053
054 _props.load(is);
055
056 is = classLoader.getResourceAsStream(
057 "test-portal-impl-ext.properties");
058
059 if (is != null) {
060 _props.load(is);
061 }
062
063 _printProperties(false);
064 }
065 catch (Exception e) {
066 e.printStackTrace();
067 }
068 }
069
070 private String _get(String key) {
071 return _props.getProperty(key);
072 }
073
074 private void _printProperties(boolean update) {
075 List<String> keys = Collections.list(
076 (Enumeration<String>)_props.propertyNames());
077
078 keys = ListUtil.sort(keys);
079
080 if (update) {
081 System.out.println("-- updated properties --");
082 }
083 else {
084 System.out.println("-- listing properties --");
085 }
086
087 for (String key : keys) {
088 System.out.println(key + "=" + _props.getProperty(key));
089 }
090
091 System.out.println("");
092 }
093
094 private void _set(String key, String value) {
095 _props.setProperty(key, value);
096 }
097
098 private static TestPropsUtil _instance = new TestPropsUtil();
099
100 private Properties _props = new Properties();
101
102 }