public void testStateCookies() throws Exception {
    final String resourceName = "something/interesting";

    ServletRunner sr = new ServletRunner();
    sr.registerServlet(resourceName, StatefulServlet.class.getName());

    WebRequest request = new PostMethodWebRequest("http://localhost/" + resourceName);
    request.setParameter("color", "red");
    WebResponse response = sr.getResponse(request);
    assertNotNull("No response received", response);
    assertEquals("Returned cookie count", 1, response.getNewCookieNames().length);
  }
  public void testNoInitialState() throws Exception {
    final String resourceName = "something/interesting";

    ServletRunner sr = new ServletRunner();
    sr.registerServlet(resourceName, StatefulServlet.class.getName());

    WebRequest request = new GetMethodWebRequest("http://localhost/" + resourceName);
    WebResponse response = sr.getResponse(request);
    assertNotNull("No response received", response);
    assertEquals("content type", "text/plain", response.getContentType());
    assertEquals("requested resource", "No session found", response.getText());
    assertEquals("Returned cookie count", 0, response.getNewCookieNames().length);
  }
  public void testSessionAccess() throws Exception {
    final String resourceName1 = "something/interesting/start";
    final String resourceName2 = "something/continue";

    ServletRunner sr = new ServletRunner();
    sr.registerServlet(resourceName1, StatefulServlet.class.getName());
    sr.registerServlet(resourceName2, StatefulServlet.class.getName());

    WebRequest request = new PostMethodWebRequest("http://localhost/" + resourceName1);
    request.setParameter("color", "yellow");
    sr.getResponse(request);

    assertNotNull("No session was created", sr.getSession(false));
    assertEquals(
        "Color attribute in session", "yellow", sr.getSession(false).getAttribute("color"));
  }