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 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  }