SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

77 lines
2.4 KiB

package de.superx.bin;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import org.apache.commons.io.FileUtils;
import org.xml.sax.SAXException;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebTable;
import de.memtext.util.StringUtils;
public class SxTestXmlCreator {
public static void main(String args[]) {
if (args.length != 1) {
System.out.println("usage SxTestXmlCreator filename (which contains url or sql)");
System.exit(-1);
}
try {
File f = new File(args[0]);
createTestXml(f);
} catch (Exception e) {
System.out.println(e);
}
}
private static void createTestXml(File f) throws MalformedURLException, IOException, SAXException {
String input = StringUtils.readFile(f);
//if (input.startsWith("http"))
String url = input;
WebConversation wc = new WebConversation();
WebRequest req = new GetMethodWebRequest(url);
WebResponse resp = wc.getResponse(req);
if (resp.getTables().length == 0) {
System.out.println("Keine Tabelle geliefert\n" + resp.getText());
System.exit(1);
}
WebTable table = resp.getTables()[1];
String params = url.substring(url.indexOf("?") + 1);
params = params.trim();
if (params.charAt(params.length() - 1) == '\n') params = params.substring(0, params.length() - 2);
StringBuffer erg = new StringBuffer("<webtest name=\"\">\n <params><![CDATA[" + params + "]]></params>\n");
for (int col = 0; col < table.getColumnCount(); col++) {
for (int row = 0; row < table.getRowCount(); row++) {
String val = table.getTableCell(row, col).getText();
//wenn \n vorkommt test auskommentieren
if (val.indexOf("\n") > -1) erg.append("<!-- ");
erg.append("<valuetest row=\"" + (row + 1) + "\" col=\"" + (col + 1) + "\" val=\"" + val + "\"/>\n");
if (val.indexOf("\n") > -1) erg.append(" -->");
}
}
erg.append("</webtest>\n");
FileUtils.writeStringToFile(new File("temp.xml"), erg.toString());
System.out.println("XML ist in temp.xml");
}
}
//Created on 27.04.2006 at 14:47:18