@Test
public void testJAFProviderBodyReader() throws Exception {
setup();
JaxRsHandler handler = HandlerCreator.getHandler(MyResource.class);
RequestImpl request = new RequestImpl();
RequestURIImpl uri = new RequestURIImpl();
uri.setPath("/");
String[] headervalues = new String[1];
headervalues[0] = "application/testobj";
request.setHeader(HeaderName.CONTENT_TYPE, headervalues);
JafSerializableObj testObj = new JafSerializableObj("foo", "bar");
// Serialize testObj
final ByteArrayOutputStream bous = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bous);
out.writeObject(testObj);
out.close();
MessageBody body = new MessageBody2Read() {
@Override
public ReadableByteChannel read() throws IOException {
return Channels.newChannel(new ByteArrayInputStream(bous.toByteArray()));
}
};
request.setMessageBody(body);
request.setRequestURI(uri);
request.setMethod(Method.GET);
Response response = new ResponseImpl();
handler.handle(request, response);
assertTrue(MyResource.myTestobj != null);
assertEquals("foo", MyResource.myTestobj.getField1());
assertEquals("bar", MyResource.myTestobj.getField2());
}