Package com.google.appengine.api.urlfetch

Examples of com.google.appengine.api.urlfetch.MockHttpResponse


    }
   
    @Test
    public void testReadResponseHeaders() throws Exception {
        GHttpEndpoint endpoint = createEndpoint("ghttp://somewhere.com:9090/path");
        MockHttpResponse response = new MockHttpResponse(200);
        response.addHeader("test", "abc");
        response.addHeader("content-type", "text/plain");
        binding.readResponseHeaders(endpoint, exchange, response);
        assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
        assertEquals("abc", exchange.getOut().getHeader("test"));
        assertEquals("text/plain", exchange.getOut().getHeader("content-type"));
    }
View Full Code Here


        assertEquals("text/plain", exchange.getOut().getHeader("content-type"));
    }
   
    @Test
    public void testReadResponseBody() throws Exception {
        MockHttpResponse response = new MockHttpResponse(200);
        response.setContent("abc".getBytes());
        binding.readResponseBody(null, exchange, response);
        InputStream stream = exchange.getOut().getBody(InputStream.class);
        assertEquals("abc".getBytes()[0], stream.read());
    }
View Full Code Here

        assertEquals("abc".getBytes()[0], stream.read());
    }
   
    @Test
    public void testReadNullResponseBody() throws Exception {
        MockHttpResponse response = new MockHttpResponse(200);
        binding.readResponseBody(null, exchange, response);
        InputStream stream = exchange.getOut().getBody(InputStream.class);
        assertNull(stream);
    }
View Full Code Here

    }
   
    @Test(expected = GHttpException.class)
    public void testFailureException() throws Exception {
        GHttpEndpoint endpoint = createEndpoint("ghttp://somewhere.com:9090/path");
        MockHttpResponse response = new MockHttpResponse(500);
        binding.readResponse(endpoint, exchange, response);
    }
View Full Code Here

    }
   
    @Test
    public void testFailureNoException() throws Exception {
        GHttpEndpoint endpoint = createEndpoint("ghttp://somewhere.com:9090/path?throwExceptionOnFailure=false");
        MockHttpResponse response = new MockHttpResponse(500);
        binding.readResponse(endpoint, exchange, response);
        assertEquals(500, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    }
View Full Code Here

    public HTTPResponse fetch(URL url) throws IOException {
        throw new UnsupportedOperationException("not impemented");
    }

    public HTTPResponse fetch(HTTPRequest request) throws IOException {
        MockHttpResponse response = new MockHttpResponse(200);
        response.setContent(request.getPayload());
        response.addHeader("testUrl", request.getURL().toString());
        response.addHeader("testQuery", request.getURL().getQuery());
        response.addHeader("testMethod", request.getMethod().toString());
        for (HTTPHeader header : request.getHeaders()) {
            response.addHeader(header.getName(), header.getValue());
        }
        return response;
    }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.urlfetch.MockHttpResponse

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.