1   /**
2    * Copyright 2006 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  package tests.w3c;
17  
18  import junit.framework.Test;
19  import junit.framework.TestSuite;
20  
21  import java.io.File;
22  import java.util.ArrayList;
23  import java.util.List;
24  import java.util.ListIterator;
25  
26  /**
27   * Class to represent a bucket of tests described by a set of .testSet files.
28   * All of the tests described in all of the .testSet files present in the top
29   * level of the directory supplied will be round-trip tested.
30   * Note: Subdirs are not traversed because the .testSet files in the top level
31   * of the xmlschema2002-01-16 bucket describe all the tests in the bucket.   
32   * cmd line parms: arg0 - location of the directory containing .testSet files
33   *                        defaults to ./target/xmlschema2002-01-16
34   *
35   */
36  public class TestW3CSchemaBucket extends TestSuite {
37  
38      private static List allTestSetFiles;
39      
40      // If tests run from cmd line without any args, run the full suite
41      private static String testSetsLocation = "./target/xmlschema2002-01-16";
42  
43      public TestW3CSchemaBucket(String name) {
44          super(name);
45      }
46  
47      public static void main(String[] args) {
48          try {
49              junit.textui.TestRunner.run(TestW3CSchemaBucket.suite());
50          } catch (Exception e) {
51              e.printStackTrace();
52          }
53      }
54  
55  
56      public static Test suite() throws Exception {
57          testSetsLocation =  System.getProperty("W3CTestLocation", testSetsLocation);
58          TestSuite suite = new TestSuite("Test for tests");
59          allTestSetFiles = getTestSetFiles(testSetsLocation);
60          ListIterator li = allTestSetFiles.listIterator();
61          while (li.hasNext()) {
62              Object o = li.next();
63              File testSet = null;
64              if (o instanceof File) {
65                  testSet = (File) o;  
66              }
67              suite.addTest(TestW3CSchemaTestSet.suite(testSet));
68          }
69          return suite;
70      }
71  
72      private static List getTestSetFiles(String testSetsLocation) throws Exception {
73          File dir = new File(testSetsLocation);
74          if (!dir.isDirectory()) {
75              throw new Exception ("testSet files location must be a directory");
76          }
77          ArrayList testSetFiles = new ArrayList();
78          File[] files = dir.listFiles();
79          for (int i = 0; i < files.length; i++) {
80              if (files[i].getAbsolutePath().endsWith("testSet")) {
81                  testSetFiles.add(files[i]);
82              }
83          }
84          return testSetFiles;
85      }
86  }