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

Feature/1152 #1153

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/fitnesse/junit/CustomVariableProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fitnesse.junit;

import java.util.Map;

/**
* Provide custom variables to override page variables in a similar way as done with URL-Parameters
* when using the fitnesse-stabdalone runner
* @author mwyraz
*/
public interface CustomVariableProvider {
public Map<String,String> getCustomVariables();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this method also receive the suiteClass?

}
41 changes: 38 additions & 3 deletions src/fitnesse/junit/FitNesseRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import fitnesse.ConfigurationParameter;
import fitnesse.ContextConfigurator;
Expand Down Expand Up @@ -68,6 +69,16 @@ public class FitNesseRunner extends ParentRunner<WikiPage> {
boolean value() default true;
}

/**
* The <code>CustomVariableProviderClass</code> annotation specifies an optional {@link CustomVariableProvider} to overwrite page variables
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface CustomVariableProviderClass {

Class<? extends CustomVariableProvider> value();
}

/**
* The <code>SuiteFilter</code> annotation specifies the suite filter of the Fitnesse suite
* to be run, e.g.: fasttests
Expand Down Expand Up @@ -165,6 +176,7 @@ public class FitNesseRunner extends ParentRunner<WikiPage> {
private FitNesseContext context;
private DescriptionFactory descriptionFactory;
private List<WikiPage> children;
private Map<String,String> customVariables;

public FitNesseRunner(Class<?> suiteClass) throws InitializationError {
super(suiteClass);
Expand Down Expand Up @@ -219,6 +231,13 @@ protected void collectInitializationErrors(List<Throwable> errors) {
} catch (Exception e) {
errors.add(e);
}

try {
this.customVariables = getCustomVariables(suiteClass);
} catch (Exception e) {
errors.add(e);
}

try {
this.context = createContext(suiteClass);
} catch (Exception e) {
Expand Down Expand Up @@ -320,6 +339,15 @@ protected boolean shouldPreventSystemExit(Class<?> klass) throws Exception {
return preventSystemExitAnnotation.value();
}


protected Map<String,String> getCustomVariables(Class<?> klass) throws Exception {
CustomVariableProviderClass customVariableProviderClass = klass.getAnnotation(CustomVariableProviderClass.class);
if (null == customVariableProviderClass) {
return null;
}
return customVariableProviderClass.value().newInstance().getCustomVariables();
}

protected String getFitNesseDir(Class<?> klass)
throws InitializationError {
FitnesseDir fitnesseDirAnnotation = klass.getAnnotation(FitnesseDir.class);
Expand Down Expand Up @@ -416,14 +444,21 @@ protected void addExecutionLogListener(RunNotifier notifier, MultipleTestsRunner
testRunner.addExecutionLogListener(new ConsoleExecutionLogListener());
}

protected WikiPage getRootPage() {
if (this.customVariables==null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.customVariables==null) {
if (this.customVariables == null) {

return context.getRootPage();
}
return context.getRootPage(customVariables);
}

protected List<WikiPage> initChildren() {
WikiPage suiteRoot = getSuiteRootPage();
if (suiteRoot == null) {
throw new IllegalArgumentException("No page " + this.suiteName);
}
List<WikiPage> children;
if (suiteRoot.getData().hasAttribute("Suite")) {
children = new SuiteContentsFinder(suiteRoot, getSuiteFilter(), context.getRootPage()).getAllPagesToRunForThisSuite();
children = new SuiteContentsFinder(suiteRoot, getSuiteFilter(), getRootPage()).getAllPagesToRunForThisSuite();
} else {
children = Collections.singletonList(suiteRoot);
}
Expand Down Expand Up @@ -460,12 +495,12 @@ protected ContextConfigurator initContextConfigurator() throws InitializationErr

private WikiPage getSuiteRootPage() {
WikiPagePath path = PathParser.parse(this.suiteName);
PageCrawler crawler = context.getRootPage().getPageCrawler();
PageCrawler crawler = getRootPage().getPageCrawler();
return crawler.getPage(path);
}

private MultipleTestsRunner createTestRunner(List<WikiPage> pages) {
final PagesByTestSystem pagesByTestSystem = new PagesByTestSystem(pages, context.getRootPage());
final PagesByTestSystem pagesByTestSystem = new PagesByTestSystem(pages, getRootPage());

MultipleTestsRunner runner = new MultipleTestsRunner(pagesByTestSystem,
context.testSystemFactory);
Expand Down