View Javadoc

1   /*
2    * Copyright 2004 The Apache Software Foundation
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   * 
16   */
17  
18  package org.apache.pluto.testsuite;
19  
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.util.Properties;
23  
24  /***
25   * A Singleton which loads a properties file containing data expected
26   * by the tests in the testsuite.
27   *
28   */
29  public class ExpectedResults {
30  	public static final String PROPERTY_FILENAME = "expectedResults.properties";
31  	
32  	public static final String EXPECTED_PORTAL_INFO_KEY = "expected.portalInfo";	
33  	
34  	private static ExpectedResults expectedResults;
35  	private Properties properties;
36  	
37  	private ExpectedResults() throws IOException {
38  		this.properties = new Properties();
39  		
40  		InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(PROPERTY_FILENAME);
41  		if (in == null) {
42  			throw new IOException("Could not find " + PROPERTY_FILENAME);
43  		}
44  		this.properties.load(in);
45  	}
46  	
47  	public Properties getProperties() {
48  		return this.properties;
49  	}
50  	
51  	/***
52  	 * Retrieves properties expected by the test suite.
53  	 *  
54  	 * @return the Properties found in the properties file.
55  	 * @throws InvalidConfigurationException if an error occured reading the properties file.
56  	 */
57  	public static Properties getExpectedProperties() throws InvalidConfigurationException {
58  		try {
59  			if (expectedResults == null) {
60  				expectedResults = new ExpectedResults(); 
61  			}
62  			
63  			return expectedResults.getProperties(); 
64  		} catch (IOException e) {
65  			throw new InvalidConfigurationException("An error occured reading the resource " + PROPERTY_FILENAME + ". Error was " + e.getMessage());
66  		}
67  	}
68  
69  }