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());
}
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())));
}
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());
}
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);
}
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);
}
Aggregations