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: package org.apache.pluto.testsuite;
018:
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.util.ArrayList;
022: import java.util.List;
023:
024: import org.apache.commons.digester.Digester;
025: import org.xml.sax.SAXException;
026:
027: /**
028: * Test configuration factory that reads and parses testsuite config file using
029: * Digester and constructs <code>TestConfig</code> objects.
030: *
031: * @see TestConfig
032: *
033: */
034: public class TestConfigFactory {
035:
036: /** Digester instance used to parse testsuite config file. */
037: private Digester digester = new Digester();
038:
039: // Constructor -------------------------------------------------------------
040:
041: /**
042: * Creates a factory instance.
043: */
044: public TestConfigFactory() {
045: digester = new Digester();
046: digester.addObjectCreate("testportlet-config", ArrayList.class);
047:
048: digester.addObjectCreate("testportlet-config/testsuite-config",
049: TestConfig.class);
050:
051: digester.addBeanPropertySetter(
052: "testportlet-config/testsuite-config/name", "name");
053: digester.addBeanPropertySetter(
054: "testportlet-config/testsuite-config/class",
055: "testClassName");
056: digester.addBeanPropertySetter(
057: "testportlet-config/testsuite-config/display-uri",
058: "displayURI");
059:
060: digester.addCallMethod(
061: "testportlet-config/testsuite-config/init-param",
062: "addInitParameter", 2);
063: digester.addCallParam(
064: "testportlet-config/testsuite-config/init-param/name",
065: 0);
066: digester.addCallParam(
067: "testportlet-config/testsuite-config/init-param/value",
068: 1);
069:
070: digester.addCallMethod(
071: "testportlet-config/testsuite-config/action-param",
072: "addActionParameter", 2);
073: digester
074: .addCallParam(
075: "testportlet-config/testsuite-config/action-param/name",
076: 0);
077: digester
078: .addCallParam(
079: "testportlet-config/testsuite-config/action-param/value",
080: 1);
081:
082: digester.addCallMethod(
083: "testportlet-config/testsuite-config/render-param",
084: "addRenderParameter", 2);
085: digester
086: .addCallParam(
087: "testportlet-config/testsuite-config/render-param/name",
088: 0);
089: digester
090: .addCallParam(
091: "testportlet-config/testsuite-config/render-param/value",
092: 1);
093:
094: digester.addSetRoot("testportlet-config/testsuite-config",
095: "add");
096:
097: }
098:
099: // Public Methods ----------------------------------------------------------
100:
101: /**
102: * Reads and parses testsuite config file, creates a list of
103: * <code>TestConfig</code> objects.
104: *
105: * @param in the input stream of the testsuite config file.
106: * @return a list of <code>TestConfig</code> objects.
107: * @throws SAXException if a parsing error occurs.
108: * @throws IOException if an IO error occurs.
109: * @see TestConfig
110: */
111: public List createTestConfigs(InputStream in) throws SAXException,
112: IOException {
113: return (List) digester.parse(in);
114: }
115:
116: }
|