Search in sources :

Example 46 with HttpRequest

use of org.jboss.netty.handler.codec.http.HttpRequest in project opentsdb by OpenTSDB.

the class TestHttpQuery method getCharsetInvalid.

@Test(expected = UnsupportedCharsetException.class)
public void getCharsetInvalid() {
    final Channel channelMock = NettyMocks.fakeChannel();
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
    req.headers().add("Content-Type", "text/plain; charset=foobar");
    final HttpQuery query = new HttpQuery(tsdb, req, channelMock);
    assertEquals(Charset.forName("UTF-16"), query.getCharset());
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) Channel(org.jboss.netty.channel.Channel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 47 with HttpRequest

use of org.jboss.netty.handler.codec.http.HttpRequest in project opentsdb by OpenTSDB.

the class TestAnnotationRpc method badMethod.

@Test(expected = BadRequestException.class)
public void badMethod() throws Exception {
    final Channel channelMock = NettyMocks.fakeChannel();
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.TRACE, "/api/annotation");
    final HttpQuery query = new HttpQuery(tsdb, req, channelMock);
    rpc.execute(tsdb, query);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) Channel(org.jboss.netty.channel.Channel) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 48 with HttpRequest

use of org.jboss.netty.handler.codec.http.HttpRequest in project opentsdb by OpenTSDB.

the class TestTreeRpc method handleTestBadMethod.

@Test(expected = BadRequestException.class)
public void handleTestBadMethod() throws Exception {
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.TRACE, "/api/tree/test");
    final HttpQuery query = new HttpQuery(tsdb, req, NettyMocks.fakeChannel());
    rpc.execute(tsdb, query);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 49 with HttpRequest

use of org.jboss.netty.handler.codec.http.HttpRequest in project opentsdb by OpenTSDB.

the class TestRpcHandler method emptyPathIsBadRequest.

@Test
public void emptyPathIsBadRequest() throws Exception {
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
    final Channel mockChan = handleHttpRpc(req, new Answer<ChannelFuture>() {

        public ChannelFuture answer(final InvocationOnMock args) throws Throwable {
            DefaultHttpResponse response = (DefaultHttpResponse) args.getArguments()[0];
            assertEquals(HttpResponseStatus.BAD_REQUEST, response.getStatus());
            return new SucceededChannelFuture((Channel) args.getMock());
        }
    });
    final RpcHandler rpc = new RpcHandler(tsdb, rpc_manager);
    Whitebox.invokeMethod(rpc, "handleHttpQuery", tsdb, mockChan, req);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) ChannelFuture(org.jboss.netty.channel.ChannelFuture) SucceededChannelFuture(org.jboss.netty.channel.SucceededChannelFuture) SucceededChannelFuture(org.jboss.netty.channel.SucceededChannelFuture) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) Channel(org.jboss.netty.channel.Channel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 50 with HttpRequest

use of org.jboss.netty.handler.codec.http.HttpRequest in project opentsdb by OpenTSDB.

the class TestRpcHandler method httpOptionsCORSNotConfigured.

@Test
public void httpOptionsCORSNotConfigured() {
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/api/v1/version");
    req.headers().add(HttpHeaders.ORIGIN, "42.com");
    handleHttpRpc(req, new Answer<ChannelFuture>() {

        public ChannelFuture answer(final InvocationOnMock args) throws Throwable {
            DefaultHttpResponse response = (DefaultHttpResponse) args.getArguments()[0];
            assertEquals(HttpResponseStatus.METHOD_NOT_ALLOWED, response.getStatus());
            assertNull(response.headers().get(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
            return null;
        }
    });
    final RpcHandler rpc = new RpcHandler(tsdb, rpc_manager);
    rpc.messageReceived(ctx, message);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) ChannelFuture(org.jboss.netty.channel.ChannelFuture) SucceededChannelFuture(org.jboss.netty.channel.SucceededChannelFuture) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)136 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)69 Channel (org.jboss.netty.channel.Channel)47 Test (org.junit.Test)47 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)46 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)43 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)31 ChannelFuture (org.jboss.netty.channel.ChannelFuture)26 List (java.util.List)19 ArrayList (java.util.ArrayList)17 Map (java.util.Map)17 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)17 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)17 InetSocketAddress (java.net.InetSocketAddress)14 ChannelHandlerContext (org.jboss.netty.channel.ChannelHandlerContext)13 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)13 SimpleHttpResponseHandler (com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler)12 SimpleTestHttpClient (com.linkedin.databus.core.test.netty.SimpleTestHttpClient)12 Configuration (org.apache.hadoop.conf.Configuration)12 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)12