|
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
|
|
package org.jbind.xml.test;
|
|
11
|
|
|
|
12
|
|
import java.io.File;
|
|
13
|
|
import java.util.ArrayList;
|
|
14
|
|
import java.util.Iterator;
|
|
15
|
|
import java.util.List;
|
|
16
|
|
|
|
17
|
|
import junit.framework.Test;
|
|
18
|
|
import junit.framework.TestResult;
|
|
19
|
|
import junit.framework.TestSuite;
|
|
20
|
|
import junit.textui.TestRunner;
|
|
21
|
|
|
|
22
|
|
import org.jbind.base.Console;
|
|
23
|
|
import org.jbind.xml.Config;
|
|
24
|
|
import org.jbind.xml.core.bridge.IRegEx;
|
|
25
|
|
import org.xml.sax.Attributes;
|
|
26
|
|
import org.xml.sax.helpers.DefaultHandler;
|
|
27
|
|
|
|
28
|
|
/**
|
|
29
|
|
*
|
|
30
|
|
* @author swachter
|
|
31
|
|
*/
|
|
32
|
|
public class CreateMsTestSuite {
|
|
33
|
|
|
|
34
|
|
public static final String TEST_DIR = "testDir";
|
|
35
|
|
|
|
36
|
|
/** Creates a new instance of ConvertSunTests */
|
|
37
|
0
|
public CreateMsTestSuite() {}
|
|
38
|
|
|
|
39
|
0
|
private static void usage() {
|
|
40
|
0
|
Console.out("CreateMsTestSuite -testDir <dir>");
|
|
41
|
|
}
|
|
42
|
|
|
|
43
|
0
|
public static void main(String[] anArgs) {
|
|
44
|
0
|
String testDir = null;
|
|
45
|
0
|
for (int i = 0; i < anArgs.length; i++) {
|
|
46
|
0
|
String a = anArgs[i];
|
|
47
|
0
|
if ("-testDir".equals(a)) {
|
|
48
|
0
|
testDir = anArgs[++i];
|
|
49
|
|
} else {
|
|
50
|
0
|
usage();
|
|
51
|
0
|
System.exit(-1);
|
|
52
|
|
}
|
|
53
|
|
}
|
|
54
|
0
|
System.getProperties().setProperty(TEST_DIR, testDir);
|
|
55
|
|
|
|
56
|
0
|
try {
|
|
57
|
0
|
String[] args = new String[]{ CreateMsTestSuite.class.getName() };
|
|
58
|
0
|
MyTestRunner testRunner = new MyTestRunner();
|
|
59
|
0
|
TestResult r = testRunner.start(args);
|
|
60
|
0
|
if (!r.wasSuccessful()) {
|
|
61
|
0
|
System.exit(-1);
|
|
62
|
|
}
|
|
63
|
0
|
System.exit(0);
|
|
64
|
|
} catch (Exception e) {
|
|
65
|
0
|
System.err.println(e.getMessage());
|
|
66
|
0
|
System.exit(-2);
|
|
67
|
|
}
|
|
68
|
|
}
|
|
69
|
|
|
|
70
|
|
private static class MyTestRunner extends TestRunner {
|
|
71
|
0
|
public MyTestRunner() {}
|
|
72
|
0
|
public TestResult start(String[] anArgs) throws Exception {
|
|
73
|
0
|
return super.start(anArgs);
|
|
74
|
|
}
|
|
75
|
|
}
|
|
76
|
|
|
|
77
|
1
|
public static Test suite() throws Exception {
|
|
78
|
1
|
TestSuite res = new TestSuite();
|
|
79
|
|
|
|
80
|
1
|
String testDirName = System.getProperty(TEST_DIR);
|
|
81
|
1
|
if (null == testDirName) {
|
|
82
|
0
|
Console.err("system property " + TEST_DIR + " missing");
|
|
83
|
0
|
System.exit(1);
|
|
84
|
|
}
|
|
85
|
|
|
|
86
|
1
|
File testDir = new File(testDirName);
|
|
87
|
|
|
|
88
|
1
|
String files[] = testDir.list();
|
|
89
|
|
|
|
90
|
1
|
if (null == files) {
|
|
91
|
0
|
return res;
|
|
92
|
|
}
|
|
93
|
|
|
|
94
|
1
|
IRegEx p = Config.instance.createRegEx(".*_LTGfmt\\.xml");
|
|
95
|
|
|
|
96
|
1
|
for (int idx = 0; idx < files.length; idx++) {
|
|
97
|
12
|
String file = files[idx];
|
|
98
|
|
|
|
99
|
12
|
if (!p.matches(file)) {
|
|
100
|
11
|
continue;
|
|
101
|
|
}
|
|
102
|
|
|
|
103
|
1
|
TestSuite testSuite = new TestSuite();
|
|
104
|
|
|
|
105
|
1
|
File testInfosFile = new File(testDir, file);
|
|
106
|
|
|
|
107
|
1
|
javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance();
|
|
108
|
1
|
factory.setNamespaceAware(false);
|
|
109
|
1
|
factory.setValidating(false);
|
|
110
|
1
|
javax.xml.parsers.SAXParser parser = factory.newSAXParser();
|
|
111
|
1
|
Description description = new Description();
|
|
112
|
1
|
parser.parse(testInfosFile.toURL().toString(), description);
|
|
113
|
|
|
|
114
|
1
|
for (Iterator i = description.testInfos.iterator(); i.hasNext(); ) {
|
|
115
|
105
|
TestInfo testInfo = (TestInfo)i.next();
|
|
116
|
105
|
TestSuite schemaSuite = new ScenarioSuite(testInfo.id);
|
|
117
|
105
|
Test schemaTest = null;
|
|
118
|
105
|
for (Iterator j = testInfo.fileInfos.iterator(); j.hasNext(); ) {
|
|
119
|
134
|
FileInfo fileInfo = (FileInfo)j.next();
|
|
120
|
134
|
if (fileInfo.isSchema) {
|
|
121
|
|
assert null == schemaTest;
|
|
122
|
105
|
schemaTest = new SchemaTest(new File(new File(testDir, fileInfo.folder), fileInfo.name), fileInfo.validity);
|
|
123
|
105
|
schemaSuite.addTest(schemaTest);
|
|
124
|
105
|
j.remove();
|
|
125
|
|
}
|
|
126
|
|
}
|
|
127
|
105
|
for (Iterator j = testInfo.fileInfos.iterator(); j.hasNext(); ) {
|
|
128
|
29
|
FileInfo fileInfo = (FileInfo)j.next();
|
|
129
|
29
|
if (fileInfo.isInstance) {
|
|
130
|
28
|
schemaSuite.addTest(new SimpleInstanceTest(new File(new File(testDir, fileInfo.folder), fileInfo.name), fileInfo.validity));
|
|
131
|
|
}
|
|
132
|
|
}
|
|
133
|
105
|
testSuite.addTest(schemaSuite);
|
|
134
|
|
|
|
135
|
|
}
|
|
136
|
|
|
|
137
|
1
|
res.addTest(testSuite);
|
|
138
|
|
}
|
|
139
|
|
|
|
140
|
1
|
return res;
|
|
141
|
|
}
|
|
142
|
|
|
|
143
|
|
private static class Description extends DefaultHandler {
|
|
144
|
|
|
|
145
|
|
public List testInfos = new ArrayList();
|
|
146
|
|
private TestInfo myTestInfo = null;
|
|
147
|
450
|
public void startElement(String aUri, String aLocalName, String aQName, Attributes anAttributes) {
|
|
148
|
450
|
if ("test".equals(aQName)) {
|
|
149
|
105
|
myTestInfo = new TestInfo(anAttributes.getValue("id"));
|
|
150
|
105
|
testInfos.add(myTestInfo);
|
|
151
|
345
|
} else if ("file".equals(aQName)) {
|
|
152
|
134
|
FileInfo fileInfo = new FileInfo(anAttributes.getValue("folder"), anAttributes.getValue("fileName"), anAttributes.getValue("validity"), anAttributes.getValue("role"));
|
|
153
|
134
|
myTestInfo.fileInfos.add(fileInfo);
|
|
154
|
211
|
} else if ("tests".equals(aQName)) {}
|
|
155
|
210
|
else if ("description".equals(aQName)) {}
|
|
156
|
105
|
else if ("files".equals(aQName)) {}
|
|
157
|
|
else {
|
|
158
|
0
|
Console.err("ignoring unexpected element: " + aQName);
|
|
159
|
|
}
|
|
160
|
|
}
|
|
161
|
|
}
|
|
162
|
|
|
|
163
|
|
private static class TestInfo {
|
|
164
|
105
|
public TestInfo(String anId) {
|
|
165
|
105
|
id = anId;
|
|
166
|
|
}
|
|
167
|
|
public String id = null;
|
|
168
|
|
public List fileInfos = new ArrayList();
|
|
169
|
|
}
|
|
170
|
|
|
|
171
|
|
private static class FileInfo {
|
|
172
|
|
|
|
173
|
|
public String folder = null;
|
|
174
|
|
public String name = null;
|
|
175
|
|
public boolean validity;
|
|
176
|
|
public boolean isSchema = false;
|
|
177
|
|
public boolean isInstance = false;
|
|
178
|
134
|
public FileInfo(String aFolder, String aName, String aValidity, String aRole) {
|
|
179
|
|
assert (null != aFolder) && (null != aName) && (null != aValidity);
|
|
180
|
134
|
folder = aFolder;
|
|
181
|
134
|
name = aName;
|
|
182
|
134
|
validity = aValidity.equals("1");
|
|
183
|
134
|
if ("schema".equals(aRole)) {
|
|
184
|
105
|
isSchema = true;
|
|
185
|
29
|
} else if ("instance".equals(aRole)) {
|
|
186
|
28
|
isInstance = true;
|
|
187
|
1
|
} else if ("resource".equals(aRole)) {}
|
|
188
|
|
else {
|
|
189
|
|
assert false : "unknown role: " + aRole;
|
|
190
|
|
}
|
|
191
|
|
}
|
|
192
|
|
}
|
|
193
|
|
}
|
|
194
|
|
|