public void testResponseObject() throws Exception {
JaxRsHandler handler = HandlerCreator.getHandler(new HidingWriter2(),
new HidingWriter(), new MyResource());
Request requestMock = EasyMock.createNiceMock(Request.class);
final Response responseMock = EasyMock.createNiceMock(Response.class);
makeThreadSafe(responseMock, true);
final MessageBody body = new MessageBody2Read() {
@Override
public ReadableByteChannel read() throws IOException {
return Channels.newChannel(new ByteArrayInputStream(hiddenEntity.getBytes()));
}
};
responseMock.setBody(BodyMatcher.eqBody(body));
responseMock.addHeader(HeaderName.CONTENT_TYPE, "test/encoded-buffer");
responseMock.setHeader(HeaderName.CONTENT_LENGTH, (long)entity.length());
responseMock.setResponseStatus(ResponseStatus.SUCCESS);
expect(requestMock.getMethod()).andReturn(Method.GET);
RequestURI requestURI = EasyMock.createNiceMock(RequestURI.class);
expect(requestURI.getPath()).andReturn("/");
expect(requestMock.getRequestURI()).andReturn(requestURI);
replay(requestMock);
replay(requestURI);
replay(responseMock);
Thread thread = new Thread() {
@Override
public void run() {
try {
responseMock.setResponseStatus(ResponseStatus.SUCCESS);
responseMock.setHeader(HeaderName.CONTENT_LENGTH, (long)entity.length());
responseMock.addHeader(HeaderName.get(HeaderName.CONTENT_TYPE.toString()), "test/encoded-buffer");
responseMock.setBody(body);
} catch (HandlerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}