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.utils;
23  
24  import java.io.ByteArrayInputStream;
25  import java.io.InputStream;
26  import java.util.HashMap;
27  import java.util.HashSet;
28  import java.util.Map;
29  import java.util.Set;
30  
31  import org.apache.amber.oauth2.common.OAuth;
32  import org.apache.amber.oauth2.common.error.OAuthError;
33  import org.apache.amber.oauth2.common.exception.OAuthProblemException;
34  import org.junit.Assert;
35  import org.junit.Test;
36  
37  /**
38   *
39   *
40   *
41   */
42  public class OAuthUtilsTest {
43      @Test
44      public void testFormat() throws Exception {
45          Map<String, Object> parameters = new HashMap<String, Object>();
46          parameters.put("movie", "Kiler");
47          parameters.put("director", "Machulski");
48  
49  
50          String format = OAuthUtils.format(parameters.entrySet(), "UTF-8");
51          Assert.assertEquals("movie=Kiler&director=Machulski", format);
52      }
53  
54      @Test
55      public void testSaveStreamAsString() throws Exception {
56          String sampleTest = "It is raining again today";
57  
58          InputStream is = new ByteArrayInputStream(sampleTest.getBytes("UTF-8"));
59          Assert.assertEquals(sampleTest, OAuthUtils.saveStreamAsString(is));
60      }
61  
62      @Test
63      public void testHandleOAuthProblemException() throws Exception {
64          OAuthProblemException exception = OAuthUtils.handleOAuthProblemException("missing parameter");
65  
66          Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, exception.getError());
67          Assert.assertEquals("missing parameter", exception.getDescription());
68      }
69  
70      @Test
71      public void testHandleMissingParameters() throws Exception {
72          Set<String> missingParameters = new HashSet<String>();
73          missingParameters.add(OAuth.OAUTH_CLIENT_ID);
74          missingParameters.add(OAuth.OAUTH_CLIENT_SECRET);
75  
76          OAuthUtils.handleMissingParameters(missingParameters);
77      }
78  
79      @Test
80      public void testHandleNotAllowedParametersOAuthException() throws Exception {
81  
82      }
83  
84      @Test
85      public void testDecodeForm() throws Exception {
86  
87      }
88  
89      @Test
90      public void testIsFormEncoded() throws Exception {
91  
92      }
93  
94      @Test
95      public void testDecodePercent() throws Exception {
96  
97      }
98  
99      @Test
100     public void testPercentEncode() throws Exception {
101 
102     }
103 
104     @Test
105     public void testInstantiateClass() throws Exception {
106 
107     }
108 
109     @Test
110     public void testInstantiateClassWithParameters() throws Exception {
111 
112     }
113 
114     @Test
115     public void testGetAuthHeaderField() throws Exception {
116 
117     }
118 
119     @Test
120     public void testDecodeOAuthHeader() throws Exception {
121 
122     }
123 
124     @Test
125     public void testEncodeOAuthHeader() throws Exception {
126     	Map<String, Object> parameters = new HashMap<String, Object>();
127     	parameters.put("realm", "example");
128     	
129     	///rfc6750#section-3
130     	String header = OAuthUtils.encodeOAuthHeader(parameters);
131         Assert.assertEquals("Bearer realm=\"example\"", header);
132 
133     }
134     
135     @Test
136     public void testEncodeAuthorizationBearerHeader() throws Exception {
137     	Map<String, Object> parameters = new HashMap<String, Object>();
138     	parameters.put("accessToken", "mF_9.B5f-4.1JqM");
139     	
140     	//rfc6749#section-7.1
141     	String header = OAuthUtils.encodeAuthorizationBearerHeader(parameters);
142         Assert.assertEquals("Bearer mF_9.B5f-4.1JqM", header);
143 
144     }
145 
146     @Test
147     public void testIsEmpty() throws Exception {
148 
149     }
150 
151     @Test
152     public void testHasEmptyValues() throws Exception {
153 
154     }
155 
156     @Test
157     public void testGetAuthzMethod() throws Exception {
158 
159     }
160 
161     @Test
162     public void testHandleOAuthError() throws Exception {
163 
164     }
165 
166     @Test
167     public void testDecodeScopes() throws Exception {
168 
169     }
170 
171     @Test
172     public void testEncodeScopes() throws Exception {
173 
174     }
175 
176     @Test
177     public void testIsExpired() throws Exception {
178 
179     }
180 
181     @Test
182     public void testGetIssuedTimeInSec() throws Exception {
183 
184     }
185 
186     @Test
187     public void testIsMultipart() throws Exception {
188 
189     }
190 
191     @Test
192     public void testHasContentType() throws Exception {
193 
194     }
195 }