harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r410852 - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security: IdentityScopeTest.java IdentityTest.java KeyPairGeneratorTest.java SignatureTest.java
Date Thu, 01 Jun 2006 12:10:40 GMT
Author: mloenko
Date: Thu Jun  1 05:10:39 2006
New Revision: 410852

URL: http://svn.apache.org/viewvc?rev=410852&view=rev
Log:
accelerating 4 security tests

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/IdentityScopeTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/IdentityTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/KeyPairGeneratorTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/SignatureTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/IdentityScopeTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/IdentityScopeTest.java?rev=410852&r1=410851&r2=410852&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/IdentityScopeTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/IdentityScopeTest.java
Thu Jun  1 05:10:39 2006
@@ -18,7 +18,6 @@
 import java.security.Identity;
 import java.security.IdentityScope;
 import java.security.KeyManagementException;
-import java.security.KeyPair;
 import java.security.KeyPairGenerator;
 import java.security.PublicKey;
 import java.util.Enumeration;
@@ -29,6 +28,13 @@
 public class IdentityScopeTest extends junit.framework.TestCase {
 
 	static PublicKey pubKey;
+    static {
+        try {
+            pubKey = KeyPairGenerator.getInstance("DSA").genKeyPair().getPublic();
+        } catch (Exception e) {
+            fail(e.toString());
+        }
+    }
 
 	public static class IdentityScopeSubclass extends IdentityScope {
 		Hashtable identities;
@@ -243,11 +249,5 @@
        		sub.addIdentity(id);
        		assertNotNull("toString returned a null", sub.toString());
        		assertTrue("Not a valid String ", sub.toString().length() > 0);
-	}
-
-	protected void setUp() throws Exception {
-       		KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
-       		KeyPair pair = gen.genKeyPair();
-       		pubKey = pair.getPublic();
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/IdentityTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/IdentityTest.java?rev=410852&r1=410851&r2=410852&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/IdentityTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/IdentityTest.java
Thu Jun  1 05:10:39 2006
@@ -21,7 +21,6 @@
 import java.security.Identity;
 import java.security.IdentityScope;
 import java.security.KeyManagementException;
-import java.security.KeyPair;
 import java.security.KeyPairGenerator;
 import java.security.Principal;
 import java.security.PublicKey;
@@ -32,6 +31,15 @@
 
 public class IdentityTest extends junit.framework.TestCase {
 
+    static PublicKey pubKey;
+    static {
+        try {
+            pubKey = KeyPairGenerator.getInstance("DSA").genKeyPair().getPublic();
+        } catch (Exception e) {
+            fail(e.toString());
+        }
+    }
+
 	public static class CertificateImpl implements java.security.Certificate {
 
 		X509Certificate cert;
@@ -109,8 +117,6 @@
 	ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2
 			.getBytes());
 
-	static PublicKey pubKey;
-
 	public static class IdentitySubclass extends Identity {
 		public IdentitySubclass() {
 			super();
@@ -301,10 +307,4 @@
        		assertEquals("The 2 hash codes are not equal", sub.hashCode(), sub2
        				.hashCode());
 	}
-
-	protected void setUp() throws Exception {
-       		KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
-       		KeyPair pair = gen.genKeyPair();
-       		pubKey = pair.getPublic();
-	}
-}
\ No newline at end of file
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/KeyPairGeneratorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/KeyPairGeneratorTest.java?rev=410852&r1=410851&r2=410852&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/KeyPairGeneratorTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/KeyPairGeneratorTest.java
Thu Jun  1 05:10:39 2006
@@ -16,7 +16,6 @@
 package tests.api.java.security;
 
 import java.math.BigInteger;
-import java.security.KeyPair;
 import java.security.KeyPairGenerator;
 import java.security.Provider;
 import java.security.SecureRandom;
@@ -25,96 +24,97 @@
 
 public class KeyPairGeneratorTest extends junit.framework.TestCase {
 
-	/**
-	 * @tests java.security.KeyPairGenerator#genKeyPair()
-	 */
-	public void test_genKeyPair() throws Exception {
-       		KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
-       		gen.initialize(1024);
-       		KeyPair pair = gen.genKeyPair();
-       		assertNotNull("KeyPair is null", pair);
-	}
-
-	/**
-	 * @tests java.security.KeyPairGenerator#getAlgorithm()
-	 */
-	public void test_getAlgorithm() throws Exception {
-       		String alg = KeyPairGenerator.getInstance("DSA").getAlgorithm();
-       		assertEquals("getAlgorithm returned enexpected value", "DSA", alg);
-	}
-
-	/**
-	 * @tests java.security.KeyPairGenerator#getInstance(java.lang.String)
-	 */
-	public void test_getInstanceLjava_lang_String() throws Exception {
-		KeyPairGenerator.getInstance("DSA");
-	}
-
-	/**
-	 * @tests java.security.KeyPairGenerator#getInstance(java.lang.String,
-	 *        java.lang.String)
-	 */
-	public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
-		// Test1: Test with named provider
-       		Provider[] providers = Security
-       				.getProviders("KeyPairGenerator.DSA");
-
-       		for (int i = 0; i < providers.length; i++) {
-       			KeyPairGenerator.getInstance("DSA", providers[i].getName());
-       		}// end for
-
-
-		// Test2: Test with empty provider name - should raise
-		// IllegalArgumentException
-		try {
-			KeyPairGenerator.getInstance("DSA", "");
-			fail("Should have thrown IllegalArgumentException");
-		} catch (IllegalArgumentException e) {
-			// expected
-		}
-	}
-
-	/**
-	 * @tests java.security.KeyPairGenerator#getProvider()
-	 */
-	public void test_getProvider() throws Exception {
-       		Provider p = KeyPairGenerator.getInstance("DSA").getProvider();
-       		assertNotNull("provider is null", p);
-	}
-
-	/**
-	 * @tests java.security.KeyPairGenerator#initialize(int)
-	 */
-	public void test_initializeI() throws Exception {
-       		KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
-       		keyPair.initialize(1024);
-	}
-
-	/**
-	 * @tests java.security.KeyPairGenerator#initialize(int,
-	 *        java.security.SecureRandom)
-	 */
-	public void test_initializeILjava_security_SecureRandom() throws Exception {
-       		KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
-       		keyPair.initialize(1024, new SecureRandom());
-	}
-
-	/**
-	 * @tests java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec)
-	 */
-	public void test_initializeLjava_security_spec_AlgorithmParameterSpec() throws Exception
{
-       		KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
-       		keyPair.initialize(new DSAParameterSpec(BigInteger.ONE,
-       				BigInteger.ONE, BigInteger.ONE));
-	}
-
-	/**
-	 * @tests java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec,
-	 *        java.security.SecureRandom)
-	 */
-	public void test_initializeLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom()
throws Exception {
-       		KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
-       		keyPair.initialize(new DSAParameterSpec(BigInteger.ONE,
-       				BigInteger.ONE, BigInteger.ONE), new SecureRandom());
-	}
-}
\ No newline at end of file
+    /**
+     * @tests java.security.KeyPairGenerator#genKeyPair()
+     */
+    public void test_genKeyPair() throws Exception {
+        KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
+        gen.initialize(1024);
+        assertNotNull("KeyPair is null", gen.genKeyPair());
+    }
+
+    /**
+     * @tests java.security.KeyPairGenerator#getAlgorithm()
+     */
+    public void test_getAlgorithm() throws Exception {
+        String alg = KeyPairGenerator.getInstance("DSA").getAlgorithm();
+        assertEquals("getAlgorithm returned enexpected value", "DSA", alg);
+    }
+
+    /**
+     * @tests java.security.KeyPairGenerator#getInstance(java.lang.String)
+     */
+    public void test_getInstanceLjava_lang_String() throws Exception {
+        KeyPairGenerator.getInstance("DSA");
+    }
+
+    /**
+     * @tests java.security.KeyPairGenerator#getInstance(java.lang.String,
+     *        java.lang.String)
+     */
+    public void test_getInstanceLjava_lang_StringLjava_lang_String()
+            throws Exception {
+
+        // Test1: Test with named provider
+        Provider[] providers = Security.getProviders("KeyPairGenerator.DSA");
+
+        for (int i = 0; i < providers.length; i++) {
+            KeyPairGenerator.getInstance("DSA", providers[i].getName());
+        }// end for
+
+        // Test2: Test with empty provider name - should raise
+        // IllegalArgumentException
+        try {
+            KeyPairGenerator.getInstance("DSA", "");
+            fail("Should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests java.security.KeyPairGenerator#getProvider()
+     */
+    public void test_getProvider() throws Exception {
+        Provider p = KeyPairGenerator.getInstance("DSA").getProvider();
+        assertNotNull("provider is null", p);
+    }
+
+    /**
+     * @tests java.security.KeyPairGenerator#initialize(int)
+     */
+    public void test_initializeI() throws Exception {
+        KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
+        keyPair.initialize(1024);
+    }
+
+    /**
+     * @tests java.security.KeyPairGenerator#initialize(int,
+     *        java.security.SecureRandom)
+     */
+    public void test_initializeILjava_security_SecureRandom() throws Exception {
+        KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
+        keyPair.initialize(1024, new SecureRandom());
+    }
+
+    /**
+     * @tests java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec)
+     */
+    public void test_initializeLjava_security_spec_AlgorithmParameterSpec()
+            throws Exception {
+        KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
+        keyPair.initialize(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
+                BigInteger.ONE));
+    }
+
+    /**
+     * @tests java.security.KeyPairGenerator#initialize(java.security.spec.AlgorithmParameterSpec,
+     *        java.security.SecureRandom)
+     */
+    public void test_initializeLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom()
+            throws Exception {
+        KeyPairGenerator keyPair = KeyPairGenerator.getInstance("DSA");
+        keyPair.initialize(new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE,
+                BigInteger.ONE), new SecureRandom());
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/SignatureTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/SignatureTest.java?rev=410852&r1=410851&r2=410852&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/SignatureTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/tests/api/java/security/SignatureTest.java
Thu Jun  1 05:10:39 2006
@@ -20,7 +20,6 @@
 import java.security.KeyPair;
 import java.security.KeyPairGenerator;
 import java.security.Provider;
-import java.security.SecureRandom;
 import java.security.Security;
 import java.security.Signature;
 import java.security.spec.DSAParameterSpec;
@@ -28,7 +27,17 @@
 public class SignatureTest extends junit.framework.TestCase {
 
 	private static final String MESSAGE = "abc";
-
+    static KeyPair keys;
+    static {
+        try {
+            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
+            keyGen.initialize(1024);
+            keys = keyGen.generateKeyPair();
+        } catch (Exception e) {
+            fail(e.toString());
+        }
+    }
+    
 	/**
 	 * @tests java.security.Signature#clone()
 	 */
@@ -95,30 +104,14 @@
 	 * @tests java.security.Signature#initSign(java.security.PrivateKey)
 	 */
 	public void test_initSignLjava_security_PrivateKey() throws Exception {
-
-		Signature sig = Signature.getInstance("DSA");
-
-		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
-
-		SecureRandom random = new SecureRandom();
-		keyGen.initialize(1024, random);
-		KeyPair keys = keyGen.generateKeyPair();
-
-		sig.initSign(keys.getPrivate());
+		Signature.getInstance("DSA").initSign(keys.getPrivate());
 	}
 
 	/**
 	 * @tests java.security.Signature#initVerify(java.security.PublicKey)
 	 */
 	public void test_initVerifyLjava_security_PublicKey() throws Exception {
-
-		Signature sig = Signature.getInstance("DSA");
-
-		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
-		SecureRandom random = new SecureRandom();
-		keyGen.initialize(1024, random);
-		KeyPair keys = keyGen.generateKeyPair();
-		sig.initVerify(keys.getPublic());
+		Signature.getInstance("DSA").initVerify(keys.getPublic());
 	}
 
 	/**
@@ -159,15 +152,7 @@
 	 * @tests java.security.Signature#sign()
 	 */
 	public void test_sign() throws Exception {
-
 		Signature sig = Signature.getInstance("DSA");
-
-		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
-
-		SecureRandom random = new SecureRandom();
-		keyGen.initialize(1024, random);
-		KeyPair keys = keyGen.generateKeyPair();
-
 		sig.initSign(keys.getPrivate());
 		sig.update(MESSAGE.getBytes());
 		sig.sign();
@@ -185,15 +170,7 @@
 	 * @tests java.security.Signature#update(byte[])
 	 */
 	public void test_update$B() throws Exception {
-
 		Signature sig = Signature.getInstance("DSA");
-
-		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
-
-		SecureRandom random = new SecureRandom();
-		keyGen.initialize(1024, random);
-		KeyPair keys = keyGen.generateKeyPair();
-
 		sig.initSign(keys.getPrivate());
 
 		byte[] bytes = MESSAGE.getBytes();
@@ -204,15 +181,7 @@
 	 * @tests java.security.Signature#update(byte[], int, int)
 	 */
 	public void test_update$BII() throws Exception {
-
 		Signature sig = Signature.getInstance("DSA");
-
-		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
-
-		SecureRandom random = new SecureRandom();
-		keyGen.initialize(1024, random);
-		KeyPair keys = keyGen.generateKeyPair();
-
 		sig.initSign(keys.getPrivate());
 
 		byte[] bytes = MESSAGE.getBytes();
@@ -223,15 +192,7 @@
 	 * @tests java.security.Signature#update(byte)
 	 */
 	public void test_updateB() throws Exception {
-
 		Signature sig = Signature.getInstance("DSA");
-
-		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
-
-		SecureRandom random = new SecureRandom();
-		keyGen.initialize(1024, random);
-		KeyPair keys = keyGen.generateKeyPair();
-
 		sig.initSign(keys.getPrivate());
 
 		sig.update(MESSAGE.getBytes()[0]);
@@ -241,15 +202,7 @@
 	 * @tests java.security.Signature#verify(byte[])
 	 */
 	public void test_verify$B() throws Exception {
-
 		Signature sig = Signature.getInstance("DSA");
-
-		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
-
-		SecureRandom random = new SecureRandom();
-		keyGen.initialize(1024, random);
-		KeyPair keys = keyGen.generateKeyPair();
-
 		sig.initSign(keys.getPrivate());
 		sig.update(MESSAGE.getBytes());
 		byte[] signature = sig.sign();
@@ -259,4 +212,4 @@
 		sig.update(MESSAGE.getBytes());
 		assertTrue("Sign/Verify does not pass", sig.verify(signature));
 	}
-}
\ No newline at end of file
+}



Mime
View raw message