<commit_before>package edu.northwestern.bioinformatics.studycalendar.web;

import edu.northwestern.bioinformatics.studycalendar.core.StudyCalendarTestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;

/**
 * @author <NAME>
 */
public class StudyCalendarTestWebApplicationContextBuilder {
    public static XmlWebApplicationContext createWebApplicationContext(
        ServletContext servletContext
    ) {
        return createPscWebApplicationContext(servletContext, new String[] {
            "classpath:applicationContext-command.xml",
            "classpath:applicationContext-webflow.xml",
            "classpath:applicationContext-web-osgi.xml",
            "classpath:applicationContext-web-testing-osgi.xml",
        });
    }

    public static WebApplicationContext createRealWebApplicationContext(ServletContext servletContext) {
        return createPscWebApplicationContext(servletContext, new String[] {
            "classpath:applicationContext-command.xml",
            "classpath:applicationContext-webflow.xml",
            "classpath:applicationContext-web-osgi.xml"
        });
    }

    public static XmlWebApplicationContext createWebApplicationContextForServlet(
        String servletName, ServletContext servletContext
    ) {
        ApplicationContext parent = createWebApplicationContext(servletContext);
        XmlWebApplicationContext context = new XmlWebApplicationContext();
        context.setParent(parent);
        context.setServletContext(servletContext);
        context.setConfigLocation("WEB-INF/" + servletName + "-servlet.xml");
        context.refresh();
        return context;
    }

    private static XmlWebApplicationContext createPscWebApplicationContext(ServletContext servletContext, String[] configLocations) {
        ApplicationContext parent = StudyCalendarTestCase.getDeployedApplicationContext();
        XmlWebApplicationContext context = new XmlWebApplicationContext();
        context.setParent(parent);
        context.setServletContext(servletContext);
        context.setConfigLocations(configLocations);
        context.refresh();
        return context;
    }
}<commit_msg>Modify test web application context to behave the same as deployed context creation.  Related to #651.<commit_after>package edu.northwestern.bioinformatics.studycalendar.web;

import edu.northwestern.bioinformatics.studycalendar.core.StudyCalendarApplicationContextBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;

import javax.servlet.ServletContext;

/**
 * @author <NAME>
 */
public class StudyCalendarTestWebApplicationContextBuilder {
    public static XmlWebApplicationContext createWebApplicationContext(
        ServletContext servletContext
    ) {
        return createPscWebApplicationContext(servletContext, new String[] {
            "classpath:applicationContext-command.xml",
            "classpath:applicationContext-webflow.xml",
            "classpath:applicationContext-web-osgi.xml",
            "classpath:applicationContext-web-testing-osgi.xml",
        });
    }

    public static WebApplicationContext createRealWebApplicationContext(ServletContext servletContext) {
        return createPscWebApplicationContext(servletContext, new String[] {
            "classpath:applicationContext-command.xml",
            "classpath:applicationContext-webflow.xml",
            "classpath:applicationContext-web-osgi.xml"
        });
    }

    public static XmlWebApplicationContext createWebApplicationContextForServlet(
        String servletName, ServletContext servletContext
    ) {
        ApplicationContext parent = createWebApplicationContext(servletContext);
        XmlWebApplicationContext context = new XmlWebApplicationContext();
        context.setParent(parent);
        context.setServletContext(servletContext);
        context.setConfigLocation("WEB-INF/" + servletName + "-servlet.xml");
        context.refresh();
        return context;
    }

    private static XmlWebApplicationContext createPscWebApplicationContext(ServletContext servletContext, String[] configLocations) {
        int coreCount = StudyCalendarApplicationContextBuilder.DEPLOYED_CONFIG_LOCATIONS.length;
        String[] loc = new String[coreCount + configLocations.length];
        System.arraycopy(
            StudyCalendarApplicationContextBuilder.DEPLOYED_CONFIG_LOCATIONS, 0,
            loc, 0, coreCount);
        System.arraycopy(
            configLocations, 0, loc, coreCount, configLocations.length);
        XmlWebApplicationContext context = new XmlWebApplicationContext();
        context.setServletContext(servletContext);
        context.setConfigLocations(loc);
        context.refresh();
        return context;
    }
}
{'fraction_non_alphanumeric': 0.07845479888490642, 'fraction_numerical': 0.0011947431302270011, 'mean_word_length': 3.9732673267326732, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2899350', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1176, 'n_words': 203}