@Test
public void testPostWithEntity() throws Exception
{
// Test a request with an entity and a query string, to be encoded as multipart/mixed
RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279?q=one&x=10&y=15"))
.setMethod("POST")
.setEntity(new String("{\name\":\"value\"}").getBytes())
.setHeader("Content-Type", "application/json").build();
// Test Conversion, should have a multipart body
RestRequest encoded = QueryTunnelUtil.encode(request, 0);
Assert.assertEquals(encoded.getMethod(), "POST");
Assert.assertEquals(encoded.getURI().toString(), "http://localhost:7279");
Assert.assertTrue(encoded.getEntity().length() > 0);
Assert.assertTrue(encoded.getHeader("Content-Type").startsWith("multipart/mixed"));
// Decode, and we should get the original request back
RestRequest decoded = QueryTunnelUtil.decode(encoded);
Assert.assertEquals(request.getURI(), decoded.getURI());
Assert.assertEquals(request.getMethod(), decoded.getMethod());
Assert.assertEquals(request.getEntity(), decoded.getEntity());
Assert.assertEquals(request.getHeader("Content-Type"), decoded.getHeader("Content-Type"));
}