KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > junit > TestSrcContent


1 /*
2  * Copyright 2003, 2004 The 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  
17 package org.apache.ws.jaxme.xs.junit;
18
19 import junit.framework.TestCase;
20
21 import java.io.File JavaDoc;
22 import java.util.Enumeration JavaDoc;
23 import java.util.zip.ZipEntry JavaDoc;
24 import java.util.zip.ZipFile JavaDoc;
25
26 import org.apache.ws.jaxme.xs.XSParser;
27 import org.xml.sax.InputSource JavaDoc;
28
29
30 public class TestSrcContent extends TestCase {
31   public TestSrcContent(String JavaDoc name) {
32     super(name);
33   }
34
35   public void testSourceFiles() throws Exception JavaDoc {
36     String JavaDoc path = System.getProperty("xstc.zip.file");
37     if (path == null || "".equals(path)) {
38       fail("The property xstc.zip.file is not set.");
39     }
40     File JavaDoc f = new File JavaDoc(path);
41     if (!f.exists() || !f.isFile()) {
42       fail("The file " + f.getAbsolutePath() +
43            ", given by property xstc.zip.file, does not exist ");
44     }
45
46     int passXSDFiles = 0;
47     int failXSDFiles = 0;
48
49     ZipFile JavaDoc zipFile = new ZipFile JavaDoc(f);
50     for (Enumeration JavaDoc en = zipFile.entries(); en.hasMoreElements(); ) {
51       ZipEntry JavaDoc entry = (ZipEntry JavaDoc) en.nextElement();
52       if (entry.isDirectory()) {
53         continue;
54       }
55       String JavaDoc name = entry.getName();
56       if (!name.endsWith(".xsd")) {
57         continue;
58       }
59
60       InputSource JavaDoc iSource = new InputSource JavaDoc(zipFile.getInputStream(entry));
61       iSource.setSystemId(name);
62       System.out.print(name);
63       XSParser parser = new XSParser();
64       parser.setValidating(false);
65       try {
66         parser.parseSyntax(iSource);
67         passXSDFiles++;
68         System.out.println(": PASS");
69       } catch (Exception JavaDoc e) {
70         failXSDFiles++;
71         System.out.println(": FAIL");
72         e.printStackTrace(System.out);
73       }
74     }
75
76     System.out.println();
77     System.out.println();
78     System.out.println("Total files = " + (passXSDFiles + failXSDFiles));
79     System.out.println("Passed = " + passXSDFiles);
80     System.out.println("Failed = " + failXSDFiles);
81   }
82
83   public static void main(String JavaDoc[] args) throws Exception JavaDoc {
84     TestSrcContent testSrcContent = new TestSrcContent(TestSrcContent.class.getName());
85     testSrcContent.testSourceFiles();
86   }
87 }
88
Popular Tags