use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project opentsdb by OpenTSDB.
the class TestSuggestRpc 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.GET, "/api/suggest?type=metrics&q=h");
req.setMethod(HttpMethod.PUT);
s.execute(tsdb, new HttpQuery(tsdb, req, channelMock));
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project opentsdb by OpenTSDB.
the class TestTreeRpc method handleRuleBadMethod.
@Test(expected = BadRequestException.class)
public void handleRuleBadMethod() throws Exception {
final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.TRACE, "/api/tree/rule");
final HttpQuery query = new HttpQuery(tsdb, req, NettyMocks.fakeChannel());
rpc.execute(tsdb, query);
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project opentsdb by OpenTSDB.
the class TestRpcHandler method httpCORSPublicSimple.
@Test
public void httpCORSPublicSimple() {
final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/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.OK, response.getStatus());
assertEquals("42.com", response.headers().get(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
return null;
}
});
tsdb.getConfig().overrideConfig("tsd.http.request.cors_domains", "*");
final RpcHandler rpc = new RpcHandler(tsdb, rpc_manager);
rpc.messageReceived(ctx, message);
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project opentsdb by OpenTSDB.
the class TestRpcHandler method createQueryInstanceForBuiltin.
@Test
public void createQueryInstanceForBuiltin() throws Exception {
final RpcHandler rpc = new RpcHandler(tsdb, rpc_manager);
final Channel mockChan = NettyMocks.fakeChannel();
final Method meth = Whitebox.getMethod(RpcHandler.class, "createQueryInstance", TSDB.class, HttpRequest.class, Channel.class);
AbstractHttpQuery query = (AbstractHttpQuery) meth.invoke(rpc, tsdb, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/api/v1/version"), mockChan);
assertTrue(query instanceof HttpQuery);
query = (AbstractHttpQuery) meth.invoke(rpc, tsdb, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/api/version"), mockChan);
assertTrue(query instanceof HttpQuery);
query = (AbstractHttpQuery) meth.invoke(rpc, tsdb, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/q"), mockChan);
assertTrue(query instanceof HttpQuery);
query = (AbstractHttpQuery) meth.invoke(rpc, tsdb, new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/"), mockChan);
assertTrue(query instanceof HttpQuery);
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project opentsdb by OpenTSDB.
the class TestRpcHandler method httpCORSIgnored.
@Test
public void httpCORSIgnored() {
final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/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.OK, 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);
}
Aggregations