Show FitTest.java syntax highlighted
package ca.ucalgary.cpsc.ebe.fitClipse.runner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import ca.ucalgary.cpsc.ebe.fitClipse.DeveloperCoordinator;
import ca.ucalgary.cpsc.ebe.fitClipse.ICoordinator;
import ca.ucalgary.cpsc.ebe.fitClipse.connector.BeanConnector;
import ca.ucalgary.cpsc.ebe.fitClipse.connector.MaseSystem;
//import fitEditor.FitView;
public class FitTest implements Serializable{
private String command = "java -classpath";
private String classPath = "";
private String sourceFile= null;
private String resultFile= null;
private static final Pattern regex = Pattern.compile("([0-9]+) right, ([0-9]+) wrong, ([0-9]+) ignored, ([0-9]+) exceptions");
private int numRight = 0;
private int numWrong = 0;
private int numIgnored = 0;
private int numExceptions = 0;
private String testOutput = "";
private String testName = "";
private String testHtml = "";
private Date startTime = null;
private Date endTime = null;
private int executionTime; //in milliseconds
private String content = null;
public FitTest(String classPath, String sourceFile, String resultFile){
this.resultFile = resultFile;
this.sourceFile = sourceFile;
command=command+ " " +classPath+" fit.TestRunner "+sourceFile+" "+resultFile;
}
public void run(){
Runtime run = Runtime.getRuntime();
BufferedReader in = null;
try {
startTime = new Date(); //record the start time
System.out.println("the command: " + command);
Process p = run.exec(command);
StreamReaderThread errStream = new StreamReaderThread(p.getErrorStream());
StreamReaderThread outStream = new StreamReaderThread(p.getInputStream());
errStream.start();
outStream.start();
try {
p.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
endTime = new Date();
String testStats = errStream.getOutput();
this.testOutput = outStream.getOutput();
System.out.println("Test Output: ");
System.out.println("-----------------------------");
System.out.println(this.testOutput);
System.out.println("-----------------------------");
parseStats(testStats);
FileManager files= new FileManager();
this.testHtml = files.readFile(resultFile);
//persist to mase system.
// BeanConnector connector = BeanConnector.getBeanConnector();
// connector.persistFitTest(this);
// System.out.println("Num Exceptions: " + this.numExceptions);
// System.out.println("Num Right: " + this.numRight);
// System.out.println("Num Wrong: " + this.numWrong);
// System.out.println("Num Ignored: " + this.numIgnored);
// System.out.println("Output Captured: '" + this.testOutput + "'");
//
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void parseStats(String stats){
System.out.println("stats: " + stats);
Matcher match = regex.matcher(stats);
if(match.find()){
this.numRight = Integer.parseInt(match.group(1));
this.numWrong = Integer.parseInt(match.group(2));
this.numIgnored= Integer.parseInt(match.group(3));
this.numExceptions = Integer.parseInt(match.group(4));
}else{
System.out.println("no match: [" + stats + "]");
}
}
private class StreamReaderThread extends Thread{
StringBuffer result = new StringBuffer();
InputStream in = null;
public StreamReaderThread(InputStream in){
this.in = in;
}
public void run(){
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line= null;
try {
while((line = reader.readLine())!= null){
result.append(line).append("\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getOutput(){
return result.toString();
}
}
public String getTestName(){
return this.testName;
}
public void setTestName(String name){
this.testName = name;
}
public int getNumExceptions() {
return numExceptions;
}
public int getNumIgnored() {
return numIgnored;
}
public int getNumRight() {
return numRight;
}
public int getNumWrong() {
return numWrong;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public int getExecutionTime() {
return executionTime;
}
public void setExecutionTime(int executionTime) {
this.executionTime = executionTime;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public String getTestOutput() {
return testOutput;
}
public void setTestOutput(String testOutput) {
this.testOutput = testOutput;
}
public void setNumExceptions(int numExceptions) {
this.numExceptions = numExceptions;
}
public void setNumIgnored(int numIgnored) {
this.numIgnored = numIgnored;
}
public void setNumRight(int numRight) {
this.numRight = numRight;
}
public void setNumWrong(int numWrong) {
this.numWrong = numWrong;
}
public String getTestHtml() {
return testHtml;
}
public void setTestHtml(String testHtml) {
this.testHtml = testHtml;
}
public String getResultFile() {
return resultFile;
}
public void setResultFile(String resultFile) {
this.resultFile = resultFile;
}
public String getSourceFile() {
return sourceFile;
}
public void setSourceFile(String sourceFile) {
this.sourceFile = sourceFile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
See more files for this project here