01: /******************************************************************************
02: * Copyright (C) Lars Ivar Almli. All rights reserved. *
03: * ---------------------------------------------------------------------------*
04: * This file is part of MActor. *
05: * *
06: * MActor is free software; you can redistribute it and/or modify *
07: * it under the terms of the GNU General Public License as published by *
08: * the Free Software Foundation; either version 2 of the License, or *
09: * (at your option) any later version. *
10: * *
11: * MActor is distributed in the hope that it will be useful, *
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14: * GNU General Public License for more details. *
15: * *
16: * You should have received a copy of the GNU General Public License *
17: * along with MActor; if not, write to the Free Software *
18: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
19: ******************************************************************************/package org.mactor.ui;
20:
21: import java.io.File;
22: import java.util.LinkedList;
23: import java.util.List;
24: import org.mactor.framework.HtmlLogFeedBackListener;
25: import org.mactor.framework.HtmlTestSuiteParser;
26: import org.mactor.framework.MactorException;
27: import org.mactor.framework.TestData;
28: import org.mactor.framework.TestSuiteRunner;
29: import org.mactor.framework.spec.TestSpec;
30:
31: /**
32: * MActor command line runner
33: *
34: * @author Lars Ivar Almli
35: */
36: public class TestSuiteRunnerCmd {
37: public static void main(String[] args) {
38: if (args.length != 2) {
39: System.out
40: .println("Usage: TestSuiteRunnerCmd <html input file> <log dir>");
41: System.exit(1);
42: }
43: try {
44: File outDir = new File(args[1]);
45: if (!outDir.exists() || !outDir.isDirectory())
46: throw new MactorException(
47: "The specified output log directory '"
48: + args[1] + "' does not exist");
49: List<HtmlTestSuiteParser> parsed = HtmlTestSuiteParser
50: .parseFile(args[0]);
51: List<TestSuiteRunner> runners = new LinkedList<TestSuiteRunner>();
52: // to force init validations:
53: for (HtmlTestSuiteParser parser : parsed) {
54: runners.add(new TestSuiteRunner(
55: TestSpec.loadFromFile(new File(parser
56: .getTestSpecPath()))));
57: }
58: int totalTestCount = 0;
59: // run:
60: int i = 0;
61: for (TestSuiteRunner runner : runners) {
62: TestData data = parsed.get(i).getData();
63: TestSpec spec = runner.getTestSpec();
64: HtmlLogFeedBackListener fl = new HtmlLogFeedBackListener(
65: data);
66: int currentErrorCount = runner.run(data, fl);
67: fl.writeLogAsHtml(new File(outDir.getAbsolutePath()
68: + "/log_"
69: + spec.getName().replace('/', '_').replace(
70: '\\', '_').replace(' ', '_') + "_"
71: + System.currentTimeMillis() + ".html"));
72: if (currentErrorCount > 0) {
73: System.err.println("Test-set for spec '"
74: + spec.getName() + "' failed '"
75: + currentErrorCount + "' of '"
76: + data.getRowCount() + "' times");
77: System.exit(1);
78: }
79: i++;
80: totalTestCount += data.getRowCount();
81: }
82: System.out.println("All '" + totalTestCount
83: + "' tests completed with success");
84: System.exit(0);
85: // new TestSuiteRunner().
86: } catch (Exception e) {
87: System.err.println("Failed to run tests. Error:"
88: + e.getMessage());
89: e.printStackTrace();
90: System.exit(1);
91: }
92: }
93: }
|