@Test
  public void shouldBadRequest() throws Exception {
    String email = "*****@*****.**";

    UserResult userResult;
    Client client = createClient();
    WebResource webResource = client.resource(ringringServerApi.getUrl() + "/user");

    // Create request hash with email address using wrong key
    HashMap<String, String> requestHash = new HashMap<String, String>();
    requestHash.put("email_wrong_key", email);

    // First email registration
    userResult =
        webResource
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(UserResult.class, requestHash);
    assertEquals(Status.BAD_REQUEST, userResult.getStatus());
    assertNull(userResult.getUser());

    // Create request hash with email address
    HashMap<String, List<String>> emailsRequestHash = new HashMap<String, List<String>>();
    List<String> userEmails =
        Arrays.asList(
            "*****@*****.**",
            "*****@*****.**",
            "*****@*****.**",
            "*****@*****.**");

    // Put emails list into requestHash with wrong hash key
    emailsRequestHash.put("emails_wrong_key", userEmails);

    webResource = client.resource(ringringServerApi.getUrl() + "/user/list");
    UserListResult userListResult =
        webResource
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(UserListResult.class, emailsRequestHash);
    assertEquals(Status.BAD_REQUEST, userListResult.getStatus());
    assertNull(userListResult.getUsers());

    // Invite email with wrong key
    HashMap<String, String> inviteRequestHash = new HashMap<String, String>();
    inviteRequestHash.put("email_wrong_key", email);
    inviteRequestHash.put("to_email", email);

    webResource = client.resource(ringringServerApi.getUrl() + "/user/" + email + "/invite");
    StatusResult statusResult =
        webResource
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(StatusResult.class, inviteRequestHash);
    assertEquals(Status.BAD_REQUEST, statusResult.getStatus());
  }
  @Test
  public void shouldGetUsersByEmailList() throws Exception {
    String email1 = "*****@*****.**";
    String email2 = "*****@*****.**";
    String email3 = "*****@*****.**";

    UserResult userResult;
    Client client = createClient();
    WebResource webResource = client.resource(ringringServerApi.getUrl() + "/user");

    // Create request hash with email address
    HashMap<String, String> requestHash = new HashMap<String, String>();
    requestHash.put("email", email1);

    // First email registration
    userResult =
        webResource
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(UserResult.class, requestHash);
    assertEquals(Status.OKAY, userResult.getStatus());
    User user1 = userResult.getUser();

    // Get first activation code from email
    MimeMessage message1 = getLastMail().getMimeMessage();
    String activationCode1 = getActivationCodeFromEmailContent(message1.getContent().toString());
    user1.setActivationCode(activationCode1);

    // Second email registration
    requestHash.clear();
    requestHash.put("email", email2);

    userResult =
        webResource
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(UserResult.class, requestHash);
    assertEquals(Status.OKAY, userResult.getStatus());
    User user2 = userResult.getUser();

    // Get second activation code from email
    MimeMessage message2 = getLastMail().getMimeMessage();
    String activationCode2 = getActivationCodeFromEmailContent(message2.getContent().toString());
    user2.setActivationCode(activationCode2);

    // Third email registration
    requestHash.clear();
    requestHash.put("email", email3);

    userResult =
        webResource
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(UserResult.class, requestHash);
    assertEquals(Status.OKAY, userResult.getStatus());
    User user3 = userResult.getUser();

    // Get first activation code from email
    MimeMessage message3 = getLastMail().getMimeMessage();
    String activationCode3 = getActivationCodeFromEmailContent(message3.getContent().toString());
    user3.setActivationCode(activationCode3);

    // Activate two users from the three (1st and 3rd)
    webResource = client.resource(ringringServerApi.getUrl() + "/user/" + user1.getEmail());
    StatusResult statusResult =
        webResource
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .put(StatusResult.class, user1);
    assertEquals(Status.OKAY, statusResult.getStatus());

    webResource = client.resource(ringringServerApi.getUrl() + "/user/" + user3.getEmail());
    statusResult =
        webResource
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .put(StatusResult.class, user3);
    assertEquals(Status.OKAY, statusResult.getStatus());

    // Get the user list
    // Create request hash with email address
    HashMap<String, List<String>> emailsRequestHash = new HashMap<String, List<String>>();

    List<String> userEmails =
        Arrays.asList(
            "*****@*****.**",
            "*****@*****.**",
            "*****@*****.**",
            "*****@*****.**");
    emailsRequestHash.put("emails", userEmails);

    webResource = client.resource(ringringServerApi.getUrl() + "/user/list");
    UserListResult userListResult =
        webResource
            .type(MediaType.APPLICATION_JSON_TYPE)
            .accept(MediaType.APPLICATION_JSON_TYPE)
            .post(UserListResult.class, emailsRequestHash);

    // Should be only two activated users from all of them
    assertEquals(2, userListResult.getUsers().size());
  }