*
* @return {@link ApplicationContext} retrieves from web application
*/
private ApplicationContext getWebApplicationContext(TestClass testClass) {
SpringWebConfiguration springWebConfiguration;
WebApplicationContext rootContext;
ApplicationContext applicationContext;
rootContext = ContextLoader.getCurrentWebApplicationContext();
if (rootContext == null) {
throw new RuntimeException("The Spring Root Web Application Context could not be found.");
}
springWebConfiguration = testClass.getAnnotation(SpringWebConfiguration.class);
if (!isEmpty(springWebConfiguration.servletName())) {
applicationContext = getServletApplicationContext(rootContext, springWebConfiguration.servletName());
if (applicationContext == null) {
throw new RuntimeException("Could not find the application context for servlet: " +
springWebConfiguration.servletName());
}
} else {
// uses the root context as the main application context
applicationContext = rootContext;
}