/** * @param configuration * @param location typically the base folder where the executing test class is located. For Maven projects this is `/target/test-classes/` * We use it in conjunction with the relative path supplied in the annotated test class to obtain the absolute path to the * web application document root (where /WEB-INF folder is). * @throws ServletException */ private void addWebAppContexts(ServerConfiguration configuration, String location) throws ServletException { for (WebAppContextConfiguration webAppContext : configuration.getWebAppContexts()) { WebContext webContextConfig = webAppContext.getConfig(); String webAppPath = FilenameUtils.normalize(location + webContextConfig.webApp()); Context webContext = tomcat.addWebapp(webContextConfig.contextPath(), webAppPath); if (webContextConfig.descriptor().length() > 0) { String webXmlPath = FilenameUtils.normalize(location + webContextConfig.descriptor()); webContext.setAltDDName(webXmlPath); log.info(String.format("LOG00330: Using custom WEB descriptor '%s' for server=%s, context=%s", webXmlPath, configuration, webContextConfig.contextPath())); } ApplicationContextFacade servletContext = (ApplicationContextFacade) webContext.getServletContext(); servletContext.setAttribute(ConfigurationConstants.SERVER_CONFIGURATION_KEY, configuration); servletContext.setAttribute(ConfigurationConstants.CONTEXT_CONFIGURATION_KEY, webAppContext); attachRequestListener(servletContext, webAppContext); log.info("LOG00150: Adding web application for context [{}]", servletContext); } }