01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test;
23:
24: import junit.framework.TestCase;
25: import junit.framework.TestSuite;
26:
27: import org.jboss.security.Util;
28:
29: /** Tests of the org.jboss.security.Util class
30:
31: @author Scott.Stark@jboss.org
32: @version $Revision: 55378 $
33: */
34: public class UtilTestCase extends TestCase {
35: public UtilTestCase(String name) {
36: super (name);
37: }
38:
39: /** Compare Util.encodeBase64 against the sun misc class
40: */
41: public void testBase64() throws Exception {
42: System.out.println("testBase64");
43: byte[] test = "echoman".getBytes();
44: String b64_1 = Util.encodeBase64(test);
45: System.out.println("b64_1 = " + b64_1);
46:
47: //sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
48: //String b64_2 = encoder.encode(test);
49: String b64_2 = javax.mail.internet.MimeUtility.encodeText(
50: "echoman", "iso-8859-1", "base64");
51: System.out.println("b64_2 = " + b64_2);
52: super .assertEquals("encodeBase64 == BASE64Encoder", b64_1,
53: b64_2);
54: }
55:
56: /** Compare Util.encodeBase16 against the java.math.BigInteger class
57: */
58: public void testBase16() throws Exception {
59: System.out.println("testBase16");
60: byte[] test = "echoman".getBytes();
61: String b16_1 = Util.encodeBase16(test);
62: System.out.println("b16_1 = " + b16_1);
63:
64: java.math.BigInteger encoder = new java.math.BigInteger(test);
65: String b16_2 = encoder.toString(16);
66: System.out.println("b16_2 = " + b16_2);
67: super .assertEquals("encodeBase16 == BigInteger", b16_1, b16_2);
68: }
69:
70: public static void main(java.lang.String[] args) {
71: System.setErr(System.out);
72: TestSuite suite = new TestSuite(UtilTestCase.class);
73: junit.textui.TestRunner.run(suite);
74: }
75: }
|