Home | History | Annotate | Download | only in domts
      1 /*
      2  * Copyright (c) 2001-2004 World Wide Web Consortium,
      3  * (Massachusetts Institute of Technology, Institut National de
      4  * Recherche en Informatique et en Automatique, Keio University). All
      5  * Rights Reserved. This program is distributed under the W3C's Software
      6  * Intellectual Property License. This program is distributed in the
      7  * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
      8  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
      9  * PURPOSE.
     10  * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     11  */
     12 
     13 package org.w3c.domts;
     14 
     15 import java.lang.reflect.Constructor;
     16 import java.lang.reflect.InvocationTargetException;
     17 
     18 import junit.framework.TestCase;
     19 import junit.framework.TestSuite;
     20 
     21 public class JUnitTestSuiteAdapter extends TestSuite implements DOMTestSink  {
     22 
     23   private DOMTestSuite test;
     24 
     25   public JUnitTestSuiteAdapter(DOMTestSuite test) {
     26     super(test.getTargetURI());
     27     this.test = test;
     28     test.build(this);
     29   }
     30 
     31   public void addTest(Class testclass) {
     32     DOMTestDocumentBuilderFactory factory = test.getFactory();
     33     try {
     34       Constructor testConstructor = testclass.getConstructor(
     35           new Class[] { DOMTestDocumentBuilderFactory.class } );
     36         //
     37         //   since this is done with reflection
     38         //     any exception on construction is wrapped with
     39         //     an InvocationTargetException and must be unwrapped
     40       Object domtest;
     41       try {
     42         domtest = testConstructor.newInstance(new Object[] { factory });
     43       } catch(InvocationTargetException ex) {
     44         throw ex.getTargetException();
     45       }
     46 
     47       if(domtest instanceof DOMTestCase) {
     48         TestCase test = new JUnitTestCaseAdapter((DOMTestCase) domtest);
     49         addTest(test);
     50       }
     51       else {
     52         if(domtest instanceof DOMTestSuite) {
     53           TestSuite test = new JUnitTestSuiteAdapter((DOMTestSuite) domtest);
     54           addTest(test);
     55         }
     56       }
     57     }
     58     catch(Throwable ex) {
     59       if(!(ex instanceof DOMTestIncompatibleException)) {
     60         ex.printStackTrace();
     61       }
     62     }
     63   }
     64 }
     65