KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > testsuite > ExpectedResults


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 JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.util.Properties JavaDoc;
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 JavaDoc PROPERTY_FILENAME = "expectedResults.properties";
31     
32     public static final String JavaDoc EXPECTED_PORTAL_INFO_KEY = "expected.portalInfo";
33     
34     private static ExpectedResults expectedResults;
35     private Properties JavaDoc properties;
36     
37     private ExpectedResults() throws IOException JavaDoc {
38         this.properties = new Properties JavaDoc();
39         
40         InputStream JavaDoc in = Thread.currentThread().getContextClassLoader().getResourceAsStream(PROPERTY_FILENAME);
41         if (in == null) {
42             throw new IOException JavaDoc("Could not find " + PROPERTY_FILENAME);
43         }
44         this.properties.load(in);
45     }
46     
47     public Properties JavaDoc 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 JavaDoc getExpectedProperties() throws InvalidConfigurationException {
58         try {
59             if (expectedResults == null) {
60                 expectedResults = new ExpectedResults();
61             }
62             
63             return expectedResults.getProperties();
64         } catch (IOException JavaDoc e) {
65             throw new InvalidConfigurationException("An error occured reading the resource " + PROPERTY_FILENAME + ". Error was " + e.getMessage());
66         }
67     }
68
69 }
70
Popular Tags