1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.amber.oauth2.common.parameters;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.apache.amber.oauth2.common.OAuth;
28 import org.apache.amber.oauth2.common.message.OAuthMessage;
29 import org.apache.amber.oauth2.common.utils.DummyOAuthMessage;
30 import org.apache.amber.oauth2.common.utils.JSONUtils;
31 import org.junit.Assert;
32 import org.junit.Test;
33
34
35
36
37
38
39 public class JSONBodyParametersApplierTest {
40
41 @Test
42 public void testApplyOAuthParameters() throws Exception {
43
44 OAuthParametersApplier app = new JSONBodyParametersApplier();
45
46 Map<String, Object> params = new HashMap<String, Object>();
47 params.put(OAuth.OAUTH_EXPIRES_IN, 3600l);
48 params.put(OAuth.OAUTH_ACCESS_TOKEN, "token_authz");
49 params.put(OAuth.OAUTH_CODE, "code_");
50 params.put(OAuth.OAUTH_SCOPE, "read");
51 params.put(OAuth.OAUTH_STATE, "state");
52 params.put("empty_param", "");
53 params.put("null_param", null);
54 params.put("", "some_value");
55 params.put(null, "some_value");
56
57 OAuthMessage message = new DummyOAuthMessage("http://www.example.com/rd", 200);
58 app.applyOAuthParameters(message, params);
59
60 String msgBody = message.getBody();
61 Map<String, Object> map = JSONUtils.parseJSON(msgBody);
62 Assert.assertEquals(3600, map.get(OAuth.OAUTH_EXPIRES_IN));
63 Assert.assertEquals("token_authz", map.get(OAuth.OAUTH_ACCESS_TOKEN));
64 Assert.assertEquals("code_", map.get(OAuth.OAUTH_CODE));
65 Assert.assertEquals("read", map.get(OAuth.OAUTH_SCOPE));
66 Assert.assertEquals("state", map.get(OAuth.OAUTH_STATE));
67 Assert.assertNull(map.get("empty_param"));
68 Assert.assertNull(map.get("null_param"));
69 Assert.assertNull(map.get(""));
70 Assert.assertNull(map.get(null));
71 }
72 }