1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.trinidad.util;
20
21 import java.io.IOException;
22 import java.io.StringReader;
23 import java.io.BufferedReader;
24
25 import junit.framework.Test;
26 import junit.framework.TestSuite;
27
28 import org.apache.myfaces.trinidad.util.Base64InputStream;
29 import org.apache.myfaces.trinidadbuild.test.FacesTestCase;
30
31
32
33
34
35
36 public class Base64InputStreamTest extends FacesTestCase
37 {
38
39
40
41
42
43
44 public Base64InputStreamTest(String testName)
45 {
46 super(testName);
47 }
48
49 @Override
50 protected void setUp() throws Exception
51 {
52 super.setUp();
53 }
54
55 @Override
56 protected void tearDown() throws Exception
57 {
58 super.tearDown();
59 }
60
61 public static Test suite()
62 {
63 return new TestSuite(Base64InputStreamTest.class);
64 }
65
66
67
68
69 public void testNoPaddingChar() throws IOException
70 {
71 String str = "abcdefghijklmnopqrstuvwxBase64 Encoding is a popular way to convert the 8bit and the binary to the 7bit for network trans using Socket, and a security method to handle text or file, often used in Authentical Login and Mail Attachment, also stored in text file or database. Most SMTP server will handle the login UserName and Password in this way. 1";
72 String str_encoded = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5LiAx";
73
74 _testRead(str, str_encoded);
75
76 }
77
78
79
80
81 public void testOnePaddingChar() throws IOException
82 {
83 String str = "Base64 Encoding is a popular way to convert the 8bit and the binary to the 7bit for network trans using Socket, and a security method to handle text or file, often used in Authentical Login and Mail Attachment, also stored in text file or database. Most SMTP server will handle the login UserName and Password in this way.9";
84 String str_encoded = "QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5Ljk=";
85
86 _testRead(str, str_encoded);
87
88 }
89
90
91
92
93 public void testTwoPaddingChars() throws IOException
94 {
95 String str = "Base64 Encoding is a popular way to convert the 8bit and the binary to the 7bit for network trans using Socket, and a security method to handle text or file, often used in Authentical Login and Mail Attachment, also stored in text file or database. Most SMTP server will handle the login UserName and Password in this way.";
96 String str_encoded = "QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5Lg==";
97
98 _testRead(str, str_encoded);
99
100 }
101
102
103
104
105
106
107
108
109
110
111
112
113 private void _testRead(String str, String str_encoded) throws IOException
114 {
115
116
117 StringReader strreader = new StringReader(str_encoded);
118 BufferedReader buffreader = new BufferedReader(strreader);
119 Base64InputStream b64_in = new Base64InputStream(buffreader);
120
121
122 String result = "";
123 int c;
124 while ( (c = b64_in.read()) != -1 )
125 {
126 result = result + (char)c;
127 }
128
129
130 assertEquals(result, str);
131 }
132
133
134
135 }