@Test
  public void shouldSignHttpRequestMessage() throws Exception {

    OAuthConsumer consumer =
        new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET, SignatureMethod.HMAC_SHA1);

    consumer.setTokenWithSecret(TOKEN, TOKEN_SECRET);

    consumer.sign(request);

    Header authHeader = request.getFirstHeader("Authorization");
    assertNotNull(authHeader);

    String oauthHeader = authHeader.getValue();
    assertTrue(oauthHeader.startsWith("OAuth "));

    HashMap<String, String> params = oauthHeaderToParamsMap(oauthHeader);
    assertNotNull(params.get("oauth_consumer_key"));
    assertNotNull(params.get("oauth_token"));
    assertNotNull(params.get("oauth_signature_method"));
    assertNotNull(params.get("oauth_signature"));
    assertNotNull(params.get("oauth_timestamp"));
    assertNotNull(params.get("oauth_nonce"));
    assertNotNull(params.get("oauth_version"));
  }
  @Test
  public void shouldPercentEncodeOAuthParameters() throws Exception {
    OAuthConsumer consumer =
        new DefaultOAuthConsumer("1%2", CONSUMER_SECRET, SignatureMethod.HMAC_SHA1);
    consumer.setTokenWithSecret("3 4", TOKEN_SECRET);

    consumer.sign(request);

    Header authHeader = request.getFirstHeader("Authorization");
    assertNotNull(authHeader);

    String oauthHeader = authHeader.getValue();

    HashMap<String, String> params = oauthHeaderToParamsMap(oauthHeader);
    assertEquals("\"1%252\"", params.get("oauth_consumer_key"));
    assertEquals("\"3%204\"", params.get("oauth_token"));
  }