harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r410243 [5/7] - in /incubator/harmony/enhanced/classlib/trunk/modules/crypto: make/common/ src/main/java/javax/crypto/ src/main/java/javax/crypto/spec/ src/main/java/org/apache/harmony/crypto/internal/ src/test/api/java.injected/javax/crypt...
Date Tue, 30 May 2006 11:35:46 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java Tue May 30 04:35:44 2006
@@ -21,27 +21,16 @@
 
 package org.apache.harmony.crypto.tests.javax.crypto;
 
-import java.security.AlgorithmParameters;
-import java.security.InvalidAlgorithmParameterException;
 import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
 import java.security.Provider;
-import java.security.Security;
-import java.security.spec.AlgorithmParameterSpec;
 
 import javax.crypto.ExemptionMechanism;
-import javax.crypto.ExemptionMechanismException;
 import javax.crypto.ExemptionMechanismSpi;
-import javax.crypto.ShortBufferException;
-import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi;
 import org.apache.harmony.security.SpiEngUtils;
+import org.apache.harmony.security.SpiEngUtils.MyProvider;
 import junit.framework.TestCase;
-
-
 /**
  * Tests for <code>ExemptionMechanism</code> class constructors and methods
  * 
@@ -55,36 +44,6 @@
     
     private static final String ExemptionMechanismProviderClass = "org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi";
 
-    private static final String[] invalidValues = SpiEngUtils.invalidValues;
-
-    private static final String[] validValues;
-
-    static {
-        validValues = new String[4];
-        validValues[0] = defaultAlg;
-        validValues[1] = defaultAlg.toLowerCase();
-        validValues[2] = "eMEch";
-        validValues[3] = "emecH";
-    }
-
-    Provider mProv;
-
-    protected void setUp() throws Exception {
-        super.setUp();
-        mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", 
-                srvExemptionMechanism.concat(".").concat(defaultAlg), 
-                ExemptionMechanismProviderClass);
-        Security.insertProviderAt(mProv, 1);
-    }
-    
-    /*
-     * @see TestCase#tearDown()
-     */
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        Security.removeProvider(mProv.getName());
-    }
-
     /**
      * Constructor for SecurityManagerFactoryTest2.
      * 
@@ -93,229 +52,16 @@
     public ExemptionMechanismTest(String arg0) {
         super(arg0);
     }
-
-    private void checkResult(ExemptionMechanism exMech) 
-            throws ExemptionMechanismException, ShortBufferException,
-            InvalidKeyException, InvalidAlgorithmParameterException  {
-        Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
-        byte [] emptyA = new byte[0];
-        int len = MyExemptionMechanismSpi.getLength();
-        byte [] byteA = new byte[len];
-        try {
-            exMech.genExemptionBlob();
-            fail("IllegalStateException must be thrown");
-        } catch (IllegalStateException e) {            
-        }
-        try {
-            exMech.genExemptionBlob(byteA);
-            fail("IllegalStateException must be thrown");
-        } catch (IllegalStateException e) {            
-        }
-        try {
-            exMech.genExemptionBlob(byteA, 1);
-            fail("IllegalStateException must be thrown");
-        } catch (IllegalStateException e) {            
-        }        
-        try {
-            exMech.getOutputSize(0);
-            fail("IllegalStateException must be thrown");
-        } catch (IllegalStateException e) {            
-        }        
-        
-        exMech.init(key);
-        byte [] bbRes = exMech.genExemptionBlob();
-        assertEquals("Incorrect length", bbRes.length, len);
-        assertEquals("Incorrect result", exMech.genExemptionBlob(new byte[5]), 5);
-        assertEquals("Incorrect result", exMech.genExemptionBlob(bbRes), len);
-        try {
-            exMech.genExemptionBlob(new byte[1], len);
-            fail("ShortBufferException must be thrown");
-        } catch (ShortBufferException e) {            
-        }        
-        try {
-            exMech.genExemptionBlob(emptyA);
-            fail("ShortBufferException must be thrown");
-        } catch (ShortBufferException e) {            
-        }
-        
-        assertEquals("Incorrect result", exMech.genExemptionBlob(byteA, 1), 9);
-        assertEquals("Incorrect result", exMech.genExemptionBlob(new byte[20], (len - 2)), len);
-                
-        assertEquals("Incorrect output size", exMech.getOutputSize(100), 5);
-        
-        AlgorithmParameters params = null;
-        exMech.init(key, params);
-        AlgorithmParameterSpec parSpec = null;
-        exMech.init(key, parSpec);
-        key = new SecretKeySpec(new byte[10], "DSA");
-        try {
-            exMech.init(key);
-            fail("ExemptionMechanismException must be throwm");
-        } catch (ExemptionMechanismException e) {
-            assertTrue("Empty message", (e.getMessage().length() > 0));
-        }
-        try {
-            exMech.init(key, params);
-            fail("ExemptionMechanismException must be throwm");
-        } catch (ExemptionMechanismException e) {
-            assertTrue("Empty message", (e.getMessage().length() > 0));
-        }
-        try {
-            exMech.init(key, parSpec);
-            fail("ExemptionMechanismException must be throwm");
-        } catch (ExemptionMechanismException e) {
-            assertTrue("Empty message", (e.getMessage().length() > 0));
-        }
-    }
-    
-    /**
-     * Test for <code>getInstance(String algorithm)</code> method
-     * Assertions:
-     * throws NullPointerException when algorithm is null;
-     * throws NoSuchAlgorithmException when algorithm is incorrect;
-     * returns ExemptionMechanism object
-     */
-    public void testGetInstance01() throws NoSuchAlgorithmException,
-            ExemptionMechanismException, InvalidAlgorithmParameterException,
-            ShortBufferException, InvalidKeyException {
-        try {
-            ExemptionMechanism.getInstance(null);
-            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
-        } catch (NullPointerException e) {
-        } catch (NoSuchAlgorithmException e) {
-        }
-        for (int i = 0; i < invalidValues.length; i++) {
-            try {
-                ExemptionMechanism.getInstance(invalidValues[i]);
-                fail("NoSuchAlgorithmException must be thrown (algorithm: "
-                        .concat(invalidValues[i]).concat(")"));
-            } catch (NoSuchAlgorithmException e) {
-            }
-        }
-        ExemptionMechanism exMech;
-        for (int i = 0; i < validValues.length; i++) {
-            exMech = ExemptionMechanism.getInstance(validValues[i]);
-            assertEquals("Incorrect algorithm", exMech.getName(),
-                    validValues[i]);
-            assertEquals("Incorrect provider", exMech.getProvider(), mProv);
-            checkResult(exMech);
-        }
-    }
-
-    /**
-     * Test for <code>getInstance(String algorithm, String provider)</code>
-     * method
-     * Assertions: 
-     * throws NullPointerException when algorithm is null;
-     * throws NoSuchAlgorithmException when algorithm is null or incorrect;
-     * throws IllegalArgumentException when provider is null;
-     * throws NoSuchProviderException when provider is available;
-     * returns ExemptionMechanism object
-     */
-    public void testGetInstance02() throws NoSuchAlgorithmException,
-            NoSuchProviderException, IllegalArgumentException,
-            ExemptionMechanismException, InvalidAlgorithmParameterException,
-            ShortBufferException, InvalidKeyException {        
-        try {
-            ExemptionMechanism.getInstance(null, mProv.getName());
-            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
-        } catch (NullPointerException e) {
-        } catch (NoSuchAlgorithmException e) {
-        }
-        for (int i = 0; i < invalidValues.length; i++) {
-            try {
-                ExemptionMechanism.getInstance(invalidValues[i], mProv
-                        .getName());
-                fail("NoSuchAlgorithmException must be thrown (algorithm: "
-                        .concat(invalidValues[i]).concat(")"));
-            } catch (NoSuchAlgorithmException e) {
-            }
-        }
-        String prov = null;
-        for (int i = 0; i < validValues.length; i++) {
-            try {
-                ExemptionMechanism.getInstance(validValues[i], prov);
-                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
-                        .concat(invalidValues[i]).concat(")"));
-            } catch (IllegalArgumentException e) {
-            }
-        }
-        for (int i = 0; i < validValues.length; i++) {
-            for (int j = 1; j < invalidValues.length; j++) {
-                try {
-                    ExemptionMechanism.getInstance(validValues[i],
-                            invalidValues[j]);
-                    fail("NoSuchProviderException must be thrown (algorithm: "
-                            .concat(invalidValues[i]).concat(" provider: ")
-                            .concat(invalidValues[j]).concat(")"));
-                } catch (NoSuchProviderException e) {
-                }
-            }
-        }
-        ExemptionMechanism exMech;
-        for (int i = 0; i < validValues.length; i++) {
-            exMech = ExemptionMechanism.getInstance(validValues[i], mProv
-                    .getName());
-            assertEquals("Incorrect algorithm", exMech.getName(),
-                    validValues[i]);
-            assertEquals("Incorrect provider", exMech.getProvider().getName(),
-                    mProv.getName());
-            checkResult(exMech);
-        }
-    }
-
-    /**
-     * Test for <code>getInstance(String algorithm, Provider provider)</code>
-     * method
-     * Assertions:
-     * throws NullPointerException when algorithm is null;
-     * throws NoSuchAlgorithmException when algorithm is null or incorrect;
-     * throws IllegalArgumentException when provider is null;
-     * returns ExemptionMechanism object
-     */
-    public void testGetInstance03() throws NoSuchAlgorithmException,
-            IllegalArgumentException,
-            ExemptionMechanismException, InvalidAlgorithmParameterException,
-            ShortBufferException, InvalidKeyException {
-        try {
-            ExemptionMechanism.getInstance(null, mProv);
-            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
-        } catch (NullPointerException e) {
-        } catch (NoSuchAlgorithmException e) {
-        }
-        for (int i = 0; i < invalidValues.length; i++) {
-            try {
-                ExemptionMechanism.getInstance(invalidValues[i], mProv);
-                fail("NoSuchAlgorithmException must be thrown (algorithm: "
-                        .concat(invalidValues[i]).concat(")"));
-            } catch (NoSuchAlgorithmException e) {
-            }
-        }
-        Provider prov = null;
-        for (int i = 0; i < validValues.length; i++) {
-            try {
-                ExemptionMechanism.getInstance(validValues[i], prov);
-                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
-                        .concat(invalidValues[i]).concat(")"));
-            } catch (IllegalArgumentException e) {
-            }
-        }
-        ExemptionMechanism exMech;
-        for (int i = 0; i < validValues.length; i++) {
-            exMech = ExemptionMechanism.getInstance(validValues[i], mProv);
-            assertEquals("Incorrect algorithm", exMech.getName(),
-                    validValues[i]);
-            assertEquals("Incorrect provider", exMech.getProvider(), mProv);
-            checkResult(exMech);
-        }
-    }
-    
+   
     /**
      * Test for <code>ExemptionMechanism</code> constructor 
      * Assertion: cretes new object using provider and mechanism name
      */
-    public void testExemptionMechanism() throws NoSuchAlgorithmException,
-            ExemptionMechanismException, ShortBufferException, InvalidKeyException {
+    public void testExemptionMechanism() throws Exception {
+        Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", 
+                srvExemptionMechanism.concat(".").concat(defaultAlg), 
+                ExemptionMechanismProviderClass);
+        
         ExemptionMechanismSpi spi = new MyExemptionMechanismSpi();
         ExemptionMechanism em = new myEM(spi, mProv, defaultAlg);
         

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java (from r410238, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement1Test.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement1Test.java&r1=410238&r2=410243&rev=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement1Test.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreementTest.java Tue May 30 04:35:44 2006
@@ -50,16 +50,7 @@
  * 
  */
 
-public class KeyAgreement1Test extends TestCase {
-
-    /**
-     * Constructor for KeyAgreement1Test.
-     * 
-     * @param arg0
-     */
-    public KeyAgreement1Test(String arg0) {
-        super(arg0);
-    }
+public class KeyAgreementTest extends TestCase {
 
     public static final String srvKeyAgreement = "KeyAgreement";
 
@@ -119,35 +110,6 @@
     }
 
     /**
-     * Test for <code>KeyAgreement</code> constructor Assertion: returns
-     * KeyAgreement object
-     */
-    public void testKeyAgreement() throws NoSuchAlgorithmException,
-            InvalidKeyException, IllegalStateException {
-        if (!DEFSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
-        KeyAgreementSpi spi = new MyKeyAgreementSpi();
-        KeyAgreement keyA = new myKeyAgreement(spi, defaultProvider,
-                defaultAlgorithm);
-        assertEquals("Incorrect algorithm", keyA.getAlgorithm(),
-                defaultAlgorithm);
-        assertEquals("Incorrect provider", keyA.getProvider(), defaultProvider);
-        assertNull("Incorrect result", keyA.doPhase(null, true));
-        assertEquals("Incorrect result", keyA.generateSecret().length, 0);
-
-        keyA = new myKeyAgreement(null, null, null);
-        assertNull("Algorithm must be null", keyA.getAlgorithm());
-        assertNull("Provider must be null", keyA.getProvider());
-        try {
-            keyA.doPhase(null, true);
-            fail("NullPointerEXception must be thrown");
-        } catch (NullPointerException e) {
-        }
-    }
-
-    /**
      * Test for <code> getInstance(String algorithm) </code> method Assertions:
      * throws NullPointerException when algorithm is null throws
      * NoSuchAlgorithmException when algorithm isnot available
@@ -484,7 +446,6 @@
             }
             try {
                 kAgs[i].init(privKey, dsa, random);
-                fail("InvalidAlgorithmParameterException must be throw");
                 fail("InvalidAlgorithmParameterException or InvalidKeyException must be throw");
             } catch (InvalidAlgorithmParameterException e) {
             } catch (InvalidKeyException e) {
@@ -584,19 +545,4 @@
         }
     }
 
-    public static void main(String args[]) {
-        junit.textui.TestRunner.run(KeyAgreement1Test.class);
-    }
-}
-
-/**
- * Additional class for KeyAgreement constructor verification
- */
-
-class myKeyAgreement extends KeyAgreement {
-
-    public myKeyAgreement(KeyAgreementSpi keyAgreeSpi, Provider provider,
-            String algorithm) {
-        super(keyAgreeSpi, provider, algorithm);
-    }
 }

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java (from r410238, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGenerator1Test.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGenerator1Test.java&r1=410238&r2=410243&rev=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGenerator1Test.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGeneratorTest.java Tue May 30 04:35:44 2006
@@ -43,16 +43,7 @@
  * 
  */
 
-public class KeyGenerator1Test extends TestCase {
-
-    /**
-     * Constructor for KeyGenerator1Test.
-     * 
-     * @param arg0
-     */
-    public KeyGenerator1Test(String arg0) {
-        super(arg0);
-    }
+public class KeyGeneratorTest extends TestCase {
     
     public static final String srvKeyGenerator = "KeyGenerator";
     
@@ -438,9 +429,6 @@
         }
     }
     
-    public static void main(String args[]) {
-        junit.textui.TestRunner.run(KeyGenerator1Test.class);
-    }     
 }
 
 /**

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java (from r410238, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/Mac1Test.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/Mac1Test.java&r1=410238&r2=410243&rev=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/Mac1Test.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/MacTest.java Tue May 30 04:35:44 2006
@@ -47,7 +47,7 @@
  * 
  */
 
-public class Mac1Test extends TestCase {
+public class MacTest extends TestCase {
 
     public static final String srvMac = "Mac";
 
@@ -100,16 +100,8 @@
             return null;
         }
     }
-    
 
     /**
-     * Constructor for MacTest.
-     * @param arg0
-     */
-    public Mac1Test(String arg0) {
-        super(arg0);
-    }
-    /**
      * Test for <code>getInstance(String algorithm)</code> method
      * Assertion: 
      * throws NullPointerException when algorithm is null
@@ -791,7 +783,7 @@
     }
     
     public static Test suite() {
-        return new TestSuite(Mac1Test.class);
+        return new TestSuite(MacTest.class);
     }
 
     public static void main(String args[]) {        

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java Tue May 30 04:35:44 2006
@@ -21,17 +21,15 @@
 
 package org.apache.harmony.crypto.tests.javax.crypto;
 
-import javax.crypto.BadPaddingException;
+import java.security.SecureRandom;
+import java.util.Arrays;
+
 import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
 import javax.crypto.NullCipher;
-import javax.crypto.ShortBufferException;
 import javax.crypto.spec.SecretKeySpec;
 
 import junit.framework.TestCase;
 
-import java.security.*;
-
 /**
  *
  * Tests for NullCipher
@@ -50,339 +48,156 @@
 	}
 
 	public void testGetBlockSize() {
-		if (c.getBlockSize() != 1) {
-			fail("getBlockSize() failed");
-		}
+        assertEquals("Incorrect BlockSize", 1, c.getBlockSize());
 	}
 
 	public void testGetOutputSize() {
-		if (c.getOutputSize(111) != 111) {
-			fail("getOutputSize() failed");
-		}
+        assertEquals("Incorrect OutputSize", 111, c.getOutputSize(111));
 	}
 
 	public void testGetIV() {
-		if (c.getIV() != null) {
-			fail("getIV() failed");
-		}
+        assertTrue("Incorrect IV", Arrays.equals(c.getIV(), new byte[8]));
 	}
 
 	public void testGetParameters() {
-		if (c.getParameters() != null) {
-			fail("getParameters() failed");	
-		}
+        assertNull("Incorrect Parameters", c.getParameters());
 	}
 
 	public void testGetExemptionMechanism() {
-		if (c.getExemptionMechanism() != null) {
-			fail("getExemptionMechanism() failed");	
-		}	
+        assertNull("Incorrect ExemptionMechanism", c.getExemptionMechanism());
 	}
 
 	/*
 	 * Class under test for void init(int, Key)
 	 */
-	public void testInitintKey() {
-		try {
-			c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1], "algorithm"));		
-		} catch (InvalidKeyException e) {
-			fail(e.toString());
-		}	
+	public void testInitintKey() throws Exception {
+		c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1], "algorithm"));
+	
 	}
 
 	/*
 	 * Class under test for void init(int, Key, SecureRandom)
 	 */
-	public void testInitintKeySecureRandom() {
-		try {
-			c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1], "algorithm"), new SecureRandom());		
-		} catch (InvalidKeyException e) {
-			fail(e.toString());
-		}
+	public void testInitintKeySecureRandom() throws Exception {
+		c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1],
+                "algorithm"), new SecureRandom());
 	}
 
 	/*
 	 * Class under test for void init(int, Key, AlgorithmParameterSpec)
 	 */
-	public void testInitintKeyAlgorithmParameterSpec() {
+	public void testInitintKeyAlgorithmParameterSpec() throws Exception {
 		class myAlgorithmParameterSpec implements java.security.spec.AlgorithmParameterSpec {}
-		try {
-			c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1], "algorithm"), new myAlgorithmParameterSpec());
-		} catch (InvalidKeyException e) {
-			fail(e.toString());
-		} catch (InvalidAlgorithmParameterException  e) {
-			fail(e.toString());
-		}
-	}
-
-	/*
-	 * Class under test for void init(int, Key, AlgorithmParameterSpec, SecureRandom)
-	 */
-	public void testInitintKeyAlgorithmParameterSpecSecureRandom() {
-	}
-
-	/*
-	 * Class under test for void init(int, Key, AlgorithmParameters)
-	 */
-	public void testInitintKeyAlgorithmParameters() {
-	}
-
-	/*
-	 * Class under test for void init(int, Key, AlgorithmParameters, SecureRandom)
-	 */
-	public void testInitintKeyAlgorithmParametersSecureRandom() {
-	}
-
-	/*
-	 * Class under test for void init(int, Certificate)
-	 */
-	public void testInitintCertificate() {		
-	}
-
-	/*
-	 * Class under test for void init(int, Certificate, SecureRandom)
-	 */
-	public void testInitintCertificateSecureRandom() {
+		c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[1],
+                "algorithm"), new myAlgorithmParameterSpec());
 	}
 
 	/*
 	 * Class under test for byte[] update(byte[])
 	 */
-	public void testUpdatebyteArray() {
+	public void testUpdatebyteArray() throws Exception {
 		byte [] b = {1, 2, 3, 4, 5};
 		byte [] r = c.update(b);
-		if (b.length != r.length) {
-			fail("different length");
-		}
-		for (int i = 0; i < b.length; i++) {
-			if (b[i] != r[i]) {
-				fail("different content");
-			}
-		}		
+        assertEquals("different length", b.length, r.length);
+        assertTrue("different content", Arrays.equals(b, r));
 	}
 
 	/*
 	 * Class under test for byte[] update(byte[], int, int)
 	 */
-	public void testUpdatebyteArrayintint() {
+	public void testUpdatebyteArrayintint() throws Exception {
 		byte [] b = {1, 2, 3, 4, 5};
 		byte [] r = c.update(b, 0, 5);
-		if (b.length != r.length) {
-			fail("different length");
-		}
-		for (int i = 0; i < b.length; i++) {
-			if (b[i] != r[i]) {
-				fail("different content");
-			}
-		}
+        assertEquals("different length", b.length, r.length);
+        assertTrue("different content", Arrays.equals(b, r));
 		
 		r = c.update(b, 1, 3);
-		if (r.length != 3) {
-			fail("different length");
-		}
+		assertEquals("different length", 3, r.length);
 		for (int i = 0; i < 3; i++) {
-			if (b[i + 1] != r[i]) {
-				fail("different content");
-			}
+            assertEquals("different content", b[i + 1], r[i]);
 		}
 	}
 
 	/*
 	 * Class under test for int update(byte[], int, int, byte[])
 	 */
-	public void testUpdatebyteArrayintintbyteArray() {
+	public void testUpdatebyteArrayintintbyteArray() throws Exception {
 		byte [] b = {1, 2, 3, 4, 5};
 		byte [] r = new byte[5]; 
-		try {
-			c.update(b, 0, 5, r);			
-		} catch (ShortBufferException e) {
-			fail(e.toString());
-		}
-
-		for (int i = 0; i < b.length; i++) {
-			if (b[i] != r[i]) {
-				fail("different content");
-			}
-		}		
+		c.update(b, 0, 5, r);			
+        assertTrue("different content", Arrays.equals(b, r));		
 	}
 
 	/*
 	 * Class under test for int update(byte[], int, int, byte[], int)
 	 */
-	public void testUpdatebyteArrayintintbyteArrayint() {
+	public void testUpdatebyteArrayintintbyteArrayint() throws Exception {
 		byte [] b = {1, 2, 3, 4, 5};
 		byte [] r = new byte[5]; 
-		try {
-			c.update(b, 0, 5, r, 0);			
-		} catch (ShortBufferException e) {
-			fail(e.toString());
-		}
-
-		for (int i = 0; i < b.length; i++) {
-			if (b[i] != r[i]) {
-				fail("different content");
-			}
-		}	
-	}
-
-	/*
-	 * Class under test for int update(ByteBuffer, ByteBuffer)
-	 */
-	public void testUpdateByteBufferByteBuffer() {
+		c.update(b, 0, 5, r, 0);			
+        assertTrue("different content", Arrays.equals(b, r));
 	}
 
 	/*
 	 * Class under test for byte[] doFinal()
 	 */
-	public void testDoFinal() {
-		try {
-			if (c.doFinal() != null) {
-				fail("doFinal failed");
-			}			
-		} catch (BadPaddingException e) {
-			fail(e.toString());
-		} catch (IllegalBlockSizeException  e) {
-			fail(e.toString());
-		}
-
+	public void testDoFinal() throws Exception {
+        assertNull("doFinal failed", c.doFinal());
 	}
 
 	/*
 	 * Class under test for int doFinal(byte[], int)
 	 */
-	public void testDoFinalbyteArrayint() {
+	public void testDoFinalbyteArrayint() throws Exception {
 		byte [] r = new byte[5];
-		try {
-			if (c.doFinal(r, 0) != 0) {
-				fail("doFinal failed");
-			}			
-		} catch (BadPaddingException e) {
-			fail(e.toString());
-		} catch (IllegalBlockSizeException  e) {
-			fail(e.toString());
-		} catch (ShortBufferException e) {
-			fail(e.toString());
-		}
+        assertEquals("doFinal failed", 0, c.doFinal(r, 0));
 	}
 
 	/*
 	 * Class under test for byte[] doFinal(byte[])
 	 */
-	public void testDoFinalbyteArray() {
+	public void testDoFinalbyteArray() throws Exception {
 		byte [] b = {1, 2, 3, 4, 5};
 		byte [] r = null; 
-		try {
-			r = c.doFinal(b);
-		} catch (BadPaddingException e) {
-			fail(e.toString());
-		} catch (IllegalBlockSizeException  e) {
-			fail(e.toString());
-		}
-		if (b.length != r.length) {
-			fail("different length");
-		}
-		for (int i = 0; i < b.length; i++) {
-			if (b[i] != r[i]) {
-				fail("different content");
-			}
-		}		
+		r = c.doFinal(b);
+        assertEquals("different length", b.length, r.length);
+        assertTrue("different content", Arrays.equals(b, r));		
 	}
 
 	/*
 	 * Class under test for byte[] doFinal(byte[], int, int)
 	 */
-	public void testDoFinalbyteArrayintint() {
+	public void testDoFinalbyteArrayintint() throws Exception {
 		byte [] b = {1, 2, 3, 4, 5};
 		byte [] r = null;
-		try {
-			r = c.doFinal(b, 0, 5);
-		} catch (BadPaddingException e) {
-			fail(e.toString());
-		} catch (IllegalBlockSizeException  e) {
-			fail(e.toString());
-		}
-		if (b.length != r.length) {
-			fail("different length");
-		}
-		for (int i = 0; i < b.length; i++) {
-			if (b[i] != r[i]) {
-				fail("different content");
-			}
-		}
+		r = c.doFinal(b, 0, 5);
+        assertEquals("different length", b.length, r.length);
+        assertTrue("different content", Arrays.equals(b, r));
 		
-		try {
-			r = c.doFinal(b, 1, 3);
-		} catch (BadPaddingException e) {
-			fail(e.toString());
-		} catch (IllegalBlockSizeException  e) {
-			fail(e.toString());
-		}
-		if (r.length != 3) {
-			fail("different length");
-		}
+		r = c.doFinal(b, 1, 3);
+        assertEquals("different length", 3, r.length);
 		for (int i = 0; i < 3; i++) {
-			if (b[i + 1] != r[i]) {
-				fail("different content");
-			}
+            assertEquals("different content", b[i + 1], r[i]);
 		}
 	}
 
 	/*
 	 * Class under test for int doFinal(byte[], int, int, byte[])
 	 */
-	public void testDoFinalbyteArrayintintbyteArray() {
+	public void testDoFinalbyteArrayintintbyteArray() throws Exception {
 		byte [] b = {1, 2, 3, 4, 5};
 		byte [] r = new byte[5]; 
-		try {
-			c.doFinal(b, 0, 5, r);			
-		} catch (BadPaddingException e) {
-			fail(e.toString());
-		}  catch (ShortBufferException e) {
-			fail(e.toString());
-		} catch (IllegalBlockSizeException  e) {
-			fail(e.toString());
-		}
-
-		for (int i = 0; i < b.length; i++) {
-			if (b[i] != r[i]) {
-				fail("different content");
-			}
-		}
+		c.doFinal(b, 0, 5, r);			
+        assertTrue("different content", Arrays.equals(b, r));
 	}
 
 	/*
 	 * Class under test for int doFinal(byte[], int, int, byte[], int)
 	 */
-	public void testDoFinalbyteArrayintintbyteArrayint() {
+	public void testDoFinalbyteArrayintintbyteArrayint() throws Exception {
 		byte [] b = {1, 2, 3, 4, 5};
 		byte [] r = new byte[5]; 
-		try {
-			c.doFinal(b, 0, 5, r, 0);			
-		} catch (BadPaddingException e) {
-			fail(e.toString());
-		}  catch (ShortBufferException e) {
-			fail(e.toString());
-		} catch (IllegalBlockSizeException  e) {
-			fail(e.toString());
-		}
-
-		for (int i = 0; i < b.length; i++) {
-			if (b[i] != r[i]) {
-				fail("different content");
-			}
-		}
-	}
-
-	/*
-	 * Class under test for int doFinal(ByteBuffer, ByteBuffer)
-	 */
-	public void testDoFinalByteBufferByteBuffer() {
-	}
-
-	public void testWrap() {
-	}
-
-	public void testUnwrap() {
+		c.doFinal(b, 0, 5, r, 0);
+        assertTrue("different content", Arrays.equals(b, r));
 	}
-
 }

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java (from r410238, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory1Test.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory1Test.java&r1=410238&r2=410243&rev=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactory1Test.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/SecretKeyFactoryTest.java Tue May 30 04:35:44 2006
@@ -45,7 +45,7 @@
  * 
  */
 
-public class SecretKeyFactory1Test extends TestCase {
+public class SecretKeyFactoryTest extends TestCase {
     
     public static final String srvSecretKeyFactory = "SecretKeyFactory";
         
@@ -111,15 +111,6 @@
     }
 
     /**
-     * Constructor for SecretKeyFactoryTests.
-     * 
-     * @param arg0
-     */
-    public SecretKeyFactory1Test(String arg0) {
-        super(arg0);
-    }
-
-    /**
      * Test for <code>SecretKeyFactory</code> constructor
      * Assertion: returns SecretKeyFactory object
      */
@@ -422,30 +413,6 @@
                 assertTrue("Incorrect getKeySpec() result 2",
                         rks instanceof DESKeySpec);
             }
-        }
-    }
-    /**
-     * Test for <code>translateKey(SecretKey key)</code> method
-     * Assertion: 
-     * throw InvalidKeyException if parameter is inappropriate
-     */    
-    public void testSecretKeyFactory11() throws InvalidKeyException {
-        if (!DEFSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
-        byte[] bb = new byte[10];
-        SecretKeySpec secKeySpec = new SecretKeySpec(bb,defaultAlgorithm);
-        SecretKeyFactory[] skF = createSKFac();
-        assertNotNull("SecretKeyFactory object were not created", skF);
-        for (int i = 0; i < skF.length; i++) {
-            try { 
-                skF[i].translateKey(null);
-                fail("InvalidKeyException must be thrown: " + i);
-            } catch (InvalidKeyException e) {
-            }
-
-            skF[i].translateKey(secKeySpec);
         }
     }
 }

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java (from r410238, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/spec/DESKeySpecTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/spec/DESKeySpecTest.java&r1=410238&r2=410243&rev=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/spec/DESKeySpecTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/spec/DESKeySpecTest.java Tue May 30 04:35:44 2006
@@ -18,11 +18,13 @@
 * @version $Revision$
 */
 
-package javax.crypto.spec;
+package org.apache.harmony.crypto.tests.javax.crypto.spec;
 
 import java.lang.NullPointerException;
 import java.security.InvalidKeyException;
 import java.util.Arrays;
+
+import javax.crypto.spec.DESKeySpec;
 
 import junit.framework.Test;
 import junit.framework.TestCase;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/spec/SecretKeySpecTest.java Tue May 30 04:35:44 2006
@@ -182,10 +182,10 @@
                     result[0] == ks.getEncoded()[0]);
 
 		// Regression for HARMONY-78
-		int offset = 1;
-		int len = 4;
-		SecretKeySpec sks = new SecretKeySpec(key, offset, len, algorithm);
-		assertEquals("Key length is incorrect", len, sks.getEncoded().length);
+		int offset = 1;
+		int len = 4;
+		SecretKeySpec sks = new SecretKeySpec(key, offset, len, algorithm);
+		assertEquals("Key length is incorrect", len, sks.getEncoded().length);
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/org/apache/harmony/crypto/internal/NullCipherSpiTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/org/apache/harmony/crypto/internal/NullCipherSpiTest.java?rev=410243&r1=410242&r2=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/org/apache/harmony/crypto/internal/NullCipherSpiTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/org/apache/harmony/crypto/internal/NullCipherSpiTest.java Tue May 30 04:35:44 2006
@@ -22,12 +22,12 @@
 package org.apache.harmony.crypto.internal;
 
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 
 import javax.crypto.ShortBufferException;
 
-import junit.framework.TestCase;
 import org.apache.harmony.crypto.internal.NullCipherSpi;
-
+import junit.framework.TestCase;
 
 /**
  *
@@ -37,23 +37,17 @@
 
 	public void testEngineGetBlockSize() {
 		NullCipherSpi spi = new NullCipherSpi();
-		if (spi.engineGetBlockSize() != 1) {
-			fail("incorrect block size");
-		}
+        assertEquals("incorrect block size", 1, spi.engineGetBlockSize());
 	}
 
 	public void testEngineGetOutputSize() {
 		NullCipherSpi spi = new NullCipherSpi();
-		if (spi.engineGetOutputSize(100) != 100) {
-			fail("incorrect output size");
-		}
+        assertEquals("incorrect output size", 100, spi.engineGetOutputSize(100));
 	}
 
 	public void testEngineGetIV() {
 		NullCipherSpi spi = new NullCipherSpi();
-		if (spi.engineGetIV() != null) {
-			fail("incorrect IV");
-		}
+        assertTrue("Incorrect IV", Arrays.equals(spi.engineGetIV() , new byte[8]));
 	}
 
 	/*
@@ -64,76 +58,46 @@
 		byte[] b = {1,2,3,4,5,6,7,8,9};
 		byte[] b1 =  spi.engineUpdate(b, 3, 4);
 		for (int i = 0; i < 4; i++) {
-			if ( b[3+i] != b1[i] ) {
-				fail("incorrect update result");
-			}
+            assertEquals("incorrect update result", b[3+i], b1[i]);
 		}
 	}
 
 	/*
 	 * Class under test for int engineUpdate(byte[], int, int, byte[], int)
 	 */
-	public void testEngineUpdatebyteArrayintintbyteArrayint() {
+	public void testEngineUpdatebyteArrayintintbyteArrayint() throws Exception {
 		NullCipherSpi spi = new NullCipherSpi();
 		byte[] b = {1,2,3,4,5,6,7,8,9};
 		byte[] b1 =  new byte[10];
-		int n = -1;
-		try {
-			n =	spi.engineUpdate(b, 3, 4, b1, 5);
-		} catch (ShortBufferException e) {
-			fail(e.toString());
-		}
-		if (n != 4) {
-			fail("incorrect update result");
-		}
+		assertEquals("incorrect update result", 4, spi.engineUpdate(b, 3, 4, b1, 5));
 		for (int i = 0; i < 4; i++) {
-			if ( b[3+i] != b1[5+i] ) {
-				fail("incorrect update result");
-			}
+            assertEquals("incorrect update result", b[3+i], b1[5+i]);
 		}	
 	}
 
 	/*
 	 * Class under test for byte[] engineDoFinal(byte[], int, int)
 	 */
-	public void testEngineDoFinalbyteArrayintint() {
+	public void testEngineDoFinalbyteArrayintint() throws Exception {
 		NullCipherSpi spi = new NullCipherSpi();
 		byte[] b = {1,2,3,4,5,6,7,8,9};
 		byte[] b1 = null; 
-		try {
-			b1 = spi.engineDoFinal(b, 3, 4);
-		} catch (Exception e) {
-			fail(e.toString());
-		}
+		b1 = spi.engineDoFinal(b, 3, 4);
 		for (int i = 0; i < 4; i++) {
-			if ( b[3+i] != b1[i] ) {
-				fail("incorrect doFinal result");
-			}
+            assertEquals("incorrect doFinal result", b[3+i], b1[i]);
 		}
 	}
 
 	/*
 	 * Class under test for int engineDoFinal(byte[], int, int, byte[], int)
 	 */
-	public void testEngineDoFinalbyteArrayintintbyteArrayint() {
+	public void testEngineDoFinalbyteArrayintintbyteArrayint() throws Exception {
 		NullCipherSpi spi = new NullCipherSpi();
 		byte[] b = {1,2,3,4,5,6,7,8,9};
 		byte[] b1 =  new byte[10];
-		int n = -1;
-		try {
-			n =	spi.engineDoFinal(b, 3, 4, b1, 5);
-		} catch (ShortBufferException e) {
-			fail(e.toString());
-		} catch (Exception e) {
-			fail(e.toString());
-		}
-		if (n != 4) {
-			fail("incorrect doFinal result");
-		}
+        assertEquals("incorrect doFinal result", 4, spi.engineDoFinal(b, 3, 4, b1, 5));
 		for (int i = 0; i < 4; i++) {
-			if ( b[3+i] != b1[5+i] ) {
-				fail("incorrect doFinal result");
-			}
+            assertEquals("incorrect doFinal result", b[3+i], b1[5+i]);
 		}
 		
 	}
@@ -141,7 +105,7 @@
 	/*
 	 * Class under test for int engineUpdate(ByteBuffer, ByteBuffer)
 	 */
-	public void testEngineUpdateByteBufferByteBuffer() {
+	public void testEngineUpdateByteBufferByteBuffer() throws Exception {
 		NullCipherSpi spi = new NullCipherSpi();
 		byte[] b = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
 
@@ -152,35 +116,22 @@
 			spi.engineUpdate(null, outbuf);
 			fail("No expected NullPointerException");
 		} catch (NullPointerException e) {	
-		} catch (ShortBufferException e) {
-			fail(e.toString());
 		}
 		
 		try {
 			spi.engineUpdate(inbuf, null);
 			fail("No expected NullPointerException");
 		} catch (NullPointerException e) {	
-		} catch (ShortBufferException e) {
-			fail(e.toString());
 		}
 		
 		inbuf.get();
 		inbuf.get();
 		inbuf.get();
 		inbuf.get();
-		int result = 0;
-		try {
-			result = spi.engineUpdate(inbuf, outbuf);
-			if (result != b.length - 4) {
-				fail("incorrect result " + result);
-			}
-		} catch (ShortBufferException e) {
-			fail(e.toString());
-		}
+		int result = spi.engineUpdate(inbuf, outbuf);
+        assertEquals("incorrect result", b.length - 4, result);
 		for (int i = 0; i < result; i++) {
-			if (outbuf.get(i) != i + 4) {		
-				fail("incorrect outbuf");
-			}
+            assertEquals("incorrect outbuf", i + 4, outbuf.get(i));
 		}
 		
 		inbuf = ByteBuffer.wrap(b,0,b.length);
@@ -199,7 +150,7 @@
 	/*
 	 * Class under test for int engineDoFinal(ByteBuffer, ByteBuffer)
 	 */
-	public void testEngineDoFinalByteBufferByteBuffer() {
+	public void testEngineDoFinalByteBufferByteBuffer() throws Exception {
 		NullCipherSpi spi = new NullCipherSpi();
 		byte[] b = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
 
@@ -209,49 +160,24 @@
 		try {
 			spi.engineDoFinal(null, outbuf);
 			fail("No expected NullPointerException");
-		} catch (NullPointerException e) {	
-		} catch (ShortBufferException e) {
-			fail(e.toString());
-		} catch (javax.crypto.BadPaddingException e) {
-			fail(e.toString());			
-		} catch (javax.crypto.IllegalBlockSizeException e) {
-			fail(e.toString());			
+		} catch (NullPointerException e) {			
 		}
 		
 		try {
 			spi.engineDoFinal(inbuf, null);
 			fail("No expected NullPointerException");
-		} catch (NullPointerException e) {	
-		} catch (ShortBufferException e) {
-			fail(e.toString());
-		} catch (javax.crypto.BadPaddingException e) {
-			fail(e.toString());			
-		} catch (javax.crypto.IllegalBlockSizeException e) {
-			fail(e.toString());			
+		} catch (NullPointerException e) {			
 		}
 		
 		inbuf.get();
 		inbuf.get();
 		inbuf.get();
 		inbuf.get();
-		int result = 0;
-		try {
-			result = spi.engineDoFinal(inbuf, outbuf);
-			if (result != b.length - 4) {
-				fail("incorrect result " + result);
-			}
-		} catch (ShortBufferException e) {
-			fail(e.toString());
-		} catch (javax.crypto.BadPaddingException e) {
-			fail(e.toString());			
-		} catch (javax.crypto.IllegalBlockSizeException e) {
-			fail(e.toString());			
-		}
-		for (int i = 0; i < result; i++) {
-			if (outbuf.get(i) != i + 4) {		
-				fail("incorrect outbuf");
-			}
-		}
+		int result = spi.engineDoFinal(inbuf, outbuf);
+        assertEquals("incorrect result", b.length - 4, result);
+        for (int i = 0; i < result; i++) {
+            assertEquals("incorrect outbuf", i + 4, outbuf.get(i));
+        }
 		
 		inbuf = ByteBuffer.wrap(b,0,b.length);
 		outbuf = ByteBuffer.allocate(5);
@@ -263,51 +189,42 @@
 			spi.engineDoFinal(inbuf, outbuf);
 			fail("No expected ShortBufferException");
 		} catch (ShortBufferException e) {
-		} catch (javax.crypto.BadPaddingException e) {
-			fail(e.toString());			
-		} catch (javax.crypto.IllegalBlockSizeException e) {
-			fail(e.toString());			
 		}
 	}
 
 	/*
 	 * Class under test for byte[] engineWrap(Key)
 	 */
-	public void testEngineWrapKey() {
+	public void testEngineWrapKey() throws Exception {
 		NullCipherSpi spi = new NullCipherSpi();
 		try {
 			spi.engineWrap(null);
 			fail("No expected UnsupportedOperationException");
 		} catch (UnsupportedOperationException e) {
-		} catch (Exception e) {
-			fail(e.toString());
-		}	}
+		}	
+    }
 
 	/*
 	 * Class under test for Key engineUnwrap(byte[], String, int)
 	 */
-	public void testEngineUnwrapbyteArrayStringint() {
+	public void testEngineUnwrapbyteArrayStringint() throws Exception {
 		NullCipherSpi spi = new NullCipherSpi();
 		try {
 			spi.engineUnwrap(new byte[3], "", 10);
 			fail("No expected UnsupportedOperationException");
 		} catch (UnsupportedOperationException e) {
-		} catch (Exception e) {
-			fail(e.toString());
 		} 
 	}
 
 	/*
 	 * Class under test for int engineGetKeySize(Key)
 	 */
-	public void testEngineGetKeySize() {
+	public void testEngineGetKeySize() throws Exception {
 		NullCipherSpi spi = new NullCipherSpi();
 		try {
 			spi.engineGetKeySize(null);
 			fail("No expected UnsupportedOperationException");
 		} catch (UnsupportedOperationException e) {
-		} catch (Exception e) {
-			fail(e.toString());
 		} 
 	}
 

Added: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Cipher_Impl1Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Cipher_Impl1Test.java?rev=410243&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Cipher_Impl1Test.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Cipher_Impl1Test.java Tue May 30 04:35:44 2006
@@ -0,0 +1,101 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+package org.apache.harmony.crypto.tests.javax.crypto;
+
+import java.security.AlgorithmParameters;
+import java.security.Key;
+import java.security.SecureRandom;
+import java.util.Arrays;
+
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+
+public class Cipher_Impl1Test extends junit.framework.TestCase {
+    
+    static Key cipherKey;
+    final static String algorithm = "DESede";
+    final static int keyLen = 168;
+    
+    static {
+        try {
+            KeyGenerator kg = KeyGenerator.getInstance(algorithm);
+            kg.init(keyLen, new SecureRandom());
+            cipherKey = kg.generateKey();
+        } catch (Exception e) {
+            fail("No key " + e);
+        }
+    }
+
+
+    /**
+     * @tests javax.crypto.Cipher#getIV()
+     * @tests javax.crypto.Cipher#init(int, java.security.Key,
+     *        java.security.AlgorithmParameters)
+     */
+    public void test_getIV() throws Exception {
+        /*
+         * If this test is changed, implement the following:
+         * test_initILjava_security_KeyLjava_security_AlgorithmParameters()
+         */
+
+        SecureRandom sr = new SecureRandom();
+        Cipher cipher = null;
+
+        byte[] iv = new byte[8];
+        sr.nextBytes(iv);
+        AlgorithmParameters ap = AlgorithmParameters.getInstance(algorithm);
+        ap.init(iv, "RAW");
+
+        cipher = Cipher.getInstance(algorithm + "/CBC/PKCS5Padding");
+        cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ap);
+
+        byte[] cipherIV = cipher.getIV();
+
+        assertTrue("IVs differ", Arrays.equals(cipherIV, iv));
+    }
+
+    /**
+     * @tests javax.crypto.Cipher#getParameters()
+     * @tests javax.crypto.Cipher#init(int, java.security.Key,
+     *        java.security.AlgorithmParameters, java.security.SecureRandom)
+     */
+    public void test_getParameters() throws Exception {
+
+        /*
+         * If this test is changed, implement the following:
+         * test_initILjava_security_KeyLjava_security_AlgorithmParametersLjava_security_SecureRandom()
+         */
+
+        SecureRandom sr = new SecureRandom();
+        Cipher cipher = null;
+
+        byte[] apEncoding = null;
+
+        byte[] iv = new byte[8];
+        sr.nextBytes(iv);
+
+        AlgorithmParameters ap = AlgorithmParameters.getInstance("DESede");
+        ap.init(iv, "RAW");
+        apEncoding = ap.getEncoded("ASN.1");
+
+        cipher = Cipher.getInstance(algorithm + "/CBC/PKCS5Padding");
+        cipher.init(Cipher.ENCRYPT_MODE, cipherKey, ap, sr);
+
+        byte[] cipherParmsEnc = cipher.getParameters().getEncoded("ASN.1");
+        assertTrue("Parameters differ", Arrays.equals(apEncoding,
+                cipherParmsEnc));
+    }
+}

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Cipher_ImplTest.java (from r410238, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Cipher_ImplTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Cipher_ImplTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Cipher_ImplTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Cipher_ImplTest.java&r1=410238&r2=410243&rev=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Cipher_ImplTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Cipher_ImplTest.java Tue May 30 04:35:44 2006
@@ -18,7 +18,7 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.javax.crypto;
 
 import java.security.InvalidKeyException;
 import java.security.Key;
@@ -28,8 +28,11 @@
 import java.security.Security;
 import java.security.spec.InvalidKeySpecException;
 
-import org.apache.harmony.security.support.TestKeyPair;
+import javax.crypto.Cipher;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.ShortBufferException;
 
+import org.apache.harmony.security.support.TestKeyPair;
 
 import junit.framework.TestCase;
 
@@ -253,65 +256,6 @@
 		assertEquals(3, c.getIV().length);
 	}
 
-	public void testGetParameters() throws NoSuchAlgorithmException,
-            NoSuchPaddingException {
-
-		Cipher c = Cipher.getInstance("DES");
-		assertNull(c.getParameters());
-	}
-
-	public void testGetExemptionMechanism() {
-//FIXME implement testGetExemptionMechanism
-	}
-
-	/*
-	 * Class under test for void init(int, Key)
-	 */
-	public void testInitintKey() {
-	}
-
-	/*
-	 * Class under test for void init(int, Key, SecureRandom)
-	 */
-	public void testInitintKeySecureRandom() {
-	}
-
-	/*
-	 * Class under test for void init(int, Key, AlgorithmParameterSpec)
-	 */
-	public void testInitintKeyAlgorithmParameterSpec() {
-	}
-
-	/*
-	 * Class under test for void init(int, Key, AlgorithmParameterSpec, SecureRandom)
-	 */
-	public void testInitintKeyAlgorithmParameterSpecSecureRandom() {
-	}
-
-	/*
-	 * Class under test for void init(int, Key, AlgorithmParameters)
-	 */
-	public void testInitintKeyAlgorithmParameters() {
-	}
-
-	/*
-	 * Class under test for void init(int, Key, AlgorithmParameters, SecureRandom)
-	 */
-	public void testInitintKeyAlgorithmParametersSecureRandom() {
-	}
-
-	/*
-	 * Class under test for void init(int, Certificate)
-	 */
-	public void testInitintCertificate() {
-	}
-
-	/*
-	 * Class under test for void init(int, Certificate, SecureRandom)
-	 */
-	public void testInitintCertificateSecureRandom() {
-	}
-
 	/*
 	 * Class under test for byte[] update(byte[])
 	 */
@@ -337,127 +281,6 @@
 		} catch (IllegalArgumentException e){
 		}
 		assertNull(c.update(new byte[0]));
-	}
-
-	/*
-	 * Class under test for byte[] update(byte[], int, int)
-	 */
-	public void testUpdatebyteArrayintint() {
-	}
-
-	/*
-	 * Class under test for int update(byte[], int, int, byte[])
-	 */
-	public void testUpdatebyteArrayintintbyteArray() {
-	}
-
-	/*
-	 * Class under test for int update(byte[], int, int, byte[], int)
-	 */
-	public void testUpdatebyteArrayintintbyteArrayint() {
-//		try {
-//			spi.engineUpdate(b, 3, 6, b1, 5);
-//			fail("No expected ShortBufferException");
-//		} catch (ShortBufferException e) {
-//		}
-	}
-
-	/*
-	 * Class under test for int update(ByteBuffer, ByteBuffer)
-	 */
-	public void testUpdateByteBufferByteBuffer() {
-	}
-
-	/*
-	 * Class under test for byte[] doFinal()
-	 */
-	public void testDoFinal() {
-	}
-
-	/*
-	 * Class under test for int doFinal(byte[], int)
-	 */
-	public void testDoFinalbyteArrayint() {
-	}
-
-	/*
-	 * Class under test for byte[] doFinal(byte[])
-	 */
-	public void testDoFinalbyteArray() {
-	}
-
-	/*
-	 * Class under test for byte[] doFinal(byte[], int, int)
-	 */
-	public void testDoFinalbyteArrayintint() {
-	}
-
-	/*
-	 * Class under test for int doFinal(byte[], int, int, byte[])
-	 */
-	public void testDoFinalbyteArrayintintbyteArray() {
-	}
-
-	/*
-	 * Class under test for int doFinal(byte[], int, int, byte[], int)
-	 */
-	public void testDoFinalbyteArrayintintbyteArrayint() {
-//		try {
-//			spi.engineDoFinal(b, 3, 6, b1, 5);
-//			fail("No expected ShortBufferException");
-//		} catch (ShortBufferException e) {
-//		} catch (Exception e) {
-//			fail(e.toString());
-//		}
-	}
-
-	/*
-	 * Class under test for int doFinal(ByteBuffer, ByteBuffer)
-	 */
-	public void testDoFinalByteBufferByteBuffer() {
-	}
-
-	public void testWrap() {
-	}
-
-	public void testUnwrap() {
-	}
-
-	public void testGetMaxAllowedKeyLength() throws NoSuchAlgorithmException {
-		try {
-			Cipher.getMaxAllowedKeyLength(null);
-			fail("No expected NullPointerException");
-		} catch (NullPointerException e) {
-		}
-		try {
-			Cipher.getMaxAllowedKeyLength("//CBC/PKCS5Paddin");
-			fail("No expected NoSuchAlgorithmException");
-		} catch (NoSuchAlgorithmException e) {
-		}
-		try {
-			Cipher.getMaxAllowedKeyLength("/DES/CBC/PKCS5Paddin/1");
-			fail("No expected NoSuchAlgorithmException");
-		} catch (NoSuchAlgorithmException e) {
-		}
-	}
-
-	public void testGetMaxAllowedParameterSpec()
-            throws NoSuchAlgorithmException {
-		try {
-			Cipher.getMaxAllowedParameterSpec(null);
-			fail("No expected NullPointerException");
-		} catch (NullPointerException e) {
-		}
-		try {
-			Cipher.getMaxAllowedParameterSpec("/DES//PKCS5Paddin");
-			fail("No expected NoSuchAlgorithmException");
-		} catch (NoSuchAlgorithmException e) {
-		}
-		try {
-			Cipher.getMaxAllowedParameterSpec("/DES/CBC/ /1");
-			fail("No expected NoSuchAlgorithmException");
-		} catch (NoSuchAlgorithmException e) {
-		}
 	}
 	
 	private class MyProvider1 extends Provider {

Added: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfo_ImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfo_ImplTest.java?rev=410243&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfo_ImplTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/EncryptedPrivateKeyInfo_ImplTest.java Tue May 30 04:35:44 2006
@@ -0,0 +1,123 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+* @author Vladimir N. Molotkov
+* @version $Revision$
+*/
+
+package org.apache.harmony.crypto.tests.javax.crypto;
+
+import java.io.IOException;
+import java.security.AlgorithmParameters;
+import java.security.NoSuchAlgorithmException;
+
+import javax.crypto.EncryptedPrivateKeyInfo;
+
+import org.apache.harmony.crypto.tests.support.EncryptedPrivateKeyInfoData;
+
+import junit.framework.TestCase;
+
+/**
+ * Test for EncryptedPrivateKeyInfo class.
+ * 
+ * All binary data for this test were generated using
+ * BEA JRockit j2sdk1.4.2_04 (http://www.bea.com) with
+ * security providers list extended by Bouncy Castle's one
+ * (http://www.bouncycastle.org)
+ */
+public class EncryptedPrivateKeyInfo_ImplTest extends TestCase {
+
+    /**
+     * Test #1 for <code>getAlgName()</code> method <br>
+     * Assertion: Returns the encryption algorithm name <br>
+     * Test preconditions: test object created using ctor which takes encoded
+     * form as the only parameter <br>
+     * Expected: corresponding algorithm name must be returned
+     * 
+     * @throws IOException
+     */
+    public final void testGetAlgName01() throws IOException {
+        boolean performed = false;
+        for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
+            try {
+                EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
+                        EncryptedPrivateKeyInfoData
+                                .getValidEncryptedPrivateKeyInfoEncoding(
+                                        EncryptedPrivateKeyInfoData.algName0[i][0]));
+                assertEquals(EncryptedPrivateKeyInfoData.algName0[i][1], epki
+                        .getAlgName());
+                performed = true;
+            } catch (NoSuchAlgorithmException allowed) {
+            }
+        }
+        assertTrue("Test not perfrormed", performed);
+    }
+
+    /**
+     * Test #2 for <code>getAlgName()</code> method <br>
+     * Assertion: Returns the encryption algorithm name <br>
+     * Test preconditions: test object created using ctor which takes algorithm
+     * name and encrypted data as a parameters <br>
+     * Expected: corresponding algorithm name must be returned
+     * 
+     * @throws IOException
+     */
+    public final void testGetAlgName02() {
+        boolean performed = false;
+        for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
+            try {
+                EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(
+                        EncryptedPrivateKeyInfoData.algName0[i][0],
+                        EncryptedPrivateKeyInfoData.encryptedData);
+                assertEquals(EncryptedPrivateKeyInfoData.algName0[i][1], epki
+                        .getAlgName());
+                performed = true;
+            } catch (NoSuchAlgorithmException allowedFailure) {
+            }
+        }
+        assertTrue("Test not perfrormed", performed);
+    }
+
+    /**
+     * Test #3 for <code>getAlgName()</code> method <br>
+     * Assertion: Returns the encryption algorithm name <br>
+     * Test preconditions: test object created using ctor which takes
+     * AlgorithmParameters and encrypted data as a parameters <br>
+     * Expected: corresponding algorithm name must be returned
+     * 
+     * @throws IOException
+     */
+    public final void testGetAlgName03() throws IOException {
+        boolean performed = false;
+        for (int i = 0; i < EncryptedPrivateKeyInfoData.algName0.length; i++) {
+            try {
+                AlgorithmParameters ap = AlgorithmParameters
+                        .getInstance(EncryptedPrivateKeyInfoData.algName0[i][0]);
+                // use pregenerated AlgorithmParameters encodings
+                ap.init(EncryptedPrivateKeyInfoData.getParametersEncoding(
+                        EncryptedPrivateKeyInfoData.algName0[i][0]));
+                EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(ap,
+                        EncryptedPrivateKeyInfoData.encryptedData);
+                assertEquals(EncryptedPrivateKeyInfoData.algName0[i][1], epki
+                        .getAlgName());
+                performed = true;
+            } catch (NoSuchAlgorithmException allowedFailure) {
+            }
+        }
+        assertTrue("Test not perfrormed", performed);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanism_ImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanism_ImplTest.java?rev=410243&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanism_ImplTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanism_ImplTest.java Tue May 30 04:35:44 2006
@@ -0,0 +1,318 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.crypto.tests.javax.crypto;
+
+import java.security.AlgorithmParameters;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.Security;
+import java.security.spec.AlgorithmParameterSpec;
+
+import javax.crypto.ExemptionMechanism;
+import javax.crypto.ExemptionMechanismException;
+import javax.crypto.ExemptionMechanismSpi;
+import javax.crypto.ShortBufferException;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi;
+import org.apache.harmony.security.SpiEngUtils;
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for <code>ExemptionMechanism</code> class constructors and methods
+ * 
+ */
+
+public class ExemptionMechanism_ImplTest extends TestCase {
+    
+    public static final String srvExemptionMechanism = "ExemptionMechanism";
+    
+    private static final String defaultAlg = "EMech";
+    
+    private static final String ExemptionMechanismProviderClass = "org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi";
+
+    private static final String[] invalidValues = SpiEngUtils.invalidValues;
+
+    private static final String[] validValues;
+
+    static {
+        validValues = new String[4];
+        validValues[0] = defaultAlg;
+        validValues[1] = defaultAlg.toLowerCase();
+        validValues[2] = "eMEch";
+        validValues[3] = "emecH";
+    }
+
+    Provider mProv;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", 
+                srvExemptionMechanism.concat(".").concat(defaultAlg), 
+                ExemptionMechanismProviderClass);
+        Security.insertProviderAt(mProv, 1);
+    }
+    
+    /*
+     * @see TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        Security.removeProvider(mProv.getName());
+    }
+
+    private void checkResult(ExemptionMechanism exMech) 
+            throws ExemptionMechanismException, ShortBufferException,
+            InvalidKeyException, InvalidAlgorithmParameterException  {
+        Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
+        byte [] emptyA = new byte[0];
+        int len = MyExemptionMechanismSpi.getLength();
+        byte [] byteA = new byte[len];
+        try {
+            exMech.genExemptionBlob();
+            fail("IllegalStateException must be thrown");
+        } catch (IllegalStateException e) {            
+        }
+        try {
+            exMech.genExemptionBlob(byteA);
+            fail("IllegalStateException must be thrown");
+        } catch (IllegalStateException e) {            
+        }
+        try {
+            exMech.genExemptionBlob(byteA, 1);
+            fail("IllegalStateException must be thrown");
+        } catch (IllegalStateException e) {            
+        }        
+        try {
+            exMech.getOutputSize(0);
+            fail("IllegalStateException must be thrown");
+        } catch (IllegalStateException e) {            
+        }        
+        
+        exMech.init(key);
+        byte [] bbRes = exMech.genExemptionBlob();
+        assertEquals("Incorrect length", bbRes.length, len);
+        assertEquals("Incorrect result", exMech.genExemptionBlob(new byte[5]), 5);
+        assertEquals("Incorrect result", exMech.genExemptionBlob(bbRes), len);
+        try {
+            exMech.genExemptionBlob(new byte[1], len);
+            fail("ShortBufferException must be thrown");
+        } catch (ShortBufferException e) {            
+        }        
+        try {
+            exMech.genExemptionBlob(emptyA);
+            fail("ShortBufferException must be thrown");
+        } catch (ShortBufferException e) {            
+        }
+        
+        assertEquals("Incorrect result", exMech.genExemptionBlob(byteA, 1), 9);
+        assertEquals("Incorrect result", exMech.genExemptionBlob(new byte[20], (len - 2)), len);
+                
+        assertEquals("Incorrect output size", exMech.getOutputSize(100), 5);
+        
+        AlgorithmParameters params = null;
+        exMech.init(key, params);
+        AlgorithmParameterSpec parSpec = null;
+        exMech.init(key, parSpec);
+        key = new SecretKeySpec(new byte[10], "DSA");
+        try {
+            exMech.init(key);
+            fail("ExemptionMechanismException must be throwm");
+        } catch (ExemptionMechanismException e) {
+            assertTrue("Empty message", (e.getMessage().length() > 0));
+        }
+        try {
+            exMech.init(key, params);
+            fail("ExemptionMechanismException must be throwm");
+        } catch (ExemptionMechanismException e) {
+            assertTrue("Empty message", (e.getMessage().length() > 0));
+        }
+        try {
+            exMech.init(key, parSpec);
+            fail("ExemptionMechanismException must be throwm");
+        } catch (ExemptionMechanismException e) {
+            assertTrue("Empty message", (e.getMessage().length() > 0));
+        }
+    }
+    
+    /**
+     * Test for <code>getInstance(String algorithm)</code> method
+     * Assertions:
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is incorrect;
+     * returns ExemptionMechanism object
+     */
+    public void testGetInstance01() throws NoSuchAlgorithmException,
+            ExemptionMechanismException, InvalidAlgorithmParameterException,
+            ShortBufferException, InvalidKeyException {
+        try {
+            ExemptionMechanism.getInstance(null);
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                ExemptionMechanism.getInstance(invalidValues[i]);
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        ExemptionMechanism exMech;
+        for (int i = 0; i < validValues.length; i++) {
+            exMech = ExemptionMechanism.getInstance(validValues[i]);
+            assertEquals("Incorrect algorithm", exMech.getName(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", exMech.getProvider(), mProv);
+            checkResult(exMech);
+        }
+    }
+
+    /**
+     * Test for <code>getInstance(String algorithm, String provider)</code>
+     * method
+     * Assertions: 
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is null or incorrect;
+     * throws IllegalArgumentException when provider is null;
+     * throws NoSuchProviderException when provider is available;
+     * returns ExemptionMechanism object
+     */
+    public void testGetInstance02() throws NoSuchAlgorithmException,
+            NoSuchProviderException, IllegalArgumentException,
+            ExemptionMechanismException, InvalidAlgorithmParameterException,
+            ShortBufferException, InvalidKeyException {        
+        try {
+            ExemptionMechanism.getInstance(null, mProv.getName());
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                ExemptionMechanism.getInstance(invalidValues[i], mProv
+                        .getName());
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        String prov = null;
+        for (int i = 0; i < validValues.length; i++) {
+            try {
+                ExemptionMechanism.getInstance(validValues[i], prov);
+                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+        }
+        for (int i = 0; i < validValues.length; i++) {
+            for (int j = 1; j < invalidValues.length; j++) {
+                try {
+                    ExemptionMechanism.getInstance(validValues[i],
+                            invalidValues[j]);
+                    fail("NoSuchProviderException must be thrown (algorithm: "
+                            .concat(invalidValues[i]).concat(" provider: ")
+                            .concat(invalidValues[j]).concat(")"));
+                } catch (NoSuchProviderException e) {
+                }
+            }
+        }
+        ExemptionMechanism exMech;
+        for (int i = 0; i < validValues.length; i++) {
+            exMech = ExemptionMechanism.getInstance(validValues[i], mProv
+                    .getName());
+            assertEquals("Incorrect algorithm", exMech.getName(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", exMech.getProvider().getName(),
+                    mProv.getName());
+            checkResult(exMech);
+        }
+    }
+
+    /**
+     * Test for <code>getInstance(String algorithm, Provider provider)</code>
+     * method
+     * Assertions:
+     * throws NullPointerException when algorithm is null;
+     * throws NoSuchAlgorithmException when algorithm is null or incorrect;
+     * throws IllegalArgumentException when provider is null;
+     * returns ExemptionMechanism object
+     */
+    public void testGetInstance03() throws NoSuchAlgorithmException,
+            IllegalArgumentException,
+            ExemptionMechanismException, InvalidAlgorithmParameterException,
+            ShortBufferException, InvalidKeyException {
+        try {
+            ExemptionMechanism.getInstance(null, mProv);
+            fail("NullPointerException or NoSuchAlgorithmException should be thrown if algorithm is null");
+        } catch (NullPointerException e) {
+        } catch (NoSuchAlgorithmException e) {
+        }
+        for (int i = 0; i < invalidValues.length; i++) {
+            try {
+                ExemptionMechanism.getInstance(invalidValues[i], mProv);
+                fail("NoSuchAlgorithmException must be thrown (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (NoSuchAlgorithmException e) {
+            }
+        }
+        Provider prov = null;
+        for (int i = 0; i < validValues.length; i++) {
+            try {
+                ExemptionMechanism.getInstance(validValues[i], prov);
+                fail("IllegalArgumentException must be thrown when provider is null (algorithm: "
+                        .concat(invalidValues[i]).concat(")"));
+            } catch (IllegalArgumentException e) {
+            }
+        }
+        ExemptionMechanism exMech;
+        for (int i = 0; i < validValues.length; i++) {
+            exMech = ExemptionMechanism.getInstance(validValues[i], mProv);
+            assertEquals("Incorrect algorithm", exMech.getName(),
+                    validValues[i]);
+            assertEquals("Incorrect provider", exMech.getProvider(), mProv);
+            checkResult(exMech);
+        }
+    }
+}
+
+class myEM extends ExemptionMechanism {
+
+    public myEM(ExemptionMechanismSpi spi, Provider prov, String mechanism) {
+        super(spi, prov, mechanism);
+    }
+
+    public void finalize() {
+        try {
+            super.finalize();
+        } catch (Throwable e) {
+            throw new RuntimeException("finalize was broken", e);
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement_Impl1Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement_Impl1Test.java?rev=410243&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement_Impl1Test.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement_Impl1Test.java Tue May 30 04:35:44 2006
@@ -0,0 +1,101 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.
+ */
+
+/**
+* @author Vera Y. Petrashkova
+* @version $Revision$
+*/
+
+package org.apache.harmony.crypto.tests.javax.crypto;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Provider;
+
+import javax.crypto.KeyAgreement;
+import javax.crypto.KeyAgreementSpi;
+
+import org.apache.harmony.crypto.tests.support.MyKeyAgreementSpi;
+import org.apache.harmony.security.SpiEngUtils;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for KeyAgreement constructor and methods
+ * 
+ */
+
+public class KeyAgreement_Impl1Test extends TestCase {
+
+    public static final String srvKeyAgreement = "KeyAgreement";
+
+    private static String defaultAlgorithm = "DH";
+
+
+    private static Provider defaultProvider = null;
+
+    private static boolean DEFSupported = false;
+
+    private static final String NotSupportMsg = "There is no suitable provider for KeyAgreement";
+
+
+    static {
+        defaultProvider = SpiEngUtils.isSupport(defaultAlgorithm,
+                srvKeyAgreement);
+        DEFSupported = (defaultProvider != null);
+    }
+
+    /**
+     * Test for <code>KeyAgreement</code> constructor Assertion: returns
+     * KeyAgreement object
+     */
+    public void testKeyAgreement() throws NoSuchAlgorithmException,
+            InvalidKeyException, IllegalStateException {
+        if (!DEFSupported) {
+            fail(NotSupportMsg);
+            return;
+        }
+        KeyAgreementSpi spi = new MyKeyAgreementSpi();
+        KeyAgreement keyA = new myKeyAgreement(spi, defaultProvider,
+                defaultAlgorithm);
+        assertEquals("Incorrect algorithm", keyA.getAlgorithm(),
+                defaultAlgorithm);
+        assertEquals("Incorrect provider", keyA.getProvider(), defaultProvider);
+        assertNull("Incorrect result", keyA.doPhase(null, true));
+        assertEquals("Incorrect result", keyA.generateSecret().length, 0);
+
+        keyA = new myKeyAgreement(null, null, null);
+        assertNull("Algorithm must be null", keyA.getAlgorithm());
+        assertNull("Provider must be null", keyA.getProvider());
+        try {
+            keyA.doPhase(null, true);
+            fail("NullPointerEXception must be thrown");
+        } catch (NullPointerException e) {
+        }
+    }
+}
+
+/**
+ * Additional class for KeyAgreement constructor verification
+ */
+
+class myKeyAgreement extends KeyAgreement {
+
+    public myKeyAgreement(KeyAgreementSpi keyAgreeSpi, Provider provider,
+            String algorithm) {
+        super(keyAgreeSpi, provider, algorithm);
+    }
+}

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement_ImplTest.java (from r410238, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyAgreement_ImplTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement_ImplTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement_ImplTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyAgreement_ImplTest.java&r1=410238&r2=410243&rev=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyAgreement_ImplTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyAgreement_ImplTest.java Tue May 30 04:35:44 2006
@@ -19,7 +19,7 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.javax.crypto;
 
 import java.security.InvalidAlgorithmParameterException;
 import java.security.InvalidKeyException;
@@ -32,6 +32,9 @@
 import java.security.spec.AlgorithmParameterSpec;
 import java.security.spec.InvalidKeySpecException;
 
+import javax.crypto.KeyAgreement;
+import javax.crypto.ShortBufferException;
+
 import org.apache.harmony.security.SpiEngUtils;
 import junit.framework.TestCase;
 
@@ -77,15 +80,6 @@
     protected void tearDown() throws Exception {
         super.tearDown();
         Security.removeProvider(mProv.getName());
-    }
-
-    /**
-     * Constructor for SecurityManagerFactoryTest2.
-     * 
-     * @param arg0
-     */
-    public KeyAgreement_ImplTest(String arg0) {
-        super(arg0);
     }
     
     protected void checkResult(KeyAgreement keyAgr) 

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGenerator_ImplTest.java (from r410238, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyGenerator_ImplTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGenerator_ImplTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGenerator_ImplTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyGenerator_ImplTest.java&r1=410238&r2=410243&rev=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/KeyGenerator_ImplTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/KeyGenerator_ImplTest.java Tue May 30 04:35:44 2006
@@ -19,7 +19,7 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.javax.crypto;
 
 import java.security.InvalidAlgorithmParameterException;
 import java.security.InvalidKeyException;
@@ -31,6 +31,8 @@
 import java.security.spec.AlgorithmParameterSpec;
 import java.security.spec.InvalidKeySpecException;
 
+import javax.crypto.KeyGenerator;
+
 import org.apache.harmony.security.SpiEngUtils;
 import junit.framework.TestCase;
 
@@ -76,15 +78,6 @@
     protected void tearDown() throws Exception {
         super.tearDown();
         Security.removeProvider(mProv.getName());
-    }
-
-    /**
-     * Constructor for SecurityManagerFactoryTest2.
-     * 
-     * @param arg0
-     */
-    public KeyGenerator_ImplTest(String arg0) {
-        super(arg0);
     }
 
     private void checkResult(KeyGenerator keyGen) {

Copied: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Mac_ImplTest.java (from r410238, incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Mac_ImplTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Mac_ImplTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Mac_ImplTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Mac_ImplTest.java&r1=410238&r2=410243&rev=410243&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java.injected/javax/crypto/Mac_ImplTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/impl/java/org/apache/harmony/crypto/tests/javax/crypto/Mac_ImplTest.java Tue May 30 04:35:44 2006
@@ -19,7 +19,7 @@
 * @version $Revision$
 */
 
-package javax.crypto;
+package org.apache.harmony.crypto.tests.javax.crypto;
 
 import java.security.InvalidAlgorithmParameterException;
 import java.security.InvalidKeyException;
@@ -30,6 +30,7 @@
 import java.security.Security;
 import java.security.spec.AlgorithmParameterSpec;
 
+import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.harmony.security.SpiEngUtils;
@@ -78,15 +79,6 @@
     protected void tearDown() throws Exception {
         super.tearDown();
         Security.removeProvider(mProv.getName());
-    }
-
-    /**
-     * Constructor for SecurityManagerFactoryTest2.
-     * 
-     * @param arg0
-     */
-    public Mac_ImplTest(String arg0) {
-        super(arg0);
     }
     
     protected void checkResult(Mac mac) throws InvalidKeyException,



Mime
View raw message