title: JerseyTest WebTarget POST support
body: <p>I am developing a light weight server App with a RESTful api implemented with Jersey 2.12 and Jackson 2.</p>
  
  <p>I am writing tests while developing using JUnit and JerseyTest. I know that my Jersey Resources work as expected including the marshalling from and to JSON because I tested them manually with the PostMan Chrome plugin.</p>
  
  <p>My GET tests with query parameters work well too, based on the example in the <a href="https://jersey.java.net/documentation/latest/test-framework.html#d0e15485" rel="nofollow">Jersey documentation</a>
  Here is a simplified (I have left out boilerplate code to make the idea clearer) example of a test I'd like to write:</p>
  
  <pre><code>import static org.junit.Assert.assertTrue;
  
  import javax.ws.rs.client.Entity;
  import javax.ws.rs.client.WebTarget;
  import javax.ws.rs.core.Application;
  import javax.ws.rs.core.Response;
  
  import org.glassfish.jersey.server.ResourceConfig;
  import org.glassfish.jersey.test.JerseyTest;
  import org.junit.Test;
  
  import com.acme.api.rest.SessionsEndPoint;
  import com.acme.api.rest.beans.UserCredentialsBean;
  
  public class TestSession extends JerseyTest {
  
      @Override
      protected Application configure() {
          return new ResourceConfig(SessionsEndPoint.class);
      }
  
      @Test
      public void test() {
          UserCredentialsBean userCredentialsBean = new UserCredentialsBean();
          userCredentialsBean.setUserId("alice");
          userCredentialsBean.setPassword("secret");
          WebTarget theTarget = target("sessions/login");
          Response response = theTarget.request().post( Entity.entity(UserCredentialsBean.class, "application/json"));
          assertTrue(true);
      }
  
  }
  </code></pre>
  
  <p>The basic problem I have is that I cannot find any documentation on how to properly use the WebTarget class for post requests. the WebTarget theTarget is constructed correctly but the line:</p>
  
  <pre><code>Response response = theTarget.request().post( Entity.entity(UserCredentialsBean.class, "application/json"));
  </code></pre>
  
  <p>does not work.</p>
  
  <p>As I understand the WebTarget class is fairly new in the JerseyTest framework. Is there anybody who can point me at any recent documentation, examples, or just explain here how I can get this to work?</p>