Search in sources :

Example 26 with Channel

use of org.jboss.netty.channel.Channel in project opentsdb by OpenTSDB.

the class TestHttpQuery method setSerializerCT.

@Test
public void setSerializerCT() throws Exception {
    HttpQuery.initializeSerializerMaps(null);
    final Channel channelMock = NettyMocks.fakeChannel();
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
    req.headers().add("Content-Type", "application/json");
    final HttpQuery query = new HttpQuery(tsdb, req, channelMock);
    query.setSerializer();
    assertEquals(HttpJsonSerializer.class.getCanonicalName(), query.serializer().getClass().getCanonicalName());
}
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 27 with Channel

use of org.jboss.netty.channel.Channel in project opentsdb by OpenTSDB.

the class TestHttpQuery method getContentBadEncoding.

@Test
public void getContentBadEncoding() {
    final Channel channelMock = NettyMocks.fakeChannel();
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
    final ChannelBuffer buf = ChannelBuffers.copiedBuffer("Sí Señor", CharsetUtil.ISO_8859_1);
    req.setContent(buf);
    final HttpQuery query = new HttpQuery(tsdb, req, channelMock);
    assertThat("Sí Señor", not(equalTo(query.getContent())));
}
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) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 28 with Channel

use of org.jboss.netty.channel.Channel 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 29 with Channel

use of org.jboss.netty.channel.Channel in project opentsdb by OpenTSDB.

the class NettyMocks method contentQuery.

/**
   * Returns an HttpQuery object with the given settings
   * @param tsdb The TSDB to associate with, needs to be mocked with the Config
   * object set
   * @param uri A URI to use
   * @param content Content to POST (UTF-8 encoding)
   * @param type Content-Type value
   * @param method The HTTP method to use, GET, POST, etc.
   * @return an HttpQuery object
   */
public static HttpQuery contentQuery(final TSDB tsdb, final String uri, final String content, final String type, final HttpMethod method) {
    final Channel channelMock = NettyMocks.fakeChannel();
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, uri);
    if (content != null) {
        req.setContent(ChannelBuffers.copiedBuffer(content, Charset.forName("UTF-8")));
    }
    req.headers().set("Content-Type", type);
    return new HttpQuery(tsdb, req, channelMock);
}
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)

Example 30 with Channel

use of org.jboss.netty.channel.Channel in project opentsdb by OpenTSDB.

the class NettyMocks method getQuery.

/**
   * Returns an HttpQuery object with the given URI and the following parameters:
   * Method = GET
   * Content = null
   * Content-Type = null
   * @param tsdb The TSDB to associate with, needs to be mocked with the Config
   * object set
   * @param uri A URI to use
   * @return an HttpQuery object
   */
public static HttpQuery getQuery(final TSDB tsdb, final String uri) {
    final Channel channelMock = NettyMocks.fakeChannel();
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri);
    return new HttpQuery(tsdb, req, channelMock);
}
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)

Aggregations

Channel (org.jboss.netty.channel.Channel)176 InetSocketAddress (java.net.InetSocketAddress)53 Test (org.junit.Test)52 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)38 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)36 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)34 SocketAddress (java.net.SocketAddress)33 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)33 ChannelFuture (org.jboss.netty.channel.ChannelFuture)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)30 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)24 Test (org.testng.annotations.Test)23 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)22 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)19 IOException (java.io.IOException)19 Logger (org.apache.log4j.Logger)19 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)17 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)15 ArrayList (java.util.ArrayList)14 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)14