Author: nicolas Date: Tue May 24 13:57:35 2011 New Revision: 1127056 URL: http://svn.apache.org/viewvc?rev=1127056&view=rev Log: TCK for Base64
Added: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Base64.java maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/Base64Test.java Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/pom.xml maven/sandbox/trunk/plexus-utils-commons-bridge/pom.xml Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/pom.xml URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/pom.xml?rev=1127056&r1=1127055&r2=1127056&view=diff ============================================================================== --- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/pom.xml (original) +++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/pom.xml Tue May 24 13:57:35 2011 @@ -21,6 +21,10 @@ <artifactId>commons-io</artifactId> </dependency> <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> Added: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Base64.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Base64.java?rev=1127056&view=auto ============================================================================== --- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Base64.java (added) +++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-commons-bridge/src/main/java/org/codehaus/plexus/util/Base64.java Tue May 24 13:57:35 2011 @@ -0,0 +1,64 @@ +package org.codehaus.plexus.util; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +@Deprecated +public class Base64 +{ + public Base64() + { + super(); + } + + public static boolean isArrayByteBase64(byte[] arrayOctect) + { + throw new UnsupportedOperationException( "Not implemented yet" ); + } + + public static byte[] encodeBase64(byte[] binaryData) + { + throw new UnsupportedOperationException( "Not implemented yet" ); + } + + public static byte[] encodeBase64Chunked(byte[] binaryData) + { + throw new UnsupportedOperationException( "Not implemented yet" ); + } + + public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) + { + throw new UnsupportedOperationException( "Not implemented yet" ); + } + + public static byte[] decodeBase64(byte[] base64Data) + { + throw new UnsupportedOperationException( "Not implemented yet" ); + } + + public byte[] encode(byte[] pArray) + { + throw new UnsupportedOperationException( "Not implemented yet" ); + } + + public byte[] decode(byte[] pArray) + { + throw new UnsupportedOperationException( "Not implemented yet" ); + } +} Added: maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/Base64Test.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/Base64Test.java?rev=1127056&view=auto ============================================================================== --- maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/Base64Test.java (added) +++ maven/sandbox/trunk/plexus-utils-commons-bridge/plexus-utils-tck/src/test/java/org/codehaus/plexus/util/Base64Test.java Tue May 24 13:57:35 2011 @@ -0,0 +1,94 @@ +package org.codehaus.plexus.util; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import static org.apache.maven.tck.TckMatchers.hasDefaultConstructor; +import static org.apache.maven.tck.TckMatchers.isFinalClass; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.*; + +import org.junit.Assert; +import org.junit.Test; + +public class Base64Test { + + + @Test + public void isNotUtilityClass() + throws Exception + { + assertThat( PropertyUtils.class, allOf( hasDefaultConstructor(), not( isFinalClass() ) ) ); + } + + @Test + public void encode() + throws Exception + { + assertEquals("dGVzdA==", new Base64().encode("test".getBytes())); + } + + @Test + public void decode() + throws Exception + { + assertEquals( "test", new Base64().decode("dGVzdA==".getBytes()) ); + } + + @Test + public void encodeBase64() + throws Exception + { + assertEquals( "dGVzdA==", Base64.encodeBase64( "test".getBytes() ) ); + assertEquals( "dGVzdA==", Base64.encodeBase64( "test".getBytes(), false ) ); + } + + @Test + public void encodeBase64Chunked() + throws Exception + { + assertEquals( + "c29tZSBsb25nIGxvbmcgbG9uZyBsb25nIGxvbmcgbG9uZyBsb25nIGxvbmcgbG9uZyBsb25nIGxv\r\n" + + "bmcgbG9uZyBsb25nIGxvbmcgdGV4dA==\r\n", + Base64.encodeBase64( + "some long long long long long long long long long long long long long long text" + .getBytes(), true ) ); + } + + @Test + public void decodeBase64() + throws Exception + { + assertEquals( "test", Base64.decodeBase64( "dGVzdA==".getBytes() ) ); + } + + @Test + public void isArrayByteBase64() + throws Exception + { + String valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + assertTrue( Base64.isArrayByteBase64( valid.getBytes() ) ); + } + + private static void assertEquals( String expected , byte[] actual ) + { + Assert.assertEquals(expected, new String(actual)); + } +} Modified: maven/sandbox/trunk/plexus-utils-commons-bridge/pom.xml URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plexus-utils-commons-bridge/pom.xml?rev=1127056&r1=1127055&r2=1127056&view=diff ============================================================================== --- maven/sandbox/trunk/plexus-utils-commons-bridge/pom.xml (original) +++ maven/sandbox/trunk/plexus-utils-commons-bridge/pom.xml Tue May 24 13:57:35 2011 @@ -51,6 +51,11 @@ under the License. <version>1.3.2</version> </dependency> <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>1.4</version> + </dependency> + <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> <version>2.0.7</version>