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.OAuthResponse;
29  import org.junit.Assert;
30  import org.junit.Test;
31  
32  /**
33   *
34   *
35   *
36   */
37  public class WWWAuthHeaderParametersApplierTest {
38  
39      @Test
40      public void testApplyOAuthParameters() throws Exception {
41  
42          Map<String, Object> params = new HashMap<String, Object>();
43          params.put("error", "invalid_token");
44          params.put("error_uri", "http://www.example.com/error");
45          params.put("scope", "s1 s2 s3");
46          params.put("empty_param", "");
47          params.put("null_param", null);
48          params.put("", "some_value");
49          params.put(null, "some_value");
50  
51          OAuthResponse res = OAuthResponse.status(200).location("").buildQueryMessage();
52  
53          OAuthParametersApplier applier = new WWWAuthHeaderParametersApplier();
54          res = (OAuthResponse)applier.applyOAuthParameters(res, params);
55          Assert.assertNotNull(res);
56          String header = res.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE);
57          Assert.assertNotNull(header);
58          Assert.assertEquals(OAuth.OAUTH_HEADER_NAME
59              + " scope=\"s1 s2 s3\",error_uri=\"http://www.example.com/error\",error=\"invalid_token\"",
60              header);
61  
62  
63      }
64  
65  }