fitnesse.testsystems.slim.tables.TableTable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse Show documentation
Show all versions of fitnesse Show documentation
The fully integrated standalone wiki, and acceptance testing framework.
// Copyright (C) 2003-2009 by Object Mentor, Inc. All rights reserved.
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.testsystems.slim.tables;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import fitnesse.slim.instructions.Instruction;
import fitnesse.testsystems.ExecutionResult;
import fitnesse.testsystems.TestResult;
import fitnesse.testsystems.TestSummary;
import fitnesse.testsystems.slim.SlimTestContext;
import fitnesse.testsystems.slim.Table;
import fitnesse.testsystems.slim.results.SlimExceptionResult;
import fitnesse.testsystems.slim.results.SlimTestResult;
public class TableTable extends SlimTable {
public TableTable(Table table, String tableId, SlimTestContext slimTestContext) {
super(table, tableId, slimTestContext);
}
@Override
protected String getTableType() {
return ("tableTable");
}
@Override
public List getAssertions() {
SlimAssertion make = constructFixture(getFixtureName());
Instruction doTable = callFunction(getTableName(), "doTable", tableAsList());
return Arrays.asList(make, makeAssertion(doTable, new TableTableExpectation()));
}
public class TableTableExpectation implements SlimExpectation {
@Override
public TestResult evaluateExpectation(Object tableReturn) {
SlimTestResult testResult;
if (tableReturn == null || "null".equals(tableReturn)) {
testResult = SlimTestResult.ignore("No results from table");
table.updateContent(table.getColumnCountInRow(0) - 1, 0, testResult);
} else if (tableReturn instanceof String) {
testResult = SlimTestResult.error((String) tableReturn);
table.updateContent(0, 0, testResult);
} else {
TestSummary testSummary = resizeTableAndEvaluateRows(tableReturn);
getTestContext().increment(testSummary);
testResult = new SlimTestResult(ExecutionResult.getExecutionResult(testSummary));
testResult.setVariables(getSymbolsToStore());
}
getTestContext().increment(testResult.getExecutionResult());
return testResult;
}
@Override
public SlimExceptionResult evaluateException(SlimExceptionResult exceptionResult) {
table.updateContent(0, 0, exceptionResult);
getTestContext().incrementErroredTestsCount();
return exceptionResult;
}
}
@SuppressWarnings("unchecked")
private TestSummary resizeTableAndEvaluateRows(Object returnValue) {
List> tableResults = (List>) returnValue;
extendTable(table, tableResults);
TestSummary testSummary = new TestSummary();
for (int row = 0; row < tableResults.size(); row++)
evaluateRow(tableResults, row, testSummary);
return testSummary;
}
private void extendTable(Table table, List> tableResults) {
addNewRows(table, tableResults);
extendExistingRows(table, tableResults);
}
private void addNewRows(Table table, List> tableResults) {
while (table.getRowCount() - 1 < tableResults.size()) {
List l = new ArrayList<>();
for (Object s : tableResults.get(table.getRowCount() - 1))
l.add((String) s);
table.addRow(l);
}
}
private void extendExistingRows(Table table, List> tableResults) {
for (int row = 1; row < table.getRowCount(); row++)
extendRow(table, row, tableResults.get(row - 1));
}
private void extendRow(Table table, int row, List