KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > UtilTestCase


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package org.jboss.test;
8
9 import junit.framework.TestCase;
10 import junit.framework.TestSuite;
11
12 import org.jboss.security.Util;
13
14 /** Tests of the org.jboss.security.Util class
15  
16  @author Scott.Stark@jboss.org
17  @version $Revision: 1.1.26.1 $
18  */

19 public class UtilTestCase extends TestCase
20 {
21    public UtilTestCase(String JavaDoc name)
22    {
23       super(name);
24    }
25    
26    /** Compare Util.encodeBase64 against the sun misc class
27     */

28    public void testBase64() throws Exception JavaDoc
29    {
30       System.out.println("testBase64");
31       byte[] test = "echoman".getBytes();
32       String JavaDoc b64_1 = Util.encodeBase64(test);
33       System.out.println("b64_1 = "+b64_1);
34
35       sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
36       String JavaDoc b64_2 = encoder.encode(test);
37       System.out.println("b64_2 = "+b64_2);
38       super.assertEquals("encodeBase64 == BASE64Encoder", b64_1, b64_2);
39    }
40
41    /** Compare Util.encodeBase16 against the java.math.BigInteger class
42     */

43    public void testBase16() throws Exception JavaDoc
44    {
45       System.out.println("testBase16");
46       byte[] test = "echoman".getBytes();
47       String JavaDoc b16_1 = Util.encodeBase16(test);
48       System.out.println("b16_1 = "+b16_1);
49
50       java.math.BigInteger JavaDoc encoder = new java.math.BigInteger JavaDoc(test);
51       String JavaDoc b16_2 = encoder.toString(16);
52       System.out.println("b16_2 = "+b16_2);
53       super.assertEquals("encodeBase16 == BigInteger", b16_1, b16_2);
54    }
55
56    public static void main(java.lang.String JavaDoc[] args)
57    {
58       System.setErr(System.out);
59       TestSuite suite = new TestSuite(UtilTestCase.class);
60       junit.textui.TestRunner.run(suite);
61    }
62 }
63
Popular Tags