From adffaces-commits-return-248-apmail-incubator-adffaces-commits-archive=incubator.apache.org@incubator.apache.org Tue Jul 25 03:55:54 2006 Return-Path: Delivered-To: apmail-incubator-adffaces-commits-archive@locus.apache.org Received: (qmail 27309 invoked from network); 25 Jul 2006 03:55:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Jul 2006 03:55:54 -0000 Received: (qmail 98955 invoked by uid 500); 25 Jul 2006 03:55:54 -0000 Delivered-To: apmail-incubator-adffaces-commits-archive@incubator.apache.org Received: (qmail 98938 invoked by uid 500); 25 Jul 2006 03:55:54 -0000 Mailing-List: contact adffaces-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: adffaces-dev@incubator.apache.org Delivered-To: mailing list adffaces-commits@incubator.apache.org Received: (qmail 98929 invoked by uid 99); 25 Jul 2006 03:55:54 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Jul 2006 20:55:54 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Jul 2006 20:55:51 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 664F91A9829; Mon, 24 Jul 2006 20:55:05 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r425268 [7/7] - in /incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src: main/java-templates/org/apache/myfaces/adf/component/ main/java/org/apache/myfaces/adf/change/ main/java/org/apache/myfaces/adf/component... Date: Tue, 25 Jul 2006 03:54:52 -0000 To: adffaces-commits@incubator.apache.org From: matzew@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060725035505.664F91A9829@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/model/RowKeySetTreeImplTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/model/SortableModelTest.java URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/model/SortableModelTest.java?rev=425268&r1=425267&r2=425268&view=diff ============================================================================== --- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/model/SortableModelTest.java (original) +++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/model/SortableModelTest.java Mon Jul 24 20:54:50 2006 @@ -13,212 +13,212 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.myfaces.adf.model; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.faces.model.DataModel; -import javax.faces.model.ListDataModel; +package org.apache.myfaces.adf.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import javax.faces.model.DataModel; +import javax.faces.model.ListDataModel; import junit.framework.Test; import junit.framework.TestSuite; -import org.apache.myfaces.adf.model.SortCriterion; +import org.apache.myfaces.adf.model.SortCriterion; import org.apache.shale.test.base.AbstractJsfTestCase; - -/** - * @author Arjuna Wijeyekoon - */ -public class SortableModelTest extends AbstractJsfTestCase -{ - public SortableModelTest(String name) - { - super(name); - } - - public void setUp() - { - super.setUp(); - } - - public void tearDown() - { - super.tearDown(); + +/** + * @author Arjuna Wijeyekoon + */ +public class SortableModelTest extends AbstractJsfTestCase +{ + public SortableModelTest(String name) + { + super(name); + } + + public void setUp() + { + super.setUp(); + } + + public void tearDown() + { + super.tearDown(); } public static Test suite() { return new TestSuite(SortableModelTest.class); - } - - public void testInitialSort() - { - DataModel dModel = _createTestDataModel(); - SortableModel sModel = new SortableModel(dModel); - _testInitialSort(sModel); - } - - private void _testInitialSort(SortableModel sModel) - { - sModel.setRowIndex(0); - assertTrue(sModel.getRowData() == _bean1); - sModel.setRowIndex(1); - assertTrue(sModel.getRowData() == _bean2); - sModel.setRowIndex(2); - assertTrue(sModel.getRowData() == _bean3); - } - - public void testRowCount() - { - DataModel dModel = _createTestDataModel(); - SortableModel sModel = new SortableModel(dModel); - assertTrue(sModel.getRowCount() == dModel.getRowCount()); - _sort(sModel, "name", true); - assertTrue(sModel.getRowCount() == dModel.getRowCount()); - } - - public void testSortableProperties() - { - DataModel dModel = _createTestDataModel(); - SortableModel sModel = new SortableModel(dModel); - assertTrue(sModel.isSortable("age")); - assertTrue(sModel.isSortable("name")); - assertFalse(sModel.isSortable("object")); - } - - public void testSortAscending() - { - DataModel dModel = _createTestDataModel(); - SortableModel sModel = new SortableModel(dModel); - _sort(sModel, "name", true); - - -// for (int i=0; i= 0) - { - actualContentLength += length; - } - - assertEquals("Inaccurate explicit content length", - expectedContentLength, actualContentLength); - } - finally - { - in.close(); - } - } - } - - public class LocalResourceLoader extends ResourceLoader - { - protected URL findResource( - String name - ) throws IOException - { - return getClass().getResource(name); - } - } -} +package org.apache.myfaces.adf.resource; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import junit.framework.TestCase; + +abstract public class ResourceLoaderTestCase extends TestCase +{ + public ResourceLoaderTestCase( + String testName) + { + super(testName); + } + + protected void doTestUnknownContentLength( + URL url) throws IOException + { + URLConnection conn = url.openConnection(); + long actualContentLength = conn.getContentLength(); + + assertEquals("Invalid explicit content length", + -1L, actualContentLength); + } + + protected void doTestContentLength( + URL url) throws IOException + { + URLConnection conn = url.openConnection(); + long expectedContentLength = conn.getContentLength(); + + if (expectedContentLength != -1) + { + byte[] buffer = new byte[2048]; + InputStream in = conn.getInputStream(); + + try + { + long actualContentLength = 0; + + int length; + while ((length = (in.read(buffer))) >= 0) + { + actualContentLength += length; + } + + assertEquals("Inaccurate explicit content length", + expectedContentLength, actualContentLength); + } + finally + { + in.close(); + } + } + } + + public class LocalResourceLoader extends ResourceLoader + { + protected URL findResource( + String name + ) throws IOException + { + return getClass().getResource(name); + } + } +} Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/resource/ResourceLoaderTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/util/Base64InputStreamTest.java URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/util/Base64InputStreamTest.java?rev=425268&r1=425267&r2=425268&view=diff ============================================================================== --- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/util/Base64InputStreamTest.java (original) +++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/util/Base64InputStreamTest.java Mon Jul 24 20:54:50 2006 @@ -13,35 +13,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package org.apache.myfaces.adf.util; - -import java.io.IOException; -import java.io.StringReader; -import java.io.BufferedReader; + +package org.apache.myfaces.adf.util; + +import java.io.IOException; +import java.io.StringReader; +import java.io.BufferedReader; import junit.framework.Test; import junit.framework.TestSuite; - -import org.apache.myfaces.adfbuild.test.FacesTestCase; - -/** - * Unit tests for Base64InputStream. - * - * @author Matthew Lee - */ - -public class Base64InputStreamTest extends FacesTestCase -{ - - /** - * Creates a new Base64InputStreamTest. - * - * @param testName the unit test name - */ - public Base64InputStreamTest(String testName) - { - super(testName); + +import org.apache.myfaces.adfbuild.test.FacesTestCase; + +/** + * Unit tests for Base64InputStream. + * + * @author Matthew Lee + */ + +public class Base64InputStreamTest extends FacesTestCase +{ + + /** + * Creates a new Base64InputStreamTest. + * + * @param testName the unit test name + */ + public Base64InputStreamTest(String testName) + { + super(testName); } public void setUp() @@ -57,75 +57,75 @@ public static Test suite() { return new TestSuite(Base64InputStreamTest.class); - } - - /** - * Tests decoding of stream that contains no trailing padding characters. - */ - public void testNoPaddingChar() throws IOException - { - 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"; - String str_encoded = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5LiAx"; - - _testRead(str, str_encoded); - - } - - /** - * Tests decoding of stream that contains exactly one trailing padding character. - */ - public void testOnePaddingChar() throws IOException - { - 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"; - String str_encoded = "QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5Ljk="; - - _testRead(str, str_encoded); - - } - - /** - * Tests decoding of stream that contains exactly two trailing padding characters. - */ - public void testTwoPaddingChars() throws IOException - { - 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."; - String str_encoded = "QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5Lg=="; - - _testRead(str, str_encoded); - - } - - - /** - * - * Uses Base64InputStream to reads from the encoded string and - * compares output with the expected decoded string. - * - * @param str the decoded string - * @param str_encoded the base64 encoded string - * - **/ - - private void _testRead(String str, String str_encoded) throws IOException - { - - // construct the Base64InputStream from the encoded string - StringReader strreader = new StringReader(str_encoded); - BufferedReader buffreader = new BufferedReader(strreader); - Base64InputStream b64_in = new Base64InputStream(buffreader); - - // read decoded chars from the Base64InputStream and form decoded string - String result = ""; - int c; - while ( (c = b64_in.read()) != -1 ) - { - result = result + (char)c; - } - - // compare resulting decoded string with the expected decoded string - assertEquals(result, str); - } - - - -} // end Base64InputStreamTest class + } + + /** + * Tests decoding of stream that contains no trailing padding characters. + */ + public void testNoPaddingChar() throws IOException + { + 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"; + String str_encoded = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5LiAx"; + + _testRead(str, str_encoded); + + } + + /** + * Tests decoding of stream that contains exactly one trailing padding character. + */ + public void testOnePaddingChar() throws IOException + { + 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"; + String str_encoded = "QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5Ljk="; + + _testRead(str, str_encoded); + + } + + /** + * Tests decoding of stream that contains exactly two trailing padding characters. + */ + public void testTwoPaddingChars() throws IOException + { + 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."; + String str_encoded = "QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5Lg=="; + + _testRead(str, str_encoded); + + } + + + /** + * + * Uses Base64InputStream to reads from the encoded string and + * compares output with the expected decoded string. + * + * @param str the decoded string + * @param str_encoded the base64 encoded string + * + **/ + + private void _testRead(String str, String str_encoded) throws IOException + { + + // construct the Base64InputStream from the encoded string + StringReader strreader = new StringReader(str_encoded); + BufferedReader buffreader = new BufferedReader(strreader); + Base64InputStream b64_in = new Base64InputStream(buffreader); + + // read decoded chars from the Base64InputStream and form decoded string + String result = ""; + int c; + while ( (c = b64_in.read()) != -1 ) + { + result = result + (char)c; + } + + // compare resulting decoded string with the expected decoded string + assertEquals(result, str); + } + + + +} // end Base64InputStreamTest class Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/util/Base64InputStreamTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/util/Base64OutputStreamTest.java URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/util/Base64OutputStreamTest.java?rev=425268&r1=425267&r2=425268&view=diff ============================================================================== --- incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/util/Base64OutputStreamTest.java (original) +++ incubator/adffaces/branches/matzew-repackaging-trinidad/trinidad/trinidad-api/src/test/java/org/apache/myfaces/adf/util/Base64OutputStreamTest.java Mon Jul 24 20:54:50 2006 @@ -13,36 +13,36 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package org.apache.myfaces.adf.util; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.BufferedWriter; -import java.util.zip.GZIPOutputStream; + +package org.apache.myfaces.adf.util; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.BufferedWriter; +import java.util.zip.GZIPOutputStream; import junit.framework.Test; import junit.framework.TestSuite; - -import org.apache.myfaces.adfbuild.test.FacesTestCase; - -/** - * Unit tests for Base64OutputStream. - * - * @author Matthew Lee - */ -public class Base64OutputStreamTest extends FacesTestCase -{ - /** - * Creates a new Base64OutputStreamTest. - * - * @param testName the unit test name - */ - public Base64OutputStreamTest(String testName) - { - super(testName); + +import org.apache.myfaces.adfbuild.test.FacesTestCase; + +/** + * Unit tests for Base64OutputStream. + * + * @author Matthew Lee + */ +public class Base64OutputStreamTest extends FacesTestCase +{ + /** + * Creates a new Base64OutputStreamTest. + * + * @param testName the unit test name + */ + public Base64OutputStreamTest(String testName) + { + super(testName); } - + public void setUp() { super.setUp(); @@ -57,193 +57,193 @@ { return new TestSuite(Base64OutputStreamTest.class); } - - /** - * Tests decoding of stream that contains no trailing padding characters. - */ - public void testNoPaddingChar() throws IOException - { - - 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"; - String str_encoded = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5LiAx"; - - _testWriteChar(str, str_encoded); - - _testWriteArray(str, str_encoded); - - } - - /** - * Tests decoding of stream that contains exactly one trailing padding character. - */ - public void testOnePaddingChar() throws IOException - { - 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"; - String str_encoded = "QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5Ljk="; - - _testWriteChar(str, str_encoded); - - _testWriteArray(str, str_encoded); - - } - - /** - * Tests decoding of stream that contains exactly two trailing padding characters. - */ - public void testTwoPaddingChars() throws IOException - { - 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."; - String str_encoded = "QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5Lg=="; - - _testWriteChar(str, str_encoded); - - _testWriteArray(str, str_encoded); - - } - - /** - * Tests decoding of stream by writing out to stream in different intervals to test whether - * whehther leftover data is persisted across calls to write - */ - public void testMultipleWrites() throws IOException - { - 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."; - String str_encoded = "QmFzZTY0IEVuY29kaW5nIGlzIGEgcG9wdWxhciB3YXkgdG8gY29udmVydCB0aGUgOGJpdCBhbmQgdGhlIGJpbmFyeSB0byB0aGUgN2JpdCBmb3IgbmV0d29yayB0cmFucyB1c2luZyBTb2NrZXQsIGFuZCBhIHNlY3VyaXR5IG1ldGhvZCB0byBoYW5kbGUgdGV4dCBvciBmaWxlLCBvZnRlbiB1c2VkIGluIEF1dGhlbnRpY2FsIExvZ2luIGFuZCBNYWlsIEF0dGFjaG1lbnQsIGFsc28gc3RvcmVkIGluIHRleHQgZmlsZSBvciBkYXRhYmFzZS4gTW9zdCBTTVRQIHNlcnZlciB3aWxsIGhhbmRsZSB0aGUgbG9naW4gVXNlck5hbWUgYW5kIFBhc3N3b3JkIGluIHRoaXMgd2F5Lg=="; - - // create a Base64OutputStream - StringWriter strwriter = new StringWriter(); - BufferedWriter buffwriter = new BufferedWriter(strwriter); - Base64OutputStream b64_out = new Base64OutputStream(buffwriter); - - byte[] b = str.getBytes(); - - // write the bytes in different lengths to test whether leftover - // data is persisted across calls to write - b64_out.write(b, 0, 33); - b64_out.write(b, 33, 1); - b64_out.write(b, 34, 1); - b64_out.write(b, 35, 2); - b64_out.write(b, 37, 3); - b64_out.write(b, 40, 3); - b64_out.write(b, 43, 3); - b64_out.write(b, 46, 5); - b64_out.write(b, 51, 4); - b64_out.write(b, 55, 5); - b64_out.write(b, 60, 6); - b64_out.write(b, 66, 10); - b64_out.write(b, 76, 51); - b64_out.write(b, 127, 150); - b64_out.write(b, 277, 22); - b64_out.write(b, 299, 21); - b64_out.write(b, 320, 2); - - // remember to add padding characters (if necessary) - b64_out.finish(); - - buffwriter.flush(); - - // compare the contents of the outputstream with the expected encoded string - assertEquals(strwriter.toString(), str_encoded); - } - - - /** - * Testing writing binary data whose byte values range from -128 to 128. - * We create such data by GZIP-ing the string before writing out to the Base64OutputStream. - * - */ - public void testWriteBinaryData() throws IOException - { - 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."; - String str_encoded = "H4sIAAAAAAAAAD2QQW7DMAwEv7IPCHIK2l4ToLe6CJD2AbREx0JkMpDouvl9KQXokVxylssTVX454F2CxiRXpArCXe9rpoKNHjBFUPnhYrCZ8TYmA0nsxZiESh9p1WuTJi0Qtk3LDVZIKtbauBcNN7ZdXyVUDmtJ9sDCNmtshNmVzDD+NThjSpl30MlYnMARSXBc3UYsBcr40Kt3Gm2glHE0ozAvrrpFropqWp5bndhwDRvJaPTIewxaDZfh6+zHFI+HLeX8f4XHyd3h29VPWrhbnalWT/bEzv4qf9D+DzA2UNlCAQAA"; - - byte[] bytes = str.getBytes(); - - StringWriter strwriter = new StringWriter(); - BufferedWriter buffwriter = new BufferedWriter(strwriter); - Base64OutputStream b64_out = new Base64OutputStream(buffwriter); - - GZIPOutputStream zip = new GZIPOutputStream(b64_out); - - zip.write(bytes, 0, bytes.length); - zip.finish(); - buffwriter.flush(); - b64_out.finish(); - - assertEquals(str_encoded, strwriter.toString()); - - } - - - ////////// private methods //////////// - - /** - * - * Writes each individual char from str to a Base64OutputStream and compares - * the resulting output stream contents with the expected encoded string. - * - * @param str the decoded string - * @param str_encoded the encoded string - * - **/ - - private void _testWriteChar(String str, String str_encoded) throws IOException - { - // create a Base64OutputStream - StringWriter strwriter = new StringWriter(); - BufferedWriter buffwriter = new BufferedWriter(strwriter); - Base64OutputStream b64_out = new Base64OutputStream(buffwriter); - - // write out each char in str to the stream - for (int i = 0; i