001: package fitnesse.runner;
002:
003: import java.io.IOException;
004: import java.net.URISyntaxException;
005: import java.util.ArrayList;
006: import java.util.Iterator;
007: import java.util.List;
008: import java.util.Properties;
009:
010: import fitnesse.FitNesse;
011:
012: public class FitnessRunner {
013: private int port;
014:
015: private String pageRootDir = "";
016:
017: private String logDirectory;
018:
019: private int pageVersionExpirationDays;
020:
021: private Properties properties;
022:
023: private FitNesse fitnesse;
024:
025: private String suiteName = "IntegrationTests";
026:
027: private String outputDirectory = "target/stiq-results";
028:
029: private String startPage = "";
030:
031: public void setOutputDirectory(String outputDirectory) {
032: this .outputDirectory = outputDirectory;
033: }
034:
035: public static void main(String[] arg) throws Exception {
036: FitnessRunner runner = new FitnessRunner();
037: runner.setPort(Integer.parseInt(arg[0]));
038: runner.setPageRootDir(arg[1]);
039: runner.setStartPage(arg[2]);
040: runner.setSuiteName(arg[3]);
041: runner.setOutputDirectory(arg[4]);
042: System.out.println("Starting Fitness and stiq");
043: boolean success = runner.runFitnessAndStiq();
044: if (!success) {
045: System.out.println("FAILED");
046: System.exit(-9);
047: } else {
048: System.out.println("PASSED");
049: System.exit(0);
050: }
051: }
052:
053: public boolean runFitnessAndStiq() throws Exception {
054: FitNesse fitnesse = run();
055: try {
056: System.out.println("Starting browser");
057: return launchSTIQ();
058: } finally {
059: fitnesse.stop();
060: }
061: }
062:
063: public FitNesse run() throws Exception {
064: List argsList = new ArrayList();
065:
066: // Port
067: argsList.add("-p");
068: argsList.add(String.valueOf(port));
069:
070: // Page Root Directory
071: if (pageRootDir == null) {
072: throw new IllegalArgumentException(
073: "Fitness page root directory (e.g., repository) must not be null.");
074: }
075: argsList.add("-r");
076: argsList.add(pageRootDir);
077:
078: if (logDirectory != null) {
079: argsList.add("-l");
080: argsList.add(logDirectory);
081: }
082:
083: argsList.add("-e");
084: argsList.add(String.valueOf(pageVersionExpirationDays));
085:
086: // Always omit updates.
087: // We don't want this because it copies duplicate stuff into the files dir,
088: // adds unneeded page properties, etc. See fitnesse.updates.Updater class.
089: argsList.add("-o");
090:
091: String[] args = (String[]) argsList.toArray(new String[] {});
092:
093: if (properties != null) {
094: for (Iterator i = properties.keySet().iterator(); i
095: .hasNext();) {
096: String key = (String) i.next();
097: String value = (String) properties.get(key);
098: if (value != null) {
099: System.setProperty(key, value);
100: }
101: }
102: }
103: fitnesse = FitNesse.startFitNesse(args);
104: return fitnesse;
105: }
106:
107: public boolean launchSTIQ() throws IOException, URISyntaxException {
108: BrowserLauncher launcher = new BrowserLauncher();
109: launcher.setPort(port);
110: launcher.setSuiteName(suiteName);
111: launcher.setStartPage(startPage);
112: launcher.setResultDirectoryPathname(outputDirectory);
113: return launcher.runStiq();
114: }
115:
116: public void setLogDirectory(String logDirectory) {
117: this .logDirectory = logDirectory;
118: }
119:
120: public void setPageVersionExpirationDays(
121: int pageVersionExpirationDays) {
122: this .pageVersionExpirationDays = pageVersionExpirationDays;
123: }
124:
125: public void setPageRootDir(String pageRootDir) {
126: this .pageRootDir = pageRootDir;
127: }
128:
129: public void setPort(int port) {
130: this .port = port;
131: }
132:
133: public void setProperties(Properties properties) {
134: this .properties = properties;
135: }
136:
137: public void setStartPage(String startPage) {
138: this .startPage = startPage;
139: }
140:
141: public void setSuiteName(String suiteName) {
142: this.suiteName = suiteName;
143: }
144: }
|