|
1
|
|
/*
|
|
2
|
|
* JBind
|
|
3
|
|
*
|
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
|
5
|
|
*
|
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
|
8
|
|
* 'Apache Software License V 1.1'.
|
|
9
|
|
*/
|
|
10
|
|
/*
|
|
11
|
|
* ConvertSunTests.java
|
|
12
|
|
*
|
|
13
|
|
* Created on 29. Juli 2002, 16:45
|
|
14
|
|
*/
|
|
15
|
|
|
|
16
|
|
package org.jbind.xml.test;
|
|
17
|
|
|
|
18
|
|
import java.io.File;
|
|
19
|
|
|
|
20
|
|
import junit.framework.Test;
|
|
21
|
|
import junit.framework.TestResult;
|
|
22
|
|
import junit.framework.TestSuite;
|
|
23
|
|
import junit.textui.TestRunner;
|
|
24
|
|
|
|
25
|
|
import org.jbind.base.Console;
|
|
26
|
|
import org.jbind.xml.Config;
|
|
27
|
|
import org.jbind.xml.core.bridge.IRegEx;
|
|
28
|
|
|
|
29
|
|
/**
|
|
30
|
|
*
|
|
31
|
|
* @author swachter
|
|
32
|
|
*/
|
|
33
|
|
public class CreateSunTestSuite {
|
|
34
|
|
|
|
35
|
|
public static final String TEST_DIR = "testDir";
|
|
36
|
|
|
|
37
|
|
/** Creates a new instance of ConvertSunTests */
|
|
38
|
0
|
public CreateSunTestSuite() {}
|
|
39
|
|
|
|
40
|
0
|
private static void usage() {
|
|
41
|
0
|
Console.out("CreateSunTestSuite -testDir <dir>");
|
|
42
|
|
}
|
|
43
|
|
|
|
44
|
0
|
public static void main(String[] anArgs) {
|
|
45
|
0
|
String testDir = null;
|
|
46
|
0
|
for (int i = 0; i < anArgs.length; i++) {
|
|
47
|
0
|
String a = anArgs[i];
|
|
48
|
0
|
if ("-testDir".equals(a)) {
|
|
49
|
0
|
testDir = anArgs[++i];
|
|
50
|
|
} else {
|
|
51
|
0
|
usage();
|
|
52
|
0
|
System.exit(-1);
|
|
53
|
|
}
|
|
54
|
|
}
|
|
55
|
0
|
System.getProperties().setProperty(TEST_DIR, testDir);
|
|
56
|
|
|
|
57
|
0
|
try {
|
|
58
|
0
|
String[] args = new String[]{ CreateSunTestSuite.class.getName() };
|
|
59
|
0
|
MyTestRunner testRunner = new MyTestRunner();
|
|
60
|
0
|
TestResult r = testRunner.start(args);
|
|
61
|
0
|
if (!r.wasSuccessful()) {
|
|
62
|
0
|
System.exit(-1);
|
|
63
|
|
}
|
|
64
|
0
|
System.exit(0);
|
|
65
|
|
} catch (Exception e) {
|
|
66
|
0
|
System.err.println(e.getMessage());
|
|
67
|
0
|
System.exit(-2);
|
|
68
|
|
}
|
|
69
|
|
}
|
|
70
|
|
|
|
71
|
|
private static class MyTestRunner extends TestRunner {
|
|
72
|
0
|
public MyTestRunner() {}
|
|
73
|
0
|
public TestResult start(String[] anArgs) throws Exception {
|
|
74
|
0
|
return super.start(anArgs);
|
|
75
|
|
}
|
|
76
|
|
}
|
|
77
|
|
|
|
78
|
1
|
public static Test suite() throws Exception {
|
|
79
|
1
|
String testDirName = System.getProperty(TEST_DIR);
|
|
80
|
1
|
if (null == testDirName) {
|
|
81
|
0
|
Console.err("system property " + TEST_DIR + " missing");
|
|
82
|
0
|
System.exit(1);
|
|
83
|
|
}
|
|
84
|
|
|
|
85
|
1
|
TestSuite testSuite = new TestSuite();
|
|
86
|
|
|
|
87
|
1
|
File testDir = new File(testDirName);
|
|
88
|
1
|
String[] files = testDir.list();
|
|
89
|
|
|
|
90
|
1
|
if (null == files) {
|
|
91
|
0
|
return testSuite;
|
|
92
|
|
}
|
|
93
|
|
|
|
94
|
1
|
IRegEx invalidSchemaPattern = Config.instance.createRegEx(".*\\.e\\.xsd");
|
|
95
|
1
|
IRegEx schemaPattern = Config.instance.createRegEx(".*\\.xsd");
|
|
96
|
|
|
|
97
|
1
|
for (int i = 0; i < files.length; i++) {
|
|
98
|
206
|
String file = files[i];
|
|
99
|
206
|
TestSuite suite = null;
|
|
100
|
206
|
if (invalidSchemaPattern.matches(file)) {
|
|
101
|
21
|
File schemaFile = new File(testDir, file);
|
|
102
|
21
|
suite = new ScenarioSuite(schemaFile.toString());
|
|
103
|
21
|
suite.addTest(new SchemaTest(schemaFile, false));
|
|
104
|
|
} else {
|
|
105
|
185
|
if (schemaPattern.matches(file)) {
|
|
106
|
22
|
File schemaFile = new File(testDir, file);
|
|
107
|
22
|
suite = new ScenarioSuite(schemaFile.toString());
|
|
108
|
22
|
suite.addTest(new SchemaTest(schemaFile, true));
|
|
109
|
22
|
String schemaPrefix = file.substring(0, file.length() - 4);
|
|
110
|
22
|
IRegEx validInstance = Config.instance.createRegEx(schemaPrefix + "\\.v.*\\.xml");
|
|
111
|
22
|
IRegEx invalidInstance = Config.instance.createRegEx(schemaPrefix + "\\.n.*\\.xml");
|
|
112
|
22
|
for (int j = 0; j < files.length; j++) {
|
|
113
|
4532
|
String s = files[j];
|
|
114
|
4532
|
if (validInstance.matches(s)) {
|
|
115
|
31
|
suite.addTest(new SimpleInstanceTest(new File(testDir, s), true));
|
|
116
|
4501
|
} else if (invalidInstance.matches(s)) {
|
|
117
|
125
|
suite.addTest(new SimpleInstanceTest(new File(testDir, s), false));
|
|
118
|
|
}
|
|
119
|
|
}
|
|
120
|
|
}
|
|
121
|
|
}
|
|
122
|
206
|
if (null != suite) {
|
|
123
|
43
|
testSuite.addTest(suite);
|
|
124
|
|
}
|
|
125
|
|
}
|
|
126
|
|
|
|
127
|
1
|
return testSuite;
|
|
128
|
|
}
|
|
129
|
|
|
|
130
|
|
}
|
|
131
|
|
|