Tuesday, January 13, 2015

Starting and Stoping FitNesse from java code

Indeed a lot of things have changed in the FitNesse code. A lot of fields have been made final, so it’s easier to reason about the code.

To create a context configuration we can use the fitnesse.ContextConfigurator class. It can be used to build a FitNesseContext to your liking, while the FitNesseContext fields remain final.

The ContextConfigurator is using a builder pattern, so you can configure it using the withXxx() methods

public void start() throws Exception {
try {
try {
if (fitnesse == null) {
FitNesseContext context = loadContext();
fitnesse = new FitNesse(context);
}
} catch (Exception e) {
throw e;
}
if (fitnesse != null) {
fitnesse.start();
}
} catch (RuntimeException e1) {
throw e1;
}

}

public void stop() throws Exception {
if (fitnesse != null) {
fitnesse.stop();
fitnesse = null;
}
}

protected FitNesseContext loadContext() throws Exception {
ContextConfigurator configurator = ContextConfigurator.empty();
   configurator.withParameter(ConfigurationParameter.ROOT_PATH,C:\\FitNesseRootPath);
 configurator.withParameter(ConfigurationParameter.PORT,8080);  
 configurator.withParameter(ConfigurationParameter.CONTEXT_ROOT, "/");

 FitNesseContext context = configurator.makeFitNesseContext();
return context;
}

No comments:

Post a Comment

java-8-streams-map-examples

package com.mkyong.java8; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; im...