View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package tests.w3c;
20  
21  import junit.framework.Test;
22  import junit.framework.TestSuite;
23  
24  import java.io.File;
25  import java.util.ArrayList;
26  import java.util.List;
27  import java.util.ListIterator;
28  
29  /**
30   * Class to represent a bucket of tests described by a set of .testSet files.
31   * All of the tests described in all of the .testSet files present in the top
32   * level of the directory supplied will be round-trip tested.
33   * Note: Subdirs are not traversed because the .testSet files in the top level
34   * of the xmlschema2002-01-16 bucket describe all the tests in the bucket.   
35   * cmd line parms: arg0 - location of the directory containing .testSet files
36   *                        defaults to ./target/xmlschema2002-01-16
37   *
38   */
39  public class TestW3CSchemaBucket extends TestSuite {
40  
41      private static List allTestSetFiles;
42      
43      // If tests run from cmd line without any args, run the full suite
44      private static String testSetsLocation = "./target/xmlschema2002-01-16";
45  
46      public TestW3CSchemaBucket(String name) {
47          super(name);
48      }
49  
50      public static void main(String[] args) {
51          try {
52              junit.textui.TestRunner.run(TestW3CSchemaBucket.suite());
53          } catch (Exception e) {
54              e.printStackTrace();
55          }
56      }
57  
58  
59      public static Test suite() throws Exception {
60          testSetsLocation =  System.getProperty("W3CTestLocation", testSetsLocation);
61          TestSuite suite = new TestSuite("Test for tests");
62          allTestSetFiles = getTestSetFiles(testSetsLocation);
63          ListIterator li = allTestSetFiles.listIterator();
64          while (li.hasNext()) {
65              Object o = li.next();
66              File testSet = null;
67              if (o instanceof File) {
68                  testSet = (File) o;  
69              }
70              suite.addTest(TestW3CSchemaTestSet.suite(testSet));
71          }
72          return suite;
73      }
74  
75      private static List getTestSetFiles(String testSetsLocation) throws Exception {
76          File dir = new File(testSetsLocation);
77          if (!dir.isDirectory()) {
78              throw new Exception ("testSet files location must be a directory");
79          }
80          ArrayList testSetFiles = new ArrayList();
81          File[] files = dir.listFiles();
82          for (int i = 0; i < files.length; i++) {
83              if (files[i].getAbsolutePath().endsWith("testSet")) {
84                  testSetFiles.add(files[i]);
85              }
86          }
87          return testSetFiles;
88      }
89  }