lantunes / fixd

An HTTP Server Fixture for Testing HTTP Clients and mocking web services, and a Java Micro Web Framework
http://bigtesting.org/fixd
Apache License 2.0
41 stars 6 forks source link

Create a Request Parameter SessionHandler #3

Closed lantunes closed 11 years ago

lantunes commented 11 years ago

Create a RequestParameterSessionHandler, analogous to PathParamSessionHandler, that gets the session values from request parameters. For example:

server.handle(Method.PUT, "/")
      .with(200, "text/plain", "OK")
      .withNewSession(new RequestParameterSessionHandler());

server.handle(Method.GET, "/")
      .with(200, "text/html", "Name: {name}");

WebClient client = new WebClient();

Page page = client.getPage(new WebRequest(new URL(
            "http://localhost:8080/?name=Tim"), 
            HttpMethod.PUT));
assertEquals(200, page.getWebResponse().getStatusCode());

page      = client.getPage(new WebRequest(new URL(
            "http://localhost:8080/"), 
            HttpMethod.GET));
assertEquals("Name: Tim", page.getWebResponse().getContentAsString().trim());