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.junit.Assert;
31 import org.junit.Test;
32
33
34
35
36
37
38 public class QueryParameterApplierTest {
39
40 @Test
41 public void testApplyOAuthParameters() throws Exception {
42
43 OAuthParametersApplier app = new QueryParameterApplier();
44
45 Map<String, Object> params = new HashMap<String, Object>();
46 params.put(OAuth.OAUTH_EXPIRES_IN, 3600l);
47 params.put(OAuth.OAUTH_ACCESS_TOKEN, "token_authz");
48 params.put(OAuth.OAUTH_CODE, "code_");
49 params.put(OAuth.OAUTH_SCOPE, "read");
50 params.put(OAuth.OAUTH_STATE, "state");
51 params.put("empty_param", "");
52 params.put("null_param", null);
53
54 OAuthMessage message = new DummyOAuthMessage("http://www.example.com/rd", 200);
55
56 app.applyOAuthParameters(message, params);
57
58 String locationURI = message.getLocationUri();
59 Assert.assertTrue(locationURI.contains("3600"));
60 Assert.assertTrue(locationURI.contains("token_authz"));
61 Assert.assertTrue(locationURI.contains("code_"));
62 Assert.assertTrue(locationURI.contains("read"));
63 Assert.assertTrue(locationURI.contains("state"));
64
65 Assert.assertTrue(!locationURI.contains("empty_param"));
66 Assert.assertTrue(!locationURI.contains("null_param"));
67
68
69 }
70 }