Example usage for org.springframework.mock.web MockServletContext MockServletContext

List of usage examples for org.springframework.mock.web MockServletContext MockServletContext

Introduction

In this page you can find the example usage for org.springframework.mock.web MockServletContext MockServletContext.

Prototype

public MockServletContext() 

Source Link

Document

Create a new MockServletContext , using no base path and a DefaultResourceLoader (i.e.

Usage

From source file:grails.util.GenerateUtils.java

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        return;/*from   w  ww.j  ava2s . com*/
    }

    String type = args[0];
    String domainClassName = args[1];

    ApplicationContext parent = new ClassPathXmlApplicationContext("applicationContext.xml");
    GrailsApplication application = parent.getBean("grailsApplication", DefaultGrailsApplication.class);

    GrailsDomainClass domainClass = findInApplication(application, domainClassName);

    // bootstrap application to try hibernate domain classes
    if (domainClass == null) {
        GrailsRuntimeConfigurator config = new GrailsRuntimeConfigurator(application, parent);
        config.configure(new MockServletContext());
    }

    // retry
    domainClass = findInApplication(application, domainClassName);
    if (domainClass == null) {
        LOG.info("Unable to generate [" + type + "] domain class not found for name [" + domainClassName + "]");
        System.exit(0);
    }

    try {
        GroovyClassLoader gcl = new GroovyClassLoader(Thread.currentThread().getContextClassLoader());
        GrailsTemplateGenerator generator = (GrailsTemplateGenerator) gcl.parseClass(
                gcl.getResourceAsStream(
                        "org/codehaus/groovy/grails/scaffolding/DefaultGrailsTemplateGenerator.groovy"),
                "DefaultGrailsTemplateGenerator.groovy").newInstance();
        if (!CONTROLLER.equals(type) && !VIEWS.equals(type) && !ALL.equals(type)) {
            LOG.info("Grails was unable to generate templates for unsupported type [" + type + "]");
        } else {
            if (VIEWS.equals(type) || ALL.equals(type)) {
                LOG.info("Generating views for domain class [" + domainClass.getName() + "]");
                generator.generateViews(domainClass, ".");
            }
            if (CONTROLLER.equals(type) || ALL.equals(type)) {
                LOG.info("Generating controller for domain class [" + domainClass.getName() + "]");
                generator.generateController(domainClass, ".");
            }
        }
    } catch (Throwable t) {
        LOG.info("Error during code generation: " + t.getMessage());
        LOG.error(t.getMessage(), t);
    } finally {
        System.exit(0);
    }
}

From source file:de.itsvs.cwtrpc.controller.config.AutowiredRemoteServiceGroupConfigBeanDefinitionParserTest.java

@BeforeClass
public static void initClass() {
    ServletContext servletContext;//  w w w .j a  v  a2 s. c o m
    XmlWebApplicationContext appContext;

    servletContext = new MockServletContext();
    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "AutowiredRemoteServiceGroupConfigBeanDefinitionParserTest1.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();

    AutowiredRemoteServiceGroupConfigBeanDefinitionParserTest.appContext = appContext;
}

From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceControllerConfigBeanDefinitionParserTest.java

@BeforeClass
public static void initClass() {
    ServletContext servletContext;/*  w w w. j  a va2 s.  c  o  m*/
    XmlWebApplicationContext appContext;

    servletContext = new MockServletContext();

    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "RemoteServiceControllerConfigBeanDefinitionParserTest1.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();
    RemoteServiceControllerConfigBeanDefinitionParserTest.appContext = appContext;
}

From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceModuleConfigBeanDefinitionParserTest.java

@BeforeClass
public static void initClass() {
    ServletContext servletContext;//from  w w  w  .java 2s .  c  o m
    XmlWebApplicationContext appContext;

    servletContext = new MockServletContext();

    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "RemoteServiceModuleConfigBeanDefinitionParserTest1.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();
    RemoteServiceModuleConfigBeanDefinitionParserTest.appContext = appContext;
}

From source file:de.itsvs.cwtrpc.controller.config.CacheControlConfigBeanDefinitionParserTest.java

@BeforeClass
public static void initClass() {
    ServletContext servletContext;//from ww  w.  j a va 2 s .co m
    XmlWebApplicationContext appContext;

    servletContext = new MockServletContext();
    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "CacheControlConfigBeanDefinitionParserTest1.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();

    CacheControlConfigBeanDefinitionParserTest.appContext = appContext;
}

From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceGroupConfigBeanDefinitionParserTest.java

@BeforeClass
public static void initClass() {
    ServletContext servletContext;/*w  w w.  j  a v  a2  s .  c  o m*/
    XmlWebApplicationContext appContext;

    servletContext = new MockServletContext();

    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "RemoteServiceGroupConfigBeanDefinitionParserTest1.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();
    RemoteServiceGroupConfigBeanDefinitionParserTest.appContext = appContext;

    appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("classpath:/de/itsvs/cwtrpc/controller/config/"
            + "RemoteServiceGroupConfigBeanDefinitionParserTest2.xml");
    appContext.setServletContext(servletContext);
    appContext.refresh();
    RemoteServiceGroupConfigBeanDefinitionParserTest.appContext2 = appContext;
}

From source file:org.eclipse.virgo.web.core.internal.StubWebApplication.java

StubWebApplication(String contextPath) {
    MockServletContext mockServletContext = new MockServletContext();
    mockServletContext.setContextPath(contextPath);
    this.servletContext = mockServletContext;
}

From source file:org.joinfaces.ServletContextConfigurerIT.java

@Test
public void testEmpty() {
    ServletContext servletContext = new MockServletContext();

    ServletContextConfigurer servletContextConfigurer = new JsfServletContextConfigurer(servletContext);

    servletContextConfigurer.configure();

    assertThat(servletContext.getInitParameter("jsf.empty")).isNull();
}

From source file:com.github.persapiens.jsfboot.ServletContextConfigurerIT.java

public void testEmpty() {
    ServletContext servletContext = new MockServletContext();

    ServletContextConfigurer servletContextConfigurer = new JsfServletContextConfigurer(servletContext);

    servletContextConfigurer.configure();

    assertThat(servletContext.getInitParameter("jsf.empty")).isNull();
}

From source file:ar.com.zauber.commons.web.uri.factory.ServletPathUriFactoryTest.java

/** test case */
@Test/*from   ww w  .  j  a  va2  s .  c  om*/
public final void testServletPath() {
    MockServletContext servletContext = new MockServletContext();
    servletContext.setContextPath("my-path/");
    ServletPathUriFactory uriFactory = new ServletPathUriFactory(new IdentityUriFactory());
    uriFactory.setServletContext(servletContext);

    assertEquals("my-path/hello", uriFactory.buildUri("hello"));
}