package com.sanction.thunder;

import com.sanction.thunder.models.PilotUser;
import io.dropwizard.testing.junit.DropwizardClientRule;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.junit.ClassRule;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ThunderClientTest {
  private static final PilotUser user =
      new PilotUser("username", "password", "fbaccess", "twaccess", "twsecret");
  private static final String password = "password";

  /**
   * Resource to be used as a test double.
   */
  @Path("/users")
  @Produces(MediaType.APPLICATION_JSON)
  public static final class TestResource {

    @POST
    public Response postUser() {
      return Response.status(Response.Status.CREATED)
          .entity(user).build();
    }

    @PUT
    public Response updateUser() {
      return Response.status(Response.Status.OK)
          .entity(user).build();
    }

    @GET
    public Response getUser() {
      return Response.status(Response.Status.OK)
          .entity(user).build();
    }

    @DELETE
    public Response deleteUser() {
      return Response.status(Response.Status.OK)
          .entity(user).build();
    }
  }

  @ClassRule
  public static final DropwizardClientRule dropwizard
      = new DropwizardClientRule(new TestResource());

  private final ThunderBuilder builder =
      new ThunderBuilder(dropwizard.baseUri().toString(), "userKey", "userSecret");
  private final ThunderClient client = builder.newThunderClient();

  @Test
  public void testPostUser() {
    PilotUser response = client.postUser(user);
    assertEquals(user.getUsername(), response.getUsername());
  }

  @Test
  public void testUpdateUser() {
    PilotUser response = client.updateUser(password, user);
    assertEquals(user.getUsername(), response.getUsername());
  }

  @Test
  public void testGetUser() {
    PilotUser response = client.getUser(password, "username");
    assertEquals(user.getUsername(), response.getUsername());
  }

  @Test
  public void testDeleteUser() {
    PilotUser response = client.deleteUser(password, "username");
    assertEquals(user.getUsername(), response.getUsername());
  }

}

@@ -179,16 +179,48 @@
 rs.GET;%0A
+import javax.ws.rs.HeaderParam;%0A
 import j
@@ -314,16 +314,47 @@
 oduces;%0A
+import javax.ws.rs.QueryParam;%0A
 import j
@@ -772,563 +772,1715 @@
 ble.
-%0A   */%0A  @Path(%22/users%22)%0A  @Produces(MediaType.APPLICATION_JSON)%0A  public static final class TestResource %7B%0A%0A    @POST%0A    public Response postUser() %7B%0A      return Response.status(Response.Status.CREATED)%0A          .entity(user).build();%0A    %7D%0A%0A    @PUT%0A    public Response updateUser() %7B%0A      return Response.status(Response.Status.OK)%0A          .entity(user).build();%0A    %7D%0A%0A    @GET%0A    public Response getUser() %7B%0A      return Response.status(Response.Status.OK)%0A          .entity(user).build();%0A    %7D%0A%0A    @DELETE%0A    public Response deleteUser() %7B
+ Requests from the ThunderClient interface%0A   * will be directed here for the unit tests. Use this to verify that all parameters are%0A   * being set correctly.%0A   */%0A  @Path(%22/users%22)%0A  @Produces(MediaType.APPLICATION_JSON)%0A  public static final class TestResource %7B%0A%0A    @POST%0A    public Response postUser(PilotUser user) %7B%0A      if (user == null) %7B%0A        return Response.status(Response.Status.BAD_REQUEST)%0A            .entity(null).build();%0A      %7D%0A%0A      return Response.status(Response.Status.CREATED)%0A          .entity(user).build();%0A    %7D%0A%0A    @PUT%0A    public Response updateUser(@HeaderParam(%22password%22) String password, PilotUser user) %7B%0A      if (password == null %7C%7C password.equals(%22%22) %7C%7C user == null) %7B%0A        return Response.status(Response.Status.BAD_REQUEST)%0A            .entity(null).build();%0A      %7D%0A%0A      return Response.status(Response.Status.OK)%0A          .entity(user).build();%0A    %7D%0A%0A    @GET%0A    public Response getUser(@QueryParam(%22username%22) String username,%0A                            @HeaderParam(%22password%22) String password) %7B%0A      if (username == null %7C%7C username.equals(%22%22) %7C%7C password == null %7C%7C password.equals(%22%22)) %7B%0A        return Response.status(Response.Status.BAD_REQUEST)%0A            .entity(null).build();%0A      %7D%0A%0A      return Response.status(Response.Status.OK)%0A          .entity(user).build();%0A    %7D%0A%0A    @DELETE%0A    public Response deleteUser(@QueryParam(%22username%22) String username,%0A                               @HeaderParam(%22password%22) String password) %7B%0A      if (username == null %7C%7C username.equals(%22%22) %7C%7C password == null %7C%7C password.equals(%22%22)) %7B%0A        return Response.status(Response.Status.BAD_REQUEST)%0A            .entity(null).build();%0A      %7D%0A
 %0A   

Improve Client tests