Project

General

Profile

« Previous | Next » 

Revision 58cdc007

Added by Andreas Kohlbecker almost 13 years ago

fixing problem with loading test configuration

View differences:

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;
14 15
import java.util.Properties;
15 16
import java.util.UUID;
16 17

  
......
43 44
	private static TestConfiguration testConfiguration = null;
44 45

  
45 46
	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;
46 91
		String userHome = System.getProperty("user.home");
47 92
		if (userHome != null) {
93

  
48 94
			File propertiesFile = new File(userHome, ".cdmLibrary" + File.separator + DATA_PORTAL_TEST_PROPERTIES_FILE);
49 95

  
50 96
			try {
51 97

  
52
				InputStream in;
53 98
				if (propertiesFile.exists()) {
54 99
					propertySourceUri = propertiesFile.toURI().toURL();
55 100
					in = new FileInputStream(propertiesFile);
......
57 102
					in =  this.getClass().getResourceAsStream("/eu/etaxonomy/dataportal/DataPortalTest.properties");
58 103
					propertySourceUri = this.getClass().getResource("/eu/etaxonomy/dataportal/DataPortalTest.properties");
59 104
				}
60
				logger.info("Loading test configuration from " + propertySourceUri);
61
				properties.loadFromXML(in);
62
				in.close();
63 105

  
64 106
				updateSystemProperties(false);
65 107

  
......
68 110
			} catch (IOException e) {
69 111
				logger.error(e);
70 112
			}
71

  
72 113
		}
114
		return in;
73 115
	}
74 116

  
75 117
	/**

Also available in: Unified diff