Package org.webbitserver.stub

Examples of org.webbitserver.stub.StubHttpRequest


    /**
     * Create stubbed request.
     */
    private StubHttpRequest request(String uri) {
        return new StubHttpRequest(uri);
    }
View Full Code Here


public class HttpRequestTest {
    private static final List<String> EMPTY = Collections.emptyList();

    @Test
    public void extractsSingleQueryParameter() throws Exception {
        HttpRequest req = new StubHttpRequest("http://host.com:8080/path?fish=cod&fruit=orange");
        assertEquals("cod", req.queryParam("fish"));
    }
View Full Code Here

        assertEquals("cod", req.queryParam("fish"));
    }

    @Test
    public void extractsMultipleQueryParameters() throws Exception {
        HttpRequest req = new StubHttpRequest("http://host.com:8080/path?fish=cod&fruit=orange&fish=smørflyndre");
        assertEquals(asList("cod", "smørflyndre"), req.queryParams("fish"));
    }
View Full Code Here

        assertEquals(asList("cod", "smørflyndre"), req.queryParams("fish"));
    }

    @Test
    public void alwaysReturnsEmptyListWhenThereIsNoQueryString() throws Exception {
        HttpRequest req = new StubHttpRequest("http://host.com:8080/path");
        assertEquals(EMPTY, req.queryParams("fish"));
        assertNull(req.queryParam("fish"));
    }
View Full Code Here

        assertNull(req.queryParam("fish"));
    }

    @Test
    public void returnsEmptyListWhenThereIsNoSuchParameter() throws Exception {
        HttpRequest req = new StubHttpRequest("http://host.com:8080/path?poisson=cabillaud");
        assertEquals(EMPTY, req.queryParams("fish"));
        assertNull(req.queryParam("fish"));
    }
View Full Code Here

    @Test
    public void matchesRequestWithFullUri() throws Exception {
        HttpHandler handler = mock(HttpHandler.class);
        PathMatchHandler pmh = new PathMatchHandler("/hello", handler);

        HttpRequest req = new StubHttpRequest("http://host.com:8080/hello");
        HttpResponse res = new StubHttpResponse();
        HttpControl ctl = new StubHttpControl();

        pmh.handleHttpRequest(req, res, ctl);
        verify(handler).handleHttpRequest(req, res, ctl);
View Full Code Here

    @Test
    public void matchesRequestWithPathOnly() throws Exception {
        HttpHandler handler = mock(HttpHandler.class);
        PathMatchHandler pmh = new PathMatchHandler("/hello", handler);

        HttpRequest req = new StubHttpRequest("/hello");
        HttpResponse res = new StubHttpResponse();
        HttpControl ctl = new StubHttpControl();

        pmh.handleHttpRequest(req, res, ctl);
        verify(handler).handleHttpRequest(req, res, ctl);
View Full Code Here

    @Test
    public void matchesRequestWithRegexpPath() throws Exception {
        HttpHandler handler = mock(HttpHandler.class);
        PathMatchHandler pmh = new PathMatchHandler("/hello/.*", handler);

        HttpRequest req = new StubHttpRequest("/hello/world");
        HttpResponse res = new StubHttpResponse();
        HttpControl ctl = new StubHttpControl();

        pmh.handleHttpRequest(req, res, ctl);
        verify(handler).handleHttpRequest(req, res, ctl);
View Full Code Here

    @Test
    public void handsOffWhenIllegalURIPath() throws Exception {
        HttpHandler handler = mock(HttpHandler.class);
        PathMatchHandler pmh = new PathMatchHandler("/hello", handler);

        HttpRequest req = new StubHttpRequest("//");
        HttpResponse res = new StubHttpResponse();
        HttpControl ctl = mock(HttpControl.class);

        pmh.handleHttpRequest(req, res, ctl);
View Full Code Here

    @Test
    public void handsOffWhenNoMatch() throws Exception {
        HttpHandler handler = mock(HttpHandler.class);
        PathMatchHandler pmh = new PathMatchHandler("/hello", handler);

        HttpRequest req = new StubHttpRequest("http://hello.com:8080/wtf");
        HttpResponse res = new StubHttpResponse();
        HttpControl ctl = mock(HttpControl.class);

        pmh.handleHttpRequest(req, res, ctl);
View Full Code Here

TOP

Related Classes of org.webbitserver.stub.StubHttpRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.