Example usage for org.springframework.mock.web MockServletConfig getServletContext

List of usage examples for org.springframework.mock.web MockServletConfig getServletContext

Introduction

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

Prototype

@Override
    public ServletContext getServletContext() 

Source Link

Usage

From source file:org.ambraproject.doi.ResolverServletTest.java

@BeforeClass(dependsOnMethods = "createDB")
public void setup() throws ConfigurationException, ServletException {
    URL configLocation = getClass().getClassLoader().getResource("test-config.xml");
    ConfigurationStore.getInstance().loadConfiguration(configLocation);
    resolverServlet = new ResolverServlet();

    //Initialize it the servlet
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.getServletContext().setAttribute("resolverDAOService", new JdbcResolverService(dataSource));
    resolverServlet.init(servletConfig);
}

From source file:org.geomajas.gwt.server.mvc.GeomajasControllerTest.java

@Test
public void testNonWebContext() throws ServletException, IOException {
    // create mock context that loads from the classpath
    MockServletConfig config = new MockServletConfig();
    MockHttpServletRequest request = new MockHttpServletRequest(config.getServletContext());
    MockHttpServletResponse response = new MockHttpServletResponse();
    GeomajasController c = new GeomajasController();
    c.init(config);/*from  w ww. j  av a 2s. c om*/
    try {
        c.doPost(request, response);
        Assert.fail("Should fail outside web context");
    } catch (RuntimeException e) {
    }
}

From source file:org.geomajas.gwt.server.mvc.GeomajasControllerTest.java

@Test
public void testSerializationPolicy() throws UnsupportedEncodingException, ServletException {
    // create mock context that loads from the classpath
    MockServletConfig config = new MockServletConfig();
    MockHttpServletRequest request = new MockHttpServletRequest(config.getServletContext());
    request.setContentType("text/x-gwt-rpc");
    request.setCharacterEncoding("UTF-8");
    request.setContent(("6|0|10|http://apps.geomajas.org/explorer/be.geosparc.Explorer/"
            + "|54044FB0C988344F1715C8B91330B0A2|org.geomajas.gwt.client.GeomajasService|"
            + "execute|org.geomajas.gwt.client.command.GwtCommand/4093389776|command.configuration.GetMap|"
            + "org.geomajas.command.dto.GetMapConfigurationRequest/104733661|explorer|mainMap|"
            + "ss.TqRPfHFh24NVxB|1|2|3|4|1|5|5|6|7|8|9|0|10|").getBytes("UTF-8"));
    request.addHeader("X-GWT-Permutation", "54044FB0C988344F1715C8B91330B0A2");
    request.addHeader("X-GWT-Module-Base", "http://test/module/");
    MockHttpServletResponse response = new MockHttpServletResponse();
    customController.setServletConfig(config);
    customController.doPost(request, response);
    // expect the message that the type is missing from our policy file
    Assert.assertTrue(response.getContentAsString().contains(
            "Type 'org.geomajas.gwt.client.command.GwtCommand' was not included in the set of types"));
}

From source file:org.geomajas.gwt.server.mvc.GeomajasControllerTest.java

@Test
public void testMockWebContext() throws ServletException, IOException {
    // create mock context that loads from the classpath
    MockServletConfig config = new MockServletConfig();
    MockHttpServletRequest request = new MockHttpServletRequest(config.getServletContext());
    request.setContentType("text/x-gwt-rpc");
    request.setCharacterEncoding("UTF-8");
    request.setContent(("6|0|10|http://apps.geomajas.org/explorer/be.geosparc.Explorer/"
            + "|54044FB0C988344F1715C8B91330B0A2|org.geomajas.gwt.client.GeomajasService|"
            + "execute|org.geomajas.gwt.client.command.GwtCommand/4093389776|command.configuration.GetMap|"
            + "org.geomajas.command.dto.GetMapConfigurationRequest/104733661|explorer|mainMap|"
            + "ss.TqRPfHFh24NVxB|1|2|3|4|1|5|5|6|7|8|9|0|10|").getBytes("UTF-8"));
    request.addHeader("X-GWT-Permutation", "54044FB0C988344F1715C8B91330B0A2");
    request.addHeader("X-GWT-Module-Base", "http://test/module/");
    MockHttpServletResponse response = new MockHttpServletResponse();
    defaultController.setServletConfig(config);
    defaultController.doPost(request, response);
    // expect the message of the out-dated 1.3 policy of GWT
    Assert.assertTrue(response.getContentAsString()
            .contains("Type 'org.geomajas.gwt.client.command.GwtCommand' was not assignable"
                    + " to 'com.google.gwt.user.client.rpc.IsSerializable'"));
}