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

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

Introduction

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

Prototype

public MockServletConfig() 

Source Link

Document

Create a new MockServletConfig with a default MockServletContext .

Usage

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);//w  w w. j av a 2  s .  com
    try {
        c.doPost(request, response);
        Assert.fail("Should fail outside web context");
    } catch (RuntimeException e) {
    }
}

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.ngrinder.script.controller.SvnDavControllerTest.java

private void prepareSVN() throws IOException, SVNException {
    File tempRepo = new File(System.getProperty("java.io.tmpdir"), "repo");
    fileEntityRepository.setUserRepository(new File(tempRepo, getTestUser().getUserId()));
    tempRepo.deleteOnExit();/* www.ja v a  2 s .  c  o  m*/
    File testUserRoot = fileEntityRepository.getUserRepoDirectory(getTestUser()).getParentFile();
    FileUtils.deleteQuietly(testUserRoot);
    testUserRoot.mkdirs();
    CompressionUtils.unzip(new ClassPathResource("TEST_USER.zip").getFile(), testUserRoot);
    testUserRoot.deleteOnExit();
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.addInitParameter("SVNParentPath", testUserRoot.getAbsolutePath());
    DAVConfig davConfig = new DAVConfig(servletConfig);
    svnController.setDAVConfig(davConfig);
}

From source file:com.google.api.server.spi.EndpointsServletTest.java

@Before
public void setUp() throws ServletException {
    req = new MockHttpServletRequest();
    req.setServletPath("/_ah/api");
    req.addHeader("Host", API_SERVER_NAME);
    req.setServerName(API_SERVER_NAME);/* ww w . j av  a 2s  .  co  m*/
    req.setServerPort(API_PORT);
    resp = new MockHttpServletResponse();
    servlet = new EndpointsServlet();
    MockServletConfig config = new MockServletConfig();
    config.addInitParameter("services", TestApi.class.getName());
    servlet.init(config);
}

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'"));
}

From source file:fi.okm.mpass.idp.authn.impl.SocialUserOpenIdConnectEndServletTest.java

/**
 * Init tests.//from   www.  j a v  a  2 s .  c  o  m
 * 
 * @throws Exception
 */
@BeforeTest
public void initTests() throws Exception {
    servlet = new SocialUserOpenIdConnectEndServlet();
    MockServletConfig mockConfig = new MockServletConfig();
    servlet.init(mockConfig);
    conversationKey = "mockKey";
}

From source file:fi.okm.mpass.shibboleth.authn.impl.ShibbolethSpAuthnServletTest.java

@BeforeMethod
public void initTests() throws Exception {
    super.setUp();
    servlet = new ShibbolethSpAuthnServlet();
    servlet.init(new MockServletConfig());
    conversationKey = "mockKey";
    flowExecutionUrl = "http://localhost/mock";
    final AuthenticationContext authnContext = prc.getSubcontext(AuthenticationContext.class, false);
    authnContext.setAttemptedFlow(authenticationFlows.get(0));
    final ExternalAuthenticationContext extContext = authnContext
            .getSubcontext(ExternalAuthenticationContext.class, true);
    extContext.setFlowExecutionUrl(flowExecutionUrl);
}

From source file:fi.okm.mpass.idp.authn.impl.SocialUserOpenIdConnectStartServletTest.java

/**
 * Init tests.//  w  w w. j  a  v  a2  s  . c  o m
 * @throws Exception
 */
@BeforeTest
public void initTests() throws Exception {
    servlet = new SocialUserOpenIdConnectStartServlet();
    MockServletConfig mockConfig = new MockServletConfig();
    servlet.init(mockConfig);
    conversationKey = "mockKey";
}

From source file:org.apache.wink.server.internal.servlet.MockServletInvocationTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    servlet = (HttpServlet) Class.forName("org.apache.wink.server.internal.servlet.RestServlet").newInstance();
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.addInitParameter("javax.ws.rs.Application", getApplicationClassName());

    String propertiesFile = getPropertiesFile();
    if (propertiesFile != null) {
        servletConfig.addInitParameter("propertiesLocation", propertiesFile);
    }/*from  www .j a  v a 2 s  .  c  o m*/

    String deploymentConfigClass = getDeploymentConfigurationClassName();
    if (deploymentConfigClass != null) {
        servletConfig.addInitParameter("deploymentConfiguration", deploymentConfigClass);
    }

    tls.set(this);
    servlet.init(servletConfig);
}

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"));
}