001: /*
002: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: * [See end of file]
005: */
006:
007: package com.hp.hpl.jena.util.junit;
008:
009: import java.util.Iterator;
010:
011: import junit.framework.*;
012: import org.apache.commons.logging.LogFactory;
013:
014: import com.hp.hpl.jena.rdf.model.Resource;
015: import com.hp.hpl.jena.shared.JenaException;
016:
017: public abstract class TestFactoryManifest implements
018: ManifestItemHandler {
019: private TestSuite currentTestSuite = null;
020: private TestSuite testSuite = null;
021:
022: public TestFactoryManifest() {
023: }
024:
025: public TestSuite process(String filename) {
026: return oneManifest(filename);
027: }
028:
029: private TestSuite oneManifest(String filename) {
030: TestSuite ts1 = new TestSuite();
031: Manifest m = null;
032: try {
033: m = new Manifest(filename);
034: } catch (JenaException ex) {
035: LogFactory.getLog(TestFactoryManifest.class).warn(
036: "Failed to load: " + filename + "\n"
037: + ex.getMessage(), ex);
038: ts1.setName("BROKEN");
039: return ts1;
040: }
041: if (m.getName() != null)
042: ts1.setName(TestUtils.safeName(m.getName()));
043: else
044: ts1.setName("Unnamed Manifest");
045:
046: // Recurse
047: for (Iterator iter = m.includedManifests(); iter.hasNext();) {
048: String n = (String) iter.next();
049: TestSuite ts2 = oneManifest(n);
050: currentTestSuite = ts2;
051: ts1.addTest(ts2);
052: }
053:
054: currentTestSuite = ts1;
055: m.apply(this );
056: return ts1;
057: }
058:
059: protected TestSuite getTestSuite() {
060: return currentTestSuite;
061: }
062:
063: /** Handle an item in a manifest */
064: public final boolean processManifestItem(Resource manifest,
065: Resource item, String testName, Resource action,
066: Resource result) {
067: Test t = makeTest(manifest, item, testName, action, result);
068: if (t != null)
069: currentTestSuite.addTest(t);
070: return true;
071: }
072:
073: protected abstract Test makeTest(Resource manifest, Resource item,
074: String testName, Resource action, Resource result);
075:
076: }
077:
078: /*
079: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
080: * All rights reserved.
081: *
082: * Redistribution and use in source and binary forms, with or without
083: * modification, are permitted provided that the following conditions
084: * are met:
085: * 1. Redistributions of source code must retain the above copyright
086: * notice, this list of conditions and the following disclaimer.
087: * 2. Redistributions in binary form must reproduce the above copyright
088: * notice, this list of conditions and the following disclaimer in the
089: * documentation and/or other materials provided with the distribution.
090: * 3. The name of the author may not be used to endorse or promote products
091: * derived from this software without specific prior written permission.
092: *
093: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
094: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
095: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
096: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
097: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
098: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
099: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
100: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
101: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
102: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103: */
|