1 7 package com.inversoft.junit; 8 9 10 import java.io.FileInputStream ; 11 import java.util.MissingResourceException ; 12 import java.util.PropertyResourceBundle ; 13 import java.util.ResourceBundle ; 14 15 16 24 public class Configuration 25 { 26 30 public static final String CONFIG_PROPERTY = "junit.config.file"; 31 32 35 public static final String DEFAULT_CONFIG_FILE = "junit"; 36 37 40 public static final String TEST_LOCATION_PREFIX = "test.location"; 41 42 45 public static final String PERSISTING_SESSION = "persisting.session"; 46 47 50 private static ResourceBundle bundle; 51 52 53 54 protected Configuration() { 55 } 57 58 64 static { 65 String location = System.getProperty(CONFIG_PROPERTY); 68 if (location != null) { 69 try { 70 bundle = new PropertyResourceBundle (new FileInputStream (location)); 71 } catch (Exception e) { 72 throw new IllegalStateException ("System property named " + CONFIG_PROPERTY + 73 " does not point to a valid configuration file or the file" + 74 " could not be read. Exception: " + e.toString()); 75 } 76 } 77 78 try { 80 bundle = PropertyResourceBundle.getBundle(DEFAULT_CONFIG_FILE); 81 } catch (MissingResourceException mre) { 82 throw new IllegalStateException ("Could not find a valid junit-framework configuration file"); 83 } 84 } 85 86 87 104 public static String getTestLocation(Class testCaseClass) { 105 String name = TEST_LOCATION_PREFIX + "." + testCaseClass.getName(); 106 String location; 107 try { 108 location = bundle.getString(name); 109 } catch (MissingResourceException mre) { 110 location = bundle.getString(TEST_LOCATION_PREFIX); 112 } 113 114 return location; 115 } 116 117 124 public static boolean isPersistingSession() { 125 try { 126 String value = bundle.getString(PERSISTING_SESSION); 127 if (value.equalsIgnoreCase("true")) { 128 return true; 129 } 130 } catch (MissingResourceException mre) { 131 } 133 134 return false; 135 } 136 } | Popular Tags |