Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decision table and script subclass #1099

Merged
merged 4 commits into from Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,36 @@
Scenarios can be called from decision tables. They should respect the actor (i.e. fixture instance) and Slim table type (i.e. script table or a subclass) of the last script created.

!2 When we create a script using Slim's standard script table, the decision table should use that subtype also.

|scenario |my division1|numerator||denominator||expected|
|setNumerator |@numerator |
|setDenominator|@denominator |
|check |quotient |@expected |


Get the Division implementation from the eg package, and use a script subclass that uses 'verify' instead of the 'check' keyword.
|script|eg.Division|



|my division1 |
|numerator|denominator|expected|
|10 |2 |5.0 |


!2 When we create a script using a subclass of Slim's standard script table, the decision table should use that subtype also.

|scenario |my division2|numerator||denominator||expected|
|setNumerator |@numerator |
|setDenominator|@denominator |
|verify |quotient |@expected |


Get the Division implementation from the eg package, and use a script subclass that uses 'verify' instead of the 'check' keyword.
|verify script|eg.Division|



|my division2 |
|numerator|denominator|expected|
|10 |2 |5.0 |
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<properties>
<Edit>true</Edit>
<Files>true</Files>
<Properties>true</Properties>
<RecentChanges>true</RecentChanges>
<Refactor>true</Refactor>
<Search>true</Search>
<Test>true</Test>
<Versions>true</Versions>
<WhereUsed>true</WhereUsed>
</properties>
9 changes: 9 additions & 0 deletions src/fitnesse/testsystems/slim/SlimTestContext.java
Expand Up @@ -8,6 +8,7 @@
import fitnesse.testsystems.TestPage;
import fitnesse.testsystems.TestSummary;
import fitnesse.testsystems.slim.tables.ScenarioTable;
import fitnesse.testsystems.slim.tables.ScriptTable;

public interface SlimTestContext {
String getSymbol(String symbolName);
Expand Down Expand Up @@ -35,4 +36,12 @@ public interface SlimTestContext {
void increment(TestSummary testSummary);

TestPage getPageToTest();

void setCurrentScriptClass(Class<? extends ScriptTable> currentScriptClass);

Class<? extends ScriptTable> getCurrentScriptClass();

void setCurrentScriptActor(String currentScriptActor);

String getCurrentScriptActor();
}
23 changes: 23 additions & 0 deletions src/fitnesse/testsystems/slim/SlimTestContextImpl.java
Expand Up @@ -14,6 +14,7 @@
import fitnesse.testsystems.TestPage;
import fitnesse.testsystems.TestSummary;
import fitnesse.testsystems.slim.tables.ScenarioTable;
import fitnesse.testsystems.slim.tables.ScriptTable;

public class SlimTestContextImpl implements SlimTestContext {
private final Map<String, String> symbols = new HashMap<>();
Expand All @@ -22,6 +23,8 @@ public class SlimTestContextImpl implements SlimTestContext {
private final TestPage pageToTest;
private List<ScenarioTable> scenariosWithInputs = null;
private boolean isSorted = true;
private String currentScriptActor;
private Class<? extends ScriptTable> currentScriptClass = ScriptTable.class;

public SlimTestContextImpl(TestPage pageToTest) {
this.pageToTest = pageToTest;
Expand Down Expand Up @@ -148,4 +151,24 @@ public TestSummary getTestSummary() {
public TestPage getPageToTest() {
return pageToTest;
}

@Override
public void setCurrentScriptClass(Class<? extends ScriptTable> currentScriptClass) {
this.currentScriptClass = currentScriptClass;
}

@Override
public Class<? extends ScriptTable> getCurrentScriptClass() {
return currentScriptClass;
}

@Override
public void setCurrentScriptActor(String currentScriptActor) {
this.currentScriptActor = currentScriptActor;
}

@Override
public String getCurrentScriptActor() {
return currentScriptActor;
}
}
2 changes: 1 addition & 1 deletion src/fitnesse/testsystems/slim/tables/DecisionTable.java
Expand Up @@ -121,7 +121,7 @@ private SlimAssertion callFunctionInRow(String functionName, int row) {
String assignedSymbol = isSymbolAssignment(col, row);
SlimAssertion assertion;
if (assignedSymbol != null) {
assertion= makeAssertion(callAndAssign(assignedSymbol, "scriptTable" + "Actor", "cloneSymbol", "$"+name),
assertion= makeAssertion(callAndAssign(assignedSymbol, getTestContext().getCurrentScriptActor(), "cloneSymbol", "$"+name),
new ReturnedSymbolExpectation(col, row, name, assignedSymbol));
} else {
assertion = makeAssertion(Instruction.NOOP_INSTRUCTION, new ReturnedSymbolExpectation(getDTCellContents(col, row), col, row, name));
Expand Down
28 changes: 21 additions & 7 deletions src/fitnesse/testsystems/slim/tables/ScenarioTable.java
Expand Up @@ -33,8 +33,6 @@
public class ScenarioTable extends SlimTable {
private static final String instancePrefix = "scenarioTable";
private static final String underscorePattern = "\\W_(?=\\W|$)";
// TODO: This property should not be static! This could cause race conditions
private Class<? extends ScriptTable> defaultChildClass = ScriptTable.class;
private String name;
private List<String> inputs = new ArrayList<>();
private Set<String> outputs = new HashSet<>();
Expand Down Expand Up @@ -201,7 +199,7 @@ protected ScriptTable createChild(ScenarioTestContext testContext, SlimTable par
if (parentTable instanceof ScriptTable) {
scriptTable = createChild((ScriptTable) parentTable, newTable, testContext);
} else {
scriptTable = createChild(defaultChildClass, newTable, testContext);
scriptTable = createChild(getTestContext().getCurrentScriptClass(), newTable, testContext);
}
scriptTable.setCustomComparatorRegistry(customComparatorRegistry);
return scriptTable;
Expand All @@ -215,10 +213,6 @@ protected ScriptTable createChild(Class<? extends ScriptTable> parentTableClass,
return SlimTableFactory.createTable(parentTableClass, newTable, id, testContext);
}

public void setDefaultChildClass(Class<? extends ScriptTable> defaultChildClass) {
this.defaultChildClass = defaultChildClass;
}

public List<SlimAssertion> call(String[] args, ScriptTable parentTable, int row) throws TestExecutionException {
Map<String, String> scenarioArguments = new HashMap<>();

Expand Down Expand Up @@ -398,5 +392,25 @@ ExecutionResult getExecutionResult() {
public TestPage getPageToTest() {
return testContext.getPageToTest();
}

@Override
public void setCurrentScriptClass(Class<? extends ScriptTable> currentScriptClass) {
testContext.setCurrentScriptClass(currentScriptClass);
}

@Override
public Class<? extends ScriptTable> getCurrentScriptClass() {
return testContext.getCurrentScriptClass();
}

@Override
public void setCurrentScriptActor(String currentScriptActor) {
testContext.setCurrentScriptActor(currentScriptActor);
}

@Override
public String getCurrentScriptActor() {
return testContext.getCurrentScriptActor();
}
}
}
7 changes: 4 additions & 3 deletions src/fitnesse/testsystems/slim/tables/ScriptTable.java
Expand Up @@ -109,6 +109,7 @@ public List<SlimAssertion> getAssertions() throws TestExecutionException {
List<SlimAssertion> assertions = new ArrayList<>();
// TODO: Should take into account here that a table can be assigned as
if (isTopLevelTable()) {
getTestContext().setCurrentScriptClass(getClass());
List<SlimAssertion> createAssertions = startActor();
if (createAssertions != null) {
assertions.addAll(createAssertions);
Expand Down Expand Up @@ -195,8 +196,6 @@ protected List<SlimAssertion> assertionsFromScenario(int row) throws TestExecuti
}
if (scenario != null) {
scenario.setCustomComparatorRegistry(customComparatorRegistry);
// TODO: ensure our scenario has the right table type
scenario.setDefaultChildClass(getClass());
assertions.addAll(scenario.call(args, this, row));
}
return assertions;
Expand Down Expand Up @@ -299,7 +298,9 @@ protected List<SlimAssertion> startActor(int row) {
protected List<SlimAssertion> startActor(int row, String cellContents, int classNameColumn) {
List<SlimAssertion> assertions = new ArrayList<>();
String className = Disgracer.disgraceClassName(cellContents);
assertions.add(constructInstance(getTableType() + "Actor", className, classNameColumn, row));
String actorName = getTableType() + "Actor";
getTestContext().setCurrentScriptActor(actorName);
assertions.add(constructInstance(actorName, className, classNameColumn, row));
getArgumentsStartingAt(classNameColumn + 1, table.getColumnCountInRow(row) - 1, row, assertions);
return assertions;
}
Expand Down
28 changes: 28 additions & 0 deletions src/fitnesse/testsystems/slim/tables/ScriptTableWithVerify.java
@@ -0,0 +1,28 @@
package fitnesse.testsystems.slim.tables;

import fitnesse.testsystems.slim.SlimTestContext;
import fitnesse.testsystems.slim.Table;

/**
* ScriptTable subclass to use in acceptance test to see that DecisionTable based on scenario respects subclasses
* used in previous script definition.
*/
public class ScriptTableWithVerify extends ScriptTable {
public ScriptTableWithVerify(Table table, String tableId, SlimTestContext context) {
super(table, tableId, context);
}

@Override
protected String getTableType() {
return "scriptWithVerifyTable";
}

protected String getTableKeyword() {
return "verify script";
}

@Override
protected String getCheckKeyword() {
return "verify";
}
}
1 change: 1 addition & 0 deletions src/fitnesse/testsystems/slim/tables/SlimTableFactory.java
Expand Up @@ -33,6 +33,7 @@ public SlimTableFactory() {
addTableType("table", TableTable.class);
addTableType("script", ScriptTable.class);
addTableType("script:", ScriptTable.class);
addTableType("verify script", ScriptTableWithVerify.class);
addTableType("scenario", ScenarioTable.class);
addTableType("import", ImportTable.class);
addTableType("library", LibraryTable.class);
Expand Down