KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > attachments > Base64Test


1 /**
2  * Copyright 2001-2004 The Apache Software Foundation.
3  * <p/>
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * <p/>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p/>
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  * <p/>
16  */

17 package org.apache.axis2.attachments;
18
19 import junit.framework.TestCase;
20
21 import java.io.ByteArrayInputStream JavaDoc;
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.ObjectInputStream JavaDoc;
24 import java.io.ObjectOutputStream JavaDoc;
25
26 /**
27  * @author <a HREF="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
28  */

29 public class Base64Test extends TestCase {
30     
31     Object JavaDoc expectedObject;
32     
33     ByteArrayInputStream JavaDoc byteStream;
34     
35     /*
36      * Class under test for String encode(byte[])
37      */

38     
39     public void testEncodebyteArray() throws Exception JavaDoc {
40         Object JavaDoc actualObject;
41         String JavaDoc expectedBase64;
42         expectedObject = new String JavaDoc("Lanka Software Foundation");
43         ByteArrayOutputStream JavaDoc byteStream = new ByteArrayOutputStream JavaDoc();
44         ObjectOutputStream JavaDoc objectOutStream = new ObjectOutputStream JavaDoc(byteStream);
45         objectOutStream.writeObject(expectedObject);
46         expectedBase64 = Base64.encode(byteStream.toByteArray());
47         byte[] tempa = Base64.decode(expectedBase64);
48         ObjectInputStream JavaDoc objectInStream = new ObjectInputStream JavaDoc(
49                 new ByteArrayInputStream JavaDoc(tempa));
50         actualObject = objectInStream.readObject();
51         assertEquals("Base64 Encoding Check", expectedObject, actualObject);
52     }
53 }
Popular Tags