PrintWriter pw = new PrintWriter(destFile);
NodeList rs = (NodeList) xpath.evaluate(ADDR_TEST_GROUPS, catalog, XPathConstants.NODESET);
final int rslen = rs.getLength();
for(int i = 0; i < rslen; i++) {
final String ADDR_TEST_GROUP = '(' + ADDR_TEST_GROUPS + ")[" + (i + 1) + ']';
Node testGroup = rs.item(i);
assert (testGroup != null);
assert (testGroup.hasAttributes());
String filepath = (String) xpath.evaluate("ns:test-case[1]/@FilePath", testGroup, XPathConstants.STRING);
if(filepath == null || filepath.length() == 0) {
// test-group might have no test-case
continue;
}
assert (filepath.endsWith("/")) : filepath;
String testDir = filepath.replace('-', '_').toLowerCase().substring(0, filepath.lastIndexOf('/'));
String packageName = testDir.replace('/', '.');
String[] dirs = testDir.split("/");
assert (dirs.length > 0);
File parentDir = new File(TEST_DEST_DIR);
assert (parentDir.isDirectory());
for(String dir : dirs) {
assert (parentDir.exists());
File curDir = new File(parentDir, dir);
if(!curDir.exists()) {
boolean mkdirSucc = curDir.mkdir();
assert (mkdirSucc);
System.err.println("Created directory.. " + curDir.getAbsolutePath());
}
parentDir = curDir;
}
assert (parentDir.exists());
final String CLASS_NAME = toClassName(testGroup.getAttributes().getNamedItem("name").getNodeValue())
+ "Test";
final String CLASS_SRC_FILE = CLASS_NAME + ".java";
File classSrcFile = new File(parentDir, CLASS_SRC_FILE);
if(!classSrcFile.exists()) {
final String tmpl = IOUtils.toString(TestCodeGenerator.class.getResourceAsStream("XQTSTest.template"));