001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.pluto.testsuite.test;
020:
021: import java.io.IOException;
022: import java.io.InputStream;
023: import java.util.Properties;
024:
025: import org.apache.pluto.testsuite.InvalidConfigurationException;
026:
027: /**
028: * A Singleton which loads a properties file containing data expected by the
029: * tests in the testsuite.
030: */
031: public class ExpectedResults {
032:
033: /** The file name of properties holding expected results. */
034: public static final String PROPERTY_FILENAME = "expectedResults.properties";
035:
036: /** The static singleton instance. */
037: private static ExpectedResults instance;
038:
039: // Private Member Variables ------------------------------------------------
040:
041: /** The nested properties. */
042: private final Properties properties;
043:
044: // Constructor -------------------------------------------------------------
045:
046: /**
047: * Private constructor that prevents external instantiation.
048: * @throws IOException if fail to load properties from file.
049: */
050: private ExpectedResults() throws IOException {
051: properties = new Properties();
052: InputStream in = Thread.currentThread().getContextClassLoader()
053: .getResourceAsStream(PROPERTY_FILENAME);
054: if (in != null) {
055: properties.load(in);
056: } else {
057: throw new IOException("Could not find " + PROPERTY_FILENAME);
058: }
059: }
060:
061: /**
062: * Returns the singleton expected results instance.
063: * @return the singleton expected results instance.
064: * @throws InvalidConfigurationException if fail to read properties file.
065: */
066: public static ExpectedResults getInstance()
067: throws InvalidConfigurationException {
068: if (instance == null) {
069: try {
070: instance = new ExpectedResults();
071: } catch (IOException ex) {
072: throw new InvalidConfigurationException(
073: "Error reading file " + PROPERTY_FILENAME
074: + ": " + ex.getMessage());
075: }
076: }
077: return instance;
078: }
079:
080: // Public Methods ----------------------------------------------------------
081:
082: public String getMajorVersion() {
083: return properties.getProperty("expected.version.major");
084: }
085:
086: public String getMinorVersion() {
087: return properties.getProperty("expected.version.minor");
088: }
089:
090: public String getServerInfo() {
091: return properties.getProperty("expected.serverInfo");
092: }
093:
094: public String getPortalInfo() {
095: return properties.getProperty("expected.portalInfo");
096: }
097:
098: public String getMappedSecurityRole() {
099: return properties.getProperty("expected.security.role.mapped");
100: }
101:
102: public String getUnmappedSecurityRole() {
103: return properties.getProperty("expected.security.role");
104: }
105:
106: }
|