View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   *
17   */
18  
19  package org.apache.commons.net.util;
20  
21  import static org.junit.Assert.*;
22  
23  import java.util.Arrays;
24  
25  import org.junit.Ignore;
26  import org.junit.Test;
27  
28  public class Base64Test {
29  
30      @Test
31      public void testBase64() {
32          Base64 b64 = new Base64();
33          assertFalse(b64.isUrlSafe());
34      }
35  
36      @Test
37      public void testBase64Boolean() {
38          Base64 b64 = new Base64(true);
39          assertTrue(b64.isUrlSafe());
40          assertTrue(Arrays.equals(new byte[]{'\r','\n'}, b64.getLineSeparator()));
41      }
42  
43      @Test
44      public void testBase64Int() {
45          Base64 b64;
46          b64 = new Base64(8);
47          assertFalse(b64.isUrlSafe());
48          assertEquals(8, b64.getLineLength());
49          b64 = new Base64(11);
50          assertEquals(8, b64.getLineLength());
51      }
52  
53      @Test
54      public void testBase64IntByteArray() {
55          Base64 b64;
56          b64 = new Base64(8, new byte[]{});
57          assertFalse(b64.isUrlSafe());
58          assertTrue(Arrays.equals(new byte[]{}, b64.getLineSeparator()));
59      }
60  
61      @Test
62      public void testBase64IntByteArrayBoolean() {
63          Base64 b64;
64          b64 = new Base64(8, new byte[]{}, false);
65          assertFalse(b64.isUrlSafe());
66          b64 = new Base64(8, new byte[]{}, true);
67          assertTrue(b64.isUrlSafe());
68      }
69  
70      @Test
71      public void testIsBase64() {
72          assertTrue(Base64.isBase64((byte)'b'));
73          assertFalse(Base64.isBase64((byte)' '));
74      }
75  
76      @Test
77      public void testIsArrayByteBase64() {
78          assertTrue(Base64.isArrayByteBase64(new byte[]{'b',' '}));
79          assertFalse(Base64.isArrayByteBase64(new byte[]{'?'}));
80      }
81  
82      @Test
83      public void testEncodeBase64ByteArray() {
84          byte[] binaryData=null;
85          assertTrue(Arrays.equals(binaryData, Base64.encodeBase64(binaryData)));
86      }
87  
88      @Test @Ignore
89      public void testEncodeBase64StringByteArray() {
90          fail("Not yet implemented");
91      }
92  
93      @Test @Ignore
94      public void testEncodeBase64StringUnChunked() {
95          fail("Not yet implemented");
96      }
97  
98      @Test @Ignore
99      public void testEncodeBase64StringByteArrayBoolean() {
100         fail("Not yet implemented");
101     }
102 
103     @Test @Ignore
104     public void testEncodeBase64URLSafe() {
105         fail("Not yet implemented");
106     }
107 
108     @Test @Ignore
109     public void testEncodeBase64URLSafeString() {
110         fail("Not yet implemented");
111     }
112 
113     @Test @Ignore
114     public void testEncodeBase64Chunked() {
115         fail("Not yet implemented");
116     }
117 
118     @Test @Ignore
119     public void testDecodeObject() {
120         fail("Not yet implemented");
121     }
122 
123     @Test @Ignore
124     public void testDecodeString() {
125         fail("Not yet implemented");
126     }
127 
128     @Test @Ignore
129     public void testDecodeByteArray() {
130         fail("Not yet implemented");
131     }
132 
133     @Test @Ignore
134     public void testEncodeBase64ByteArrayBoolean() {
135         fail("Not yet implemented");
136     }
137 
138     @Test @Ignore
139     public void testEncodeBase64ByteArrayBooleanBoolean() {
140         fail("Not yet implemented");
141     }
142 
143     @Test
144     public void testEncodeBase64ByteArrayBooleanBooleanInt() {
145         byte[] binaryData = new byte[]{'1','2','3'};
146         byte[] encoded;
147         encoded = Base64.encodeBase64(binaryData, false, false);
148         assertNotNull(encoded);
149         assertEquals(4, encoded.length);
150         try {
151             Base64.encodeBase64(binaryData, false, false, 3);
152             fail("Expected IllegalArgumentException");
153         } catch (IllegalArgumentException expected) {
154             // expected
155         }
156         encoded = Base64.encodeBase64(binaryData, false, false, 4); // NET-483
157         assertNotNull(encoded);
158         assertEquals(4, encoded.length);
159         encoded = Base64.encodeBase64(binaryData, true, false);
160         assertNotNull(encoded);
161         assertEquals(6, encoded.length); // always adds trailer
162         try {
163             Base64.encodeBase64(binaryData, true, false, 5);
164             fail("Expected IllegalArgumentException");
165         } catch (IllegalArgumentException expected) {
166             // expected
167         }
168         encoded = Base64.encodeBase64(binaryData, true, false, 6);
169         assertNotNull(encoded);
170         assertEquals(6, encoded.length);
171     }
172 
173     @Test @Ignore
174     public void testDecodeBase64String() {
175         fail("Not yet implemented");
176     }
177 
178     @Test @Ignore
179     public void testDecodeBase64ByteArray() {
180         fail("Not yet implemented");
181     }
182 
183     @Test @Ignore
184     public void testEncodeObject() {
185         fail("Not yet implemented");
186     }
187 
188     @Test @Ignore
189     public void testEncodeToString() {
190         fail("Not yet implemented");
191     }
192 
193     @Test @Ignore
194     public void testEncodeByteArray() {
195         fail("Not yet implemented");
196     }
197 
198     @Test @Ignore
199     public void testDecodeInteger() {
200         fail("Not yet implemented");
201     }
202 
203     @Test @Ignore
204     public void testEncodeInteger() {
205         fail("Not yet implemented");
206     }
207 
208     @Test @Ignore
209     public void testToIntegerBytes() {
210         fail("Not yet implemented");
211     }
212 
213 }