if (getRequestCount() == -1)
{
container = DefaultServletContainerFactory.getInstance().getServletContainer();
if (container == null)
{
return new FailureResponse(Failure.createAssertionFailure("No servlet container present"));
}
// Register and save the deployed web apps
registry = new WebAppRegistry();
container.addWebAppListener(registry);
keys = new HashSet<String>(registry.getKeys());
// Deploy the application web app
return new DeployResponse("test-spi-app.war");
}
else if (getRequestCount() == 0)
{
// Compute the difference with the previous deployed web apps
Set diff = new HashSet<String>(registry.getKeys());
diff.removeAll(keys);
// It should be 1
if (diff.size() != 1)
{
return new FailureResponse(Failure.createAssertionFailure("The size of the new web application deployed should be 1, it is " + diff.size() + " instead." +
"The previous set was " + keys + " and the new set is " + registry.getKeys()));
}
String key = (String)diff.iterator().next();
if (!"/test-spi-app".equals(key))
{
return new FailureResponse(Failure.createAssertionFailure("The newly deployed web application should be /test-spi-war and it is " + key));
}
//
WebApp webApp = registry.getWebApp("/test-spi-app");
if (webApp == null)
{
return new FailureResponse(Failure.createAssertionFailure("The web app /test-spi-app was not found"));
}
if (!"/test-spi-app".equals(webApp.getContextPath()))
{
return new FailureResponse(Failure.createAssertionFailure("The web app context is not equals to the expected value but has the value " + webApp.getContextPath()));
}
//
return new InvokeGetResponse("/test-spi-server");
}
else
{
return new FailureResponse(Failure.createAssertionFailure(""));
}
}