View Javadoc

1   /**
2    *       Copyright 2010 Newcastle University
3    *
4    *          http://research.ncl.ac.uk/smart/
5    *
6    * Licensed to the Apache Software Foundation (ASF) under one or more
7    * contributor license agreements.  See the NOTICE file distributed with
8    * this work for additional information regarding copyright ownership.
9    * The ASF licenses this file to You under the Apache License, Version 2.0
10   * (the "License"); you may not use this file except in compliance with
11   * the License.  You may obtain a copy of the License at
12   *
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
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 BodyURLEncodedParametersApplierTest {
39  
40      @Test
41      public void testApplyOAuthParameters() throws Exception {
42  
43          OAuthParametersApplier app = new BodyURLEncodedParametersApplier();
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          params.put("", "some_value");
54          params.put(null, "some_value");
55  
56          OAuthMessage message = new DummyOAuthMessage("http://www.example.com/rd", 200);
57  
58          app.applyOAuthParameters(message, params);
59  
60          String body = message.getBody();
61          Assert.assertTrue(body.contains("3600"));
62          Assert.assertTrue(body.contains("token_authz"));
63          Assert.assertTrue(body.contains("code_"));
64          Assert.assertTrue(body.contains("read"));
65          Assert.assertTrue(body.contains("state"));
66  
67          Assert.assertFalse(body.contains("empty_param"));
68          Assert.assertFalse(body.contains("null_param"));
69  
70  
71      }
72  }