@Test
public void shouldNormalizeParameters() throws Exception {
// should ignore signature, callback, and realm params
HttpParameters params = new HttpParameters();
params.put("a", "1", true);
params.put("realm", "www.example.com", true);
params.put("oauth_signature", "12345", true);
String result = new SignatureBaseString(httpGetMock, params).normalizeRequestParameters();
assertEquals("a=1", result);
// example from OAuth spec
params = new HttpParameters();
params.put("a", "1", true);
params.put("c", "hi there", true);
params.put("f", "25", true);
params.put("f", "50", true);
params.put("f", "a", true);
params.put("z", "p", true);
params.put("z", "t", true);
String expected = "a=1&c=hi%20there&f=25&f=50&f=a&z=p&z=t";
result = new SignatureBaseString(httpGetMock, params).normalizeRequestParameters();
assertEquals(expected, result);
// examples from the official test cases on
// http://oauth.pbwiki.com/TestCases
params = new HttpParameters();
params.put("a", "x!y", true);
params.put("a", "x y", true);
expected = "a=x%20y&a=x%21y";
result = new SignatureBaseString(httpGetMock, params).normalizeRequestParameters();
assertEquals(expected, result);
params = new HttpParameters();
params.put("name", "", true);
assertEquals("name=", new SignatureBaseString(httpGetMock, params)
.normalizeRequestParameters());
params.putNull("name", null);
assertEquals("name=", new SignatureBaseString(httpGetMock, params)
.normalizeRequestParameters());
}