Revision 67d73594
Added by Andreas Kohlbecker almost 13 years ago
modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/TestConfiguration.java | ||
---|---|---|
11 | 11 |
import java.net.URI; |
12 | 12 |
import java.net.URISyntaxException; |
13 | 13 |
import java.net.URL; |
14 |
import java.util.InvalidPropertiesFormatException; |
|
15 | 14 |
import java.util.Properties; |
16 | 15 |
import java.util.UUID; |
17 | 16 |
|
... | ... | |
44 | 43 |
private static TestConfiguration testConfiguration = null; |
45 | 44 |
|
46 | 45 |
private TestConfiguration() { |
47 |
InputStream in = null; |
|
48 |
|
|
49 |
in = readFromUserHome(); |
|
50 |
if(in == null){ |
|
51 |
in = readFromClassPath(); |
|
52 |
} |
|
53 |
if(in == null){ |
|
54 |
String message = "Test configuration file " + DATA_PORTAL_TEST_PROPERTIES_FILE + " not found!"; |
|
55 |
logger.error(message); |
|
56 |
System.exit(-1); |
|
57 |
} |
|
58 |
|
|
59 |
logger.info("Loading test configuration from " + propertySourceUri); |
|
60 |
try { |
|
61 |
properties.loadFromXML(in); |
|
62 |
} catch (InvalidPropertiesFormatException e) { |
|
63 |
logger.error(e); |
|
64 |
} catch (IOException e) { |
|
65 |
logger.error(e); |
|
66 |
} finally { |
|
67 |
try { |
|
68 |
in.close(); |
|
69 |
} catch (IOException e) { |
|
70 |
/* IGNORE */ |
|
71 |
} |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* @return |
|
77 |
*/ |
|
78 |
private InputStream readFromClassPath() { |
|
79 |
ClassLoader cl = getClass().getClassLoader(); |
|
80 |
return cl.getResourceAsStream("eu/etaxonomy/dataportal/"+DATA_PORTAL_TEST_PROPERTIES_FILE); |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* @param userHome |
|
85 |
* @param in |
|
86 |
* @return |
|
87 |
*/ |
|
88 |
public InputStream readFromUserHome() { |
|
89 |
|
|
90 |
InputStream in = null; |
|
91 | 46 |
String userHome = System.getProperty("user.home"); |
92 | 47 |
if (userHome != null) { |
93 |
|
|
94 | 48 |
File propertiesFile = new File(userHome, ".cdmLibrary" + File.separator + DATA_PORTAL_TEST_PROPERTIES_FILE); |
95 | 49 |
|
96 | 50 |
try { |
97 | 51 |
|
52 |
InputStream in; |
|
98 | 53 |
if (propertiesFile.exists()) { |
99 | 54 |
propertySourceUri = propertiesFile.toURI().toURL(); |
100 | 55 |
in = new FileInputStream(propertiesFile); |
101 | 56 |
} else { |
102 |
in = this.getClass().getResourceAsStream("/eu/etaxonomy/dataportal/DataPortalTest.properties"); |
|
103 |
propertySourceUri = this.getClass().getResource("/eu/etaxonomy/dataportal/DataPortalTest.properties"); |
|
57 |
String resourceName = "/eu/etaxonomy/dataportal/"+ DATA_PORTAL_TEST_PROPERTIES_FILE; |
|
58 |
|
|
59 |
in = this.getClass().getResourceAsStream(resourceName); |
|
60 |
propertySourceUri = this.getClass().getResource(resourceName); |
|
104 | 61 |
} |
62 |
logger.info("Loading test configuration from " + propertySourceUri); |
|
63 |
properties.loadFromXML(in); |
|
64 |
in.close(); |
|
105 | 65 |
|
106 | 66 |
updateSystemProperties(false); |
107 | 67 |
|
... | ... | |
110 | 70 |
} catch (IOException e) { |
111 | 71 |
logger.error(e); |
112 | 72 |
} |
73 |
|
|
113 | 74 |
} |
114 |
return in; |
|
115 | 75 |
} |
116 | 76 |
|
117 | 77 |
/** |
Also available in: Unified diff
fixing problem with loading test configuration