1 package org.testng.internal; 2 3 import java.util.Map; 4 import java.util.Properties; 5 6 import org.testng.ITestResult; 7 import org.testng.collections.Maps; 8 9 10 11 /** 12 * Constants used by TestNG 13 * 14 * @author Cedric Beust, May 2, 2004 15 * 16 */ 17 public class Constants { 18 private static final String NAMESPACE = "testng"; 19 20 //////// // 21 // Properties 22 // 23 public static final String PROP_OUTPUT_DIR = NAMESPACE + "." + "outputDir"; 24 // public static final String PROP_NAME = NAMESPACE + "." + "name"; 25 // public static final String PROP_INCLUDED_GROUPS = NAMESPACE + "." + "includedGroups"; 26 // public static final String PROP_EXCLUDED_GROUPS = NAMESPACE + "." + "excludedGroups"; 27 // public static final String PROP_CLASS_NAMES = NAMESPACE + "." + "classNames"; 28 // public static final String PROP_VERBOSE = NAMESPACE + "." + "verbose"; 29 // public static final String PROP_JUNIT= NAMESPACE + "." + "junit"; 30 // public static final String PROP_QUIET= NAMESPACE + "." + "quiet"; 31 // public static final String PROP_GROUP= NAMESPACE + "." + "group"; 32 33 private static final TestNGProperty[] COMMAND_LINE_PARAMETERS = { 34 new TestNGProperty("-d", PROP_OUTPUT_DIR, "Directory where the result files will be created.", "test-output"), 35 }; 36 37 private static final Map<String, TestNGProperty> m_propertiesByName = Maps.newHashMap(); 38 39 static { 40 // for (int i = 0; i < PROPERTIES.length; i++) { 41 // m_propertiesByName.put(PROPERTIES[i].getName(), PROPERTIES[i]); 42 // } 43 for (TestNGProperty element : COMMAND_LINE_PARAMETERS) { element.getName()44 m_propertiesByName.put(element.getName(), element); 45 } 46 } 47 getProperty(String propertyName)48 private static TestNGProperty getProperty(String propertyName) { 49 TestNGProperty result = m_propertiesByName.get(propertyName); 50 assert null != result : "Unknown property : " + propertyName; 51 52 return result; 53 } 54 getPropertyValue(Properties p, String propertyName)55 public static String getPropertyValue(Properties p, String propertyName) { 56 TestNGProperty r= getProperty(propertyName); 57 assert null != r : "Unknown property : " + propertyName; 58 59 String result = p.getProperty(r.getName()); 60 61 return result; 62 } 63 getBooleanPropertyValue(Properties properties, String propertyName)64 public static boolean getBooleanPropertyValue(Properties properties, String propertyName) { 65 TestNGProperty p = getProperty(propertyName); 66 String r = properties.getProperty(propertyName, p.getDefault()); 67 boolean result = "true".equalsIgnoreCase(r); 68 69 return Boolean.valueOf(result); 70 } 71 getIntegerPropertyValue(Properties properties, String propertyName)72 public static int getIntegerPropertyValue(Properties properties, String propertyName) { 73 TestNGProperty p = getProperty(propertyName); 74 String r = properties.getProperty(propertyName, p.getDefault()); 75 int result = Integer.parseInt(r); 76 77 return result; 78 } 79 getDefaultValueFor(String propertyName)80 public static String getDefaultValueFor(String propertyName) { 81 TestNGProperty p = getProperty(propertyName); 82 return p.getDefault(); 83 } 84 displayStatus(int status)85 public static String displayStatus(int status) { 86 if (ITestResult.SKIP == status) { 87 return "SKIP"; 88 } else if (ITestResult.SUCCESS == status) { 89 return "SUCCESS"; 90 } else if (ITestResult.FAILURE == status) { 91 return "FAILURE"; 92 } else { 93 return "UNKNOWN_STATUS"; 94 } 95 } 96 97 } 98