package com.canoo.webtest.reporting;
import org.apache.tools.ant.Location;
import com.canoo.webtest.ant.TestStepSequence;
import com.canoo.webtest.ant.WebtestTask;
import com.canoo.webtest.engine.Configuration;
import com.canoo.webtest.engine.StepFailedException;
/**
* The root step result containing it's children results as well as some general information
* about the webtest. It is generated by the {@link StepExecutionListener}.
* @author Marc Guillemot
*/
public class RootStepResult extends StepResult
{
private final String fWebtestName;
private final String fWebtestDescription;
private final Location fWebtestLocation;
private final Configuration fConfiguration;
private StepResult fLastFailingTaskResult;
private Throwable fException;
public RootStepResult(final TestStepSequence step)
{
super(step);
final WebtestTask webtest = step.getContext().getWebtest();
fWebtestName = webtest.getName();
fWebtestDescription = webtest.getDescription();
fWebtestLocation = webtest.getLocation();
fConfiguration = step.getContext().getConfig();
}
public Configuration getConfig()
{
return fConfiguration;
}
/**
* Gets the description of the <webtest>
* @return the description
*/
public String getWebtestDescription()
{
return fWebtestDescription;
}
public String getWebtestName()
{
return fWebtestName;
}
public Location getWebtestLocation()
{
return fWebtestLocation;
}
public boolean isError()
{
return fException != null && !isFailure();
}
public Throwable getException()
{
return fException;
}
public boolean isFailure()
{
return StepFailedException.isCausedByStepFailedException(fException);
// return fException instanceof StepFailedException;
}
public boolean isSuccessful()
{
return fException == null;
}
/**
* Gets the result of the failing task (if any)
* @return <code>null</code> if the test is successfull.
*/
public StepResult getFailingTaskResult()
{
if (isSuccessful())
return null;
else
return fLastFailingTaskResult;
}
protected void setLastFailingTaskResult(final StepResult stepResult, final Throwable throwable)
{
fLastFailingTaskResult = stepResult;
fException = throwable;
}
}