Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 31 32 package org.opencms.test; 33 34 import org.opencms.util.CmsFileUtil; 35 import org.opencms.util.CmsPropertyUtils; 36 37 import java.io.File ; 38 import java.io.IOException ; 39 40 import org.apache.commons.collections.ExtendedProperties; 41 42 51 public final class OpenCmsTestProperties { 52 53 private static ExtendedProperties m_configuration; 54 55 58 private static OpenCmsTestProperties m_testSingleton; 59 60 63 private String m_basePath; 64 65 68 private String m_dbProduct; 69 70 73 private String m_testDataPath; 74 75 78 private String m_testWebappPath; 79 80 83 private OpenCmsTestProperties() { 84 85 } 87 88 91 public static OpenCmsTestProperties getInstance() { 92 93 if (m_testSingleton == null) { 94 throw new RuntimeException ("You have to initialize the test properties."); 95 } 96 return m_testSingleton; 97 } 98 99 104 public static void initialize(String basePath) { 105 106 if (m_testSingleton != null) { 107 return; 108 } 109 110 String testPropPath; 111 m_testSingleton = new OpenCmsTestProperties(); 112 113 m_testSingleton.m_basePath = basePath; 114 if (!m_testSingleton.m_basePath.endsWith("/")) { 115 m_testSingleton.m_basePath += "/"; 116 } 117 118 try { 119 testPropPath = CmsFileUtil.getResourcePathFromClassloader("test.properties"); 120 if (testPropPath == null) { 121 throw new RuntimeException ( 122 "Test property file ('test.properties') could not be found by context Classloader."); 123 } 124 File f = new File (testPropPath); 125 if (!f.exists()) { 126 throw new RuntimeException ( 127 "Test property file ('test.properties') could not be found. Context Classloader suggested location: " 128 + testPropPath); 129 } 130 m_configuration = CmsPropertyUtils.loadProperties(testPropPath); 131 } catch (IOException e) { 132 e.printStackTrace(System.out); 133 throw new RuntimeException (e); 134 } 135 136 m_testSingleton.m_testDataPath = m_configuration.getString("test.data.path"); 137 m_testSingleton.m_testWebappPath = m_configuration.getString("test.webapp.path"); 138 m_testSingleton.m_dbProduct = m_configuration.getString("db.product"); 139 140 } 141 142 145 public String getBasePath() { 146 147 return m_basePath; 148 } 149 150 153 154 public ExtendedProperties getConfiguration() { 155 156 return m_configuration; 157 } 158 159 163 public String getDbProduct() { 164 165 return m_dbProduct; 166 } 167 168 171 public String getTestDataPath() { 172 173 return m_testDataPath; 174 } 175 176 179 public String getTestWebappPath() { 180 181 return m_testWebappPath; 182 } 183 184 }
| Popular Tags
|