SignatureBaseString { public String normalizeRequestParameters() throws IOException { if (requestParameters == null) { return ""; } StringBuilder sb = new StringBuilder(); Iterator<String> iter = requestParameters.keySet().iterator(); for (int i = 0; iter.hasNext(); i++) { String param = iter.next(); if (OAuth.OAUTH_SIGNATURE.equals(param) || "realm".equals(param)) { continue; } if (i > 0) { sb.append("&"); } sb.append(requestParameters.getAsQueryString(param, false)); } return sb.toString(); } SignatureBaseString(HttpRequest request, HttpParameters requestParameters); String generate(); String normalizeRequestUrl(); String normalizeRequestParameters();  }
@Test public void shouldNormalizeParameters() throws Exception { 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); 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); 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()); }