@Test
public void tesPost1() throws Exception {
JaxRsHandler handler = HandlerCreator.getHandler(MyRootResource.class);
RequestURIImpl uri = new RequestURIImpl();
RequestImpl request = new RequestImpl();
ResponseImpl response = new ResponseImpl();
String queryParam = "post1";
final String bodyString = "body";
uri.setPath("foo");
uri.setQuery("name="+queryParam);
request.setRequestURI(uri);
String[] headervalues = new String[1];
headervalues[0]="text/plain";
request.setHeader(HeaderName.CONTENT_TYPE, headervalues);
MessageBody messageBody = new MessageBody2Read() {
@Override
public ReadableByteChannel read() throws IOException {
return Channels.newChannel(new ByteArrayInputStream(bodyString.getBytes()));
}
};
request.setMessageBody(messageBody);
request.setMethod(Method.POST);
handler.handle(request, response);
Assert.assertEquals(queryParam, value);
Assert.assertEquals(bodyString, body);