title: Unit testing views in dropwizard
body: <p>I'm trying to test that a view returned from a drowpizard resource is assembled correctly. Specifically, the view to add a user has a field that allows a password checker to reject an attempt to build a user if it fails to meet certain rules. The view works great when deploying and running the webapp, and specifying a bad password, but when I try to unit test it, it throws a web application exception saying there's no message body writer for the view.</p>
  
  <p>My unit test is pretty plain:</p>
  
  <pre><code>@Test
  public void testBadPassword(){
      ClientResponse response = null;
      try {
           response=client().resource("/users").post(ClientResponse.class, createUserParameters);
           Status status = response.getClientResponseStatus();
           assertEquals(Status.SEE_OTHER, status);
      } finally {
          if (response != null) {
              response.close();
          }
      }
  }
  </code></pre>
  
  <p>I get back a server 500 error, which has buried within the following:</p>
  
  <pre><code>javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class com.seeker.stm.resources.views.AddUserView, and Java type class com.seeker.stm.resources.views.AddUserView, and MIME media type text/html was not found
      at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285)
      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1448)
  </code></pre>
  
  <p>The resource dealing with the request and generating the views and responses looks like this:</p>
  
  <pre><code>@Path("/users")
  public class UserResource {
  
      public Object addUser(@FormParam("username") String username,
          @FormParam("password") String password,
          @FormParam("email") String email){
      Set&lt;String&gt; passwordErrors = passwordChecker.checkValidity(password, username, email);
      if (!passwordErrors.isEmpty()) {            
          return new AddUserView(userDAO.getAllActive(), passwordErrors);
      }
  
      // ...
  }
  </code></pre>
  
  <p>I can understand the exception (the writers it knows about, like StringProvider and ByteArrayProvider, don't work for a response or a view or something) but I'd more like to know how to properly test a resource that can return either a response code, or a view.</p>