harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r413841 [6/9] - in /incubator/harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/java/security/ test/api/java.injected/java/security/ test/api/java/org/apache/harmony/security/tests/java/security/ test/impl/java.injected...
Date Tue, 13 Jun 2006 08:58:17 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java.injected/java/security/cert/X509CertificateTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java.injected/java/security/cert/X509CertificateTest.java?rev=413841&r1=413840&r2=413841&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java.injected/java/security/cert/X509CertificateTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java.injected/java/security/cert/X509CertificateTest.java Tue Jun 13 01:58:11 2006
@@ -1,284 +1,284 @@
-/*
- *  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 Alexander Y. Kleymenov
-* @version $Revision$
-*/
-
-package java.security.cert;
-
-import java.io.ByteArrayInputStream;
-import java.math.BigInteger;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.Principal;
-import java.security.PublicKey;
-import java.security.SignatureException;
-import java.util.Date;
-import java.util.Set;
-
-import javax.security.auth.x500.X500Principal;
-
-import org.apache.harmony.luni.util.Base64;
-import org.apache.harmony.security.tests.support.cert.TestUtils;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * X509CertificateTest
- */
-public class X509CertificateTest extends TestCase {
-
-    // Base64 encoded form of ASN.1 DER encoded X.509 Certificate
-    // (see RFC 3280 at http://www.ietf.org/rfc/rfc3280.txt)
-    // (generated by using of classes from 
-    // org.apache.harmony.security.x509 package)
-    static String base64cert =
-          "MIIByzCCATagAwIBAgICAiswCwYJKoZIhvcNAQEFMB0xGzAZBgNVBAoT"
-        + "EkNlcnRpZmljYXRlIElzc3VlcjAeFw0wNjA0MjYwNjI4MjJaFw0zMzAz"
-        + "MDExNjQ0MDlaMB0xGzAZBgNVBAoTEkNlcnRpZmljYXRlIElzc3VlcjCB"
-        + "nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAkLGLsPdSPDMyP1OUOKu+"
-        + "U3cvbNK5RGaQ3bXc5aDjvApx43BcaoXgt6YD/5yXz0OsIooj5yA37+bY"
-        + "JGcVrvFD5FMPdDd3vjNPQOep0MzG4CdbkaZde5SigPabOMQYS4oUyLBx"
-        + "W3LGG0mUODe5AGGqtqXU0GlKg4K2je6cCtookCUCAwEAAaMeMBwwGgYD"
-        + "VR0RAQH/BBAwDoEMcmZjQDgyMi5OYW1lMAsGCSqGSIb3DQEBBQOBgQBZ"
-        + "pVXj01dOpqnZErU+Qb50j8lJD1dIaz1eJTvJCSadj7ziV1VtnnapI07c"
-        + "XEa7ONzcHQTYTG10poHfOK/a0BaULF3GlctDESilwQYbW5BdfpAlZpbH"
-        + "AFLcUDh6Eq50kc+0A/anh/j3mgBNuvbIMo7hHNnZB6k/prswm2BszyLD"
-        + "yw==";
-
-    // Base64 encoded form of ASN.1 DER encoded X.509 CRL
-    // (see RFC 3280 at http://www.ietf.org/rfc/rfc3280.txt)
-    // (generated by using of classes from 
-    // org.apache.harmony.security.x509 package)
-    static String base64crl = 
-          "MIHXMIGXAgEBMAkGByqGSM44BAMwFTETMBEGA1UEChMKQ1JMIElzc3Vl"
-        + "chcNMDYwNDI3MDYxMzQ1WhcNMDYwNDI3MDYxNTI1WjBBMD8CAgIrFw0w"
-        + "NjA0MjcwNjEzNDZaMCowCgYDVR0VBAMKAQEwHAYDVR0YBBUYEzIwMDYw"
-        + "NDI3MDYxMzQ1LjQ2OFqgDzANMAsGA1UdFAQEBAQEBDAJBgcqhkjOOAQD"
-        + "AzAAMC0CFQCk0t0DTyu82QpajbBlxX9uXvUDSgIUSBN4g+xTEeexs/0k"
-        + "9AkjBhjF0Es=";
-
-    // has stub implementation for abstract methods
-    private static class MyX509Certificate extends X509Certificate {
-
-            public void checkValidity()
-                    throws CertificateExpiredException,
-                           CertificateNotYetValidException {}
-
-            public void checkValidity(Date date)
-                    throws CertificateExpiredException,
-                           CertificateNotYetValidException {}
-
-            public int getVersion() {
-                return 3;
-            }
-
-            public BigInteger getSerialNumber() {
-                return null;
-            }
-
-            public Principal getIssuerDN() {
-                return null;
-            }
-
-            public Principal getSubjectDN() {
-                return null;
-            }
-
-            public Date getNotBefore() {
-                return null;
-            }
-
-            public Date getNotAfter() {
-                return null;
-            }
-
-            public byte[] getTBSCertificate()
-                                throws CertificateEncodingException
-            {
-                return null;
-            }
-
-            public byte[] getSignature() {
-                return null;
-            }
-
-            public String getSigAlgName() {
-                return null;
-            }
-
-            public String getSigAlgOID() {
-                return null;
-            }
-
-            public byte[] getSigAlgParams() {
-                return null;
-            }
-
-            public boolean[] getIssuerUniqueID() {
-                return null;
-            }
-
-            public boolean[] getSubjectUniqueID() {
-                return null;
-            }
-
-            public boolean[] getKeyUsage() {
-                return null;
-            }
-
-            public int getBasicConstraints() {
-                return 0;
-            }
-
-            public void verify(PublicKey key)
-                         throws CertificateException, NoSuchAlgorithmException,
-                                InvalidKeyException, NoSuchProviderException,
-                                SignatureException
-            {
-            }
-
-            public void verify(PublicKey key,
-                                        String sigProvider)
-                         throws CertificateException, NoSuchAlgorithmException,
-                                InvalidKeyException, NoSuchProviderException,
-                                SignatureException
-            {
-            }
-
-            public String toString() {
-                return "";
-            }
-
-            public PublicKey getPublicKey() {
-                return null;
-            }
-
-            public byte[] getEncoded() throws CertificateEncodingException
-            {
-                return null;
-            }
-
-            public Set getNonCriticalExtensionOIDs() {
-                return null;
-            }
-
-            public Set getCriticalExtensionOIDs() {
-                return null;
-            }
-
-            public byte[] getExtensionValue(String oid) {
-                return null;
-            }
-
-            public boolean hasUnsupportedCriticalExtension() {
-                return false;
-            }
-    }
-
-    /**
-     * @tests java.security.cert.X509Certificate#getType()
-     */
-    public void testGetType() {
-        assertEquals("X.509", new MyX509Certificate().getType());
-    }
-
-    /**
-     * @tests java.security.cert.X509Certificate#getIssuerX500Principal()
-     */
-    public void testGetIssuerX500Principal() {
-        // return valid encoding
-        MyX509Certificate cert = new MyX509Certificate() {
-            public byte[] getEncoded() {
-                return TestUtils.getX509Certificate_v1();
-            };
-        };
-
-        assertEquals(new X500Principal("CN=Z"), cert.getIssuerX500Principal());
-    }
-
-    /**
-     * @tests java.security.cert.X509Certificate#getSubjectX500Principal()
-     */
-    public void testGetSubjectX500Principal() {
-        // return valid encoding
-        MyX509Certificate cert = new MyX509Certificate() {
-            public byte[] getEncoded() {
-                return TestUtils.getX509Certificate_v1();
-            };
-        };
-
-        assertEquals(new X500Principal("CN=Y"), cert.getSubjectX500Principal());
-    }
-
-    /**
-     * @tests java.security.cert.X509Certificate#getExtendedKeyUsage()
-     */
-    public void testGetExtendedKeyUsage() throws CertificateParsingException {
-        assertNull(new MyX509Certificate().getExtendedKeyUsage());
-    }
-
-    /**
-     * @tests java.security.cert.X509Certificate#getSubjectAlternativeNames()
-     */
-    public void testGetSubjectAlternativeNames()
-            throws CertificateParsingException {
-
-        assertNull(new MyX509Certificate().getSubjectAlternativeNames());
-    }
-
-    /**
-     * @tests java.security.cert.X509Certificate#getIssuerAlternativeNames()
-     */
-    public void testGetIssuerAlternativeNames()
-            throws CertificateParsingException {
-
-        assertNull(new MyX509Certificate().getIssuerAlternativeNames());
-    }
-
-    /**
-     * @tests java.security.cert.X509Certificate#getExtensionValue()
-     */
-    public void testGetExtensionValue() throws Exception {
-        // Regression for HARMONY-419
-        ByteArrayInputStream is = null;
-        CertificateFactory certFactory = CertificateFactory
-                .getInstance("X.509");
-        is = new ByteArrayInputStream(Base64.decode(base64cert.getBytes()));
-        X509Certificate cert = (X509Certificate) certFactory
-                .generateCertificate(is);
-        cert.getExtensionValue("1.1.1.1");
-
-        is = new ByteArrayInputStream(Base64.decode(base64crl.getBytes()));
-        X509CRL crl = (X509CRL) certFactory.generateCRL(is);
-        crl.getExtensionValue("1.1.1.1");
-    }
-    
-    
-    public static Test suite() {
-        return new TestSuite(X509CertificateTest.class);
-    }
-
-    public static void main(String[] args) {
-        junit.textui.TestRunner.run(suite());
-    }
-}
-
+/*
+ *  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 Alexander Y. Kleymenov
+* @version $Revision$
+*/
+
+package java.security.cert;
+
+import java.io.ByteArrayInputStream;
+import java.math.BigInteger;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Principal;
+import java.security.PublicKey;
+import java.security.SignatureException;
+import java.util.Date;
+import java.util.Set;
+
+import javax.security.auth.x500.X500Principal;
+
+import org.apache.harmony.luni.util.Base64;
+import org.apache.harmony.security.tests.support.cert.TestUtils;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * X509CertificateTest
+ */
+public class X509CertificateTest extends TestCase {
+
+    // Base64 encoded form of ASN.1 DER encoded X.509 Certificate
+    // (see RFC 3280 at http://www.ietf.org/rfc/rfc3280.txt)
+    // (generated by using of classes from 
+    // org.apache.harmony.security.x509 package)
+    static String base64cert =
+          "MIIByzCCATagAwIBAgICAiswCwYJKoZIhvcNAQEFMB0xGzAZBgNVBAoT"
+        + "EkNlcnRpZmljYXRlIElzc3VlcjAeFw0wNjA0MjYwNjI4MjJaFw0zMzAz"
+        + "MDExNjQ0MDlaMB0xGzAZBgNVBAoTEkNlcnRpZmljYXRlIElzc3VlcjCB"
+        + "nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAkLGLsPdSPDMyP1OUOKu+"
+        + "U3cvbNK5RGaQ3bXc5aDjvApx43BcaoXgt6YD/5yXz0OsIooj5yA37+bY"
+        + "JGcVrvFD5FMPdDd3vjNPQOep0MzG4CdbkaZde5SigPabOMQYS4oUyLBx"
+        + "W3LGG0mUODe5AGGqtqXU0GlKg4K2je6cCtookCUCAwEAAaMeMBwwGgYD"
+        + "VR0RAQH/BBAwDoEMcmZjQDgyMi5OYW1lMAsGCSqGSIb3DQEBBQOBgQBZ"
+        + "pVXj01dOpqnZErU+Qb50j8lJD1dIaz1eJTvJCSadj7ziV1VtnnapI07c"
+        + "XEa7ONzcHQTYTG10poHfOK/a0BaULF3GlctDESilwQYbW5BdfpAlZpbH"
+        + "AFLcUDh6Eq50kc+0A/anh/j3mgBNuvbIMo7hHNnZB6k/prswm2BszyLD"
+        + "yw==";
+
+    // Base64 encoded form of ASN.1 DER encoded X.509 CRL
+    // (see RFC 3280 at http://www.ietf.org/rfc/rfc3280.txt)
+    // (generated by using of classes from 
+    // org.apache.harmony.security.x509 package)
+    static String base64crl = 
+          "MIHXMIGXAgEBMAkGByqGSM44BAMwFTETMBEGA1UEChMKQ1JMIElzc3Vl"
+        + "chcNMDYwNDI3MDYxMzQ1WhcNMDYwNDI3MDYxNTI1WjBBMD8CAgIrFw0w"
+        + "NjA0MjcwNjEzNDZaMCowCgYDVR0VBAMKAQEwHAYDVR0YBBUYEzIwMDYw"
+        + "NDI3MDYxMzQ1LjQ2OFqgDzANMAsGA1UdFAQEBAQEBDAJBgcqhkjOOAQD"
+        + "AzAAMC0CFQCk0t0DTyu82QpajbBlxX9uXvUDSgIUSBN4g+xTEeexs/0k"
+        + "9AkjBhjF0Es=";
+
+    // has stub implementation for abstract methods
+    private static class MyX509Certificate extends X509Certificate {
+
+            public void checkValidity()
+                    throws CertificateExpiredException,
+                           CertificateNotYetValidException {}
+
+            public void checkValidity(Date date)
+                    throws CertificateExpiredException,
+                           CertificateNotYetValidException {}
+
+            public int getVersion() {
+                return 3;
+            }
+
+            public BigInteger getSerialNumber() {
+                return null;
+            }
+
+            public Principal getIssuerDN() {
+                return null;
+            }
+
+            public Principal getSubjectDN() {
+                return null;
+            }
+
+            public Date getNotBefore() {
+                return null;
+            }
+
+            public Date getNotAfter() {
+                return null;
+            }
+
+            public byte[] getTBSCertificate()
+                                throws CertificateEncodingException
+            {
+                return null;
+            }
+
+            public byte[] getSignature() {
+                return null;
+            }
+
+            public String getSigAlgName() {
+                return null;
+            }
+
+            public String getSigAlgOID() {
+                return null;
+            }
+
+            public byte[] getSigAlgParams() {
+                return null;
+            }
+
+            public boolean[] getIssuerUniqueID() {
+                return null;
+            }
+
+            public boolean[] getSubjectUniqueID() {
+                return null;
+            }
+
+            public boolean[] getKeyUsage() {
+                return null;
+            }
+
+            public int getBasicConstraints() {
+                return 0;
+            }
+
+            public void verify(PublicKey key)
+                         throws CertificateException, NoSuchAlgorithmException,
+                                InvalidKeyException, NoSuchProviderException,
+                                SignatureException
+            {
+            }
+
+            public void verify(PublicKey key,
+                                        String sigProvider)
+                         throws CertificateException, NoSuchAlgorithmException,
+                                InvalidKeyException, NoSuchProviderException,
+                                SignatureException
+            {
+            }
+
+            public String toString() {
+                return "";
+            }
+
+            public PublicKey getPublicKey() {
+                return null;
+            }
+
+            public byte[] getEncoded() throws CertificateEncodingException
+            {
+                return null;
+            }
+
+            public Set getNonCriticalExtensionOIDs() {
+                return null;
+            }
+
+            public Set getCriticalExtensionOIDs() {
+                return null;
+            }
+
+            public byte[] getExtensionValue(String oid) {
+                return null;
+            }
+
+            public boolean hasUnsupportedCriticalExtension() {
+                return false;
+            }
+    }
+
+    /**
+     * @tests java.security.cert.X509Certificate#getType()
+     */
+    public void testGetType() {
+        assertEquals("X.509", new MyX509Certificate().getType());
+    }
+
+    /**
+     * @tests java.security.cert.X509Certificate#getIssuerX500Principal()
+     */
+    public void testGetIssuerX500Principal() {
+        // return valid encoding
+        MyX509Certificate cert = new MyX509Certificate() {
+            public byte[] getEncoded() {
+                return TestUtils.getX509Certificate_v1();
+            };
+        };
+
+        assertEquals(new X500Principal("CN=Z"), cert.getIssuerX500Principal());
+    }
+
+    /**
+     * @tests java.security.cert.X509Certificate#getSubjectX500Principal()
+     */
+    public void testGetSubjectX500Principal() {
+        // return valid encoding
+        MyX509Certificate cert = new MyX509Certificate() {
+            public byte[] getEncoded() {
+                return TestUtils.getX509Certificate_v1();
+            };
+        };
+
+        assertEquals(new X500Principal("CN=Y"), cert.getSubjectX500Principal());
+    }
+
+    /**
+     * @tests java.security.cert.X509Certificate#getExtendedKeyUsage()
+     */
+    public void testGetExtendedKeyUsage() throws CertificateParsingException {
+        assertNull(new MyX509Certificate().getExtendedKeyUsage());
+    }
+
+    /**
+     * @tests java.security.cert.X509Certificate#getSubjectAlternativeNames()
+     */
+    public void testGetSubjectAlternativeNames()
+            throws CertificateParsingException {
+
+        assertNull(new MyX509Certificate().getSubjectAlternativeNames());
+    }
+
+    /**
+     * @tests java.security.cert.X509Certificate#getIssuerAlternativeNames()
+     */
+    public void testGetIssuerAlternativeNames()
+            throws CertificateParsingException {
+
+        assertNull(new MyX509Certificate().getIssuerAlternativeNames());
+    }
+
+    /**
+     * @tests java.security.cert.X509Certificate#getExtensionValue()
+     */
+    public void testGetExtensionValue() throws Exception {
+        // Regression for HARMONY-419
+        ByteArrayInputStream is = null;
+        CertificateFactory certFactory = CertificateFactory
+                .getInstance("X.509");
+        is = new ByteArrayInputStream(Base64.decode(base64cert.getBytes()));
+        X509Certificate cert = (X509Certificate) certFactory
+                .generateCertificate(is);
+        cert.getExtensionValue("1.1.1.1");
+
+        is = new ByteArrayInputStream(Base64.decode(base64crl.getBytes()));
+        X509CRL crl = (X509CRL) certFactory.generateCRL(is);
+        crl.getExtensionValue("1.1.1.1");
+    }
+    
+    
+    public static Test suite() {
+        return new TestSuite(X509CertificateTest.class);
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(suite());
+    }
+}
+

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator_ImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator_ImplTest.java?rev=413841&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator_ImplTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/AlgorithmParameterGenerator_ImplTest.java Tue Jun 13 01:58:11 2006
@@ -0,0 +1,100 @@
+/*
+ *  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.security.tests.java.security;
+
+import java.security.AlgorithmParameterGenerator;
+import java.security.Provider;
+import java.security.SecureRandom;
+
+import org.apache.harmony.security.tests.support.SpiEngUtils;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>AlgorithmParameterGenerator</code> class constructors and
+ * methods.
+ * 
+ */
+
+public class AlgorithmParameterGenerator_ImplTest extends TestCase {
+
+    private static String validAlgName = "DSA";
+            
+    public static final String srvAlgorithmParameterGenerator = "AlgorithmParameterGenerator";
+
+
+    private static String validProviderName = null;
+
+    private static Provider validProvider = null;
+
+    private static boolean DSASupported = false;
+
+    static {
+        validProvider = SpiEngUtils.isSupport(
+                validAlgName,
+                srvAlgorithmParameterGenerator);
+        DSASupported = (validProvider != null);
+        validProviderName = (DSASupported ? validProvider.getName() : null);
+    }
+
+    protected AlgorithmParameterGenerator[] createAPGen() throws Exception {
+        if (!DSASupported) {
+            fail(validAlgName + " algorithm is not supported");
+            return null;
+        }
+        AlgorithmParameterGenerator[] apg = new AlgorithmParameterGenerator[3];
+        apg[0] = AlgorithmParameterGenerator.getInstance(validAlgName);
+        apg[1] = AlgorithmParameterGenerator.getInstance(validAlgName,
+                validProvider);
+        apg[2] = AlgorithmParameterGenerator.getInstance(validAlgName,
+                validProviderName);
+        return apg;
+    }
+
+    /**
+     * Test for <code>init(int size)</code> and
+     * <code>init(int size, SecureRandom random<code> methods
+     * Assertion: throws InvalidParameterExceptiom when size is incorrect
+     */
+    public void testAlgorithmParameterGenerator11() throws Exception {        
+        if (!DSASupported) {
+            fail(validAlgName + " algorithm is not supported");
+            return;
+        }
+        int [] keys = {-10000, -512, -1, 0, 10000};
+        SecureRandom random = new SecureRandom();
+        AlgorithmParameterGenerator[] apgs = createAPGen();
+        assertNotNull("AlgorithmParameterGenerator objects were not created",
+                apgs);
+
+        for (int i = 0; i < apgs.length; i++) {
+            for (int j = 0; j < keys.length; j++) {
+                apgs[i].init(keys[j]);
+                apgs[i].init(keys[j], random);
+                apgs[i].init(keys[j], null);
+            }
+            apgs[i].init(1024);
+            apgs[i].init(1024, random);
+        }
+    }
+    
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSigner_ImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSigner_ImplTest.java?rev=413841&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSigner_ImplTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSigner_ImplTest.java Tue Jun 13 01:58:11 2006
@@ -0,0 +1,52 @@
+/*
+ *  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 Alexander V. Astapchuk
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.security.CodeSigner;
+import java.security.Timestamp;
+import java.security.cert.CertPath;
+import java.util.Date;
+
+import org.apache.harmony.security.tests.support.TestCertUtils;
+import junit.framework.TestCase;
+
+/**
+ * Unit test for CodeSigner. 
+ */
+
+public class CodeSigner_ImplTest extends TestCase {
+
+    private CertPath cpath = TestCertUtils.genCertPath(3, 0);
+    private Date now = new Date();
+
+    private Timestamp ts = new Timestamp(now, cpath);
+
+    /**
+     * Tests CodeSigner.hashCode()
+     */
+    public void testHashCode() {
+        assertTrue(new CodeSigner(cpath, ts).hashCode() == (cpath.hashCode() ^ ts
+                .hashCode()));
+        assertTrue(new CodeSigner(cpath, null).hashCode() == cpath.hashCode());
+    }
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java?rev=413841&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java Tue Jun 13 01:58:11 2006
@@ -0,0 +1,210 @@
+/*
+ *  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 Alexander V. Astapchuk
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.CodeSigner;
+import java.security.CodeSource;
+import java.security.Provider;
+import java.security.Security;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+
+import javax.security.auth.x500.X500Principal;
+
+import org.apache.harmony.security.tests.support.TestCertUtils;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit test for CodeSource.
+ * 
+ */
+
+public class CodeSource_ImplTest extends TestCase {
+
+    /* Below are various URLs used during the testing */
+    private static URL urlSite;
+
+    static {
+        try {
+            String siteName = "www.intel.com";
+            urlSite = new URL("http://"+siteName+"");
+        } catch (MalformedURLException ex) {
+            throw new Error(ex);
+        }
+    }
+
+    /**
+     * Test for equals(Object)<br>
+     * The signer certificate may contain nulls, and equals() must not fail with NPE 
+     */
+    public void testEqualsObject_03() {
+        Certificate cert0 = new TestCertUtils.TestCertificate();
+        Certificate[] certs0 = new Certificate[] { cert0, null };
+        Certificate[] certs1 = new Certificate[] { null, cert0 };
+        CodeSource thiz = new CodeSource(urlSite, certs0);
+        CodeSource that = new CodeSource(urlSite, certs1);
+        assertTrue(thiz.equals(that));
+    }
+
+    /**
+     * Test for equals(Object)<br>
+     * Checks that both 'null' and not-null certs are taken into account - properly. 
+     */
+    public void testEqualsObject_05() {
+        Certificate cert0 = new TestCertUtils.TestCertificate("cert0");
+        Certificate cert1 = new TestCertUtils.TestCertificate("cert1");
+        Certificate cert2 = new TestCertUtils.TestCertificate("cert2");
+
+        Certificate[] smallSet = new Certificate[] { cert0, cert1 };
+        Certificate[] bigSet = new Certificate[] { cert0, cert1, cert2 };
+
+        CodeSource thiz = new CodeSource(urlSite, smallSet);
+        CodeSource that = new CodeSource(urlSite, (Certificate[]) null);
+        assertFalse(thiz.equals(that));
+
+        that = new CodeSource(urlSite, bigSet);
+        assertFalse(thiz.equals(that));
+
+        thiz = new CodeSource(urlSite, bigSet);
+        that = new CodeSource(urlSite, smallSet);
+        assertFalse(thiz.equals(that));
+
+        thiz = new CodeSource(urlSite, (Certificate[]) null);
+        that = new CodeSource(urlSite, /*any set*/smallSet);
+        assertFalse(thiz.equals(that));
+        assertFalse(that.equals(thiz));
+    }
+
+    /**
+     * getCodeSigners() must not take into account non-X509 certificates.
+     */
+    public void testGetCodeSigners_01() {
+        Certificate[] certs = { new TestCertUtils.TestCertificate("00") };
+        CodeSource cs = new CodeSource(null, certs);
+        assertNull(cs.getCodeSigners());
+    }
+
+    /**
+     * getCodeSigners() must return null if no X509 factory available
+     */
+    public void testGetCodeSigners_02() {
+        ArrayList al = new ArrayList();
+        boolean noMoreFactories = false;
+        try {
+            // remove all providers for x509
+            // 'for' loop here for the sake of avoding endless loop - well, just 
+            // in case if something is wrong with add/remove machinery.
+            // '100' seems reasonable big to remove all necessary providers
+            // ...
+            for (int i = 0; i < 100; i++) {
+                try {
+                    CertificateFactory f = CertificateFactory
+                            .getInstance("X.509");
+                    al.add(f.getProvider());
+                    Security.removeProvider(f.getProvider().getName());
+                } catch (CertificateException ex) {
+                    noMoreFactories = true;
+                    break;
+                }
+            }
+            if (!noMoreFactories) {
+                throw new Error(
+                        "Unable to setup test: too many providers provide X.509");
+            }
+            Certificate[] certs = new Certificate[] { TestCertUtils.rootCA };
+            CodeSource cs = new CodeSource(null, certs);
+            assertNull(cs.getCodeSigners());
+        } finally {
+            // .. and restore providers back - to avoid affecting following tests
+            for (int i = 0; i < al.size(); i++) {
+                Security.addProvider((Provider) al.get(i));
+            }
+        }
+
+    }
+
+    /**
+     * getCodeSigners() must return an array of CodeSigners. Just make sure
+     * the array looks healthy.
+     */
+    public void testGetCodeSigners_03() {
+        TestCertUtils.install_test_x509_factory();
+        try {
+            X500Principal[] ps = TestCertUtils.UniGen.genX500s(3);
+
+            // 2-certs chain 
+            X509Certificate rootCA = TestCertUtils.rootCA;
+            X509Certificate c0 = new TestCertUtils.TestX509Certificate(ps[0],
+                    rootCA.getIssuerX500Principal());
+            //
+            X509Certificate c1 = new TestCertUtils.TestX509Certificate(ps[1],
+                    ps[1]);
+            X509Certificate c2 = new TestCertUtils.TestX509Certificate(ps[2],
+                    ps[2]);
+
+            java.security.cert.Certificate [] certs = new java.security.cert.Certificate[] {
+                    c0, rootCA, c1, c2 };
+            CodeSource cs = new CodeSource(null, certs);
+            CodeSigner[] signers = cs.getCodeSigners();
+
+            // must get exactly 3 CodeSigner-s: one for the chain, and one 
+            // for each of single certs
+            assertEquals(3, signers.length);
+        } finally {
+            TestCertUtils.uninstall_test_x509_factory();
+        }
+    }
+
+    /**
+     * getCodeSigners(). Make sure, that CertException is handled properly
+     */
+    public void testGetCodeSigners_04() {
+        try {
+            TestCertUtils.install_test_x509_factory();
+            X500Principal[] ps = TestCertUtils.UniGen.genX500s(1);
+
+            // 2-certs chain 
+            X509Certificate rootCA = TestCertUtils.rootCA;
+            X509Certificate c0 = new TestCertUtils.TestInvalidX509Certificate(
+                    ps[0], rootCA.getIssuerX500Principal());
+            java.security.cert.Certificate [] certs = new java.security.cert.Certificate[] {
+                    c0, rootCA };
+
+            CodeSource cs = new CodeSource(null, certs);
+            CodeSigner[] signers = cs.getCodeSigners();
+
+            assertNull(signers);
+
+            // Must force a check for 'factory==null' 
+            cs.getCodeSigners();
+        } finally {
+            TestCertUtils.uninstall_test_x509_factory();
+        }
+    }
+
+}

Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KSBuilder_ImplTest.java (from r412639, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KSBuilderTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KSBuilder_ImplTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KSBuilder_ImplTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KSBuilderTest.java&r1=412639&r2=413841&rev=413841&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KSBuilderTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KSBuilder_ImplTest.java Tue Jun 13 01:58:11 2006
@@ -19,48 +19,50 @@
 * @version $Revision$
 */
 
-package java.security;
-
+package org.apache.harmony.security.tests.java.security;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.security.InvalidKeyException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.PrivateKey;
+import java.security.Provider;
+import java.security.PublicKey;
+import java.security.SignatureException;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateEncodingException;
 import java.security.cert.CertificateException;
 import java.security.spec.InvalidKeySpecException;
-
 import java.util.Enumeration;
 
-import junit.framework.TestCase;
-
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport;
 import org.apache.harmony.security.tests.support.SpiEngUtils;
 import org.apache.harmony.security.tests.support.TestKeyPair;
 import org.apache.harmony.security.tests.support.TestUtils;
+import org.apache.harmony.security.tests.support.tmpCallbackHandler;
+
+import junit.framework.TestCase;
 
 /**
  * Tests for <code>KeyStore.Builder</code> class
  * 
  */
 
-public class KSBuilderTest extends TestCase {
-    /**
-     * Constructor for KSBuilderTest
-     * 
-     * @param arg
-     */
-    public KSBuilderTest(String arg) {
-        super(arg);
-    }
+public class KSBuilder_ImplTest extends TestCase {
+
     private static char[] pass =  {'s','t','o','r','e','p','w','d'};
     
     private KeyStore.PasswordProtection protPass = new KeyStore.PasswordProtection(pass);
     private tmpCallbackHandler tmpCall = new tmpCallbackHandler();
     private KeyStore.CallbackHandlerProtection callbackHand = new KeyStore.CallbackHandlerProtection(tmpCall);
     private myProtectionParameter myProtParam = new myProtectionParameter(new byte[5]);  
-    public static String[] validValues = KeyStore1Test.validValues;
+    public static String[] validValues = KeyStoreTestSupport.validValues;
 
-    private static String defaultType = KeyStore1Test.defaultType;
+    private static String defaultType = KeyStoreTestSupport.defaultType;
 
     private static boolean JKSSupported = false;
 
@@ -72,7 +74,7 @@
     
     static {
         defaultProvider = SpiEngUtils.isSupport(
-                KeyStore1Test.defaultType, KeyStore1Test.srvKeyStore);
+                KeyStoreTestSupport.defaultType, KeyStoreTestSupport.srvKeyStore);
         JKSSupported = (defaultProvider != null);
         fileEmpty = SpiEngUtils.getFileName(TestUtils.TEST_ROOT,
                 fileEmpty);
@@ -83,7 +85,7 @@
 
     private boolean isCreateKS;
     // Creates empty KeyStoreand loads it to file    
-    private void createKS() {
+    private void createKS()throws Exception {
         isCreateKS = false;
         FileOutputStream fos = null;
         try {
@@ -100,8 +102,6 @@
             ks.load(null, null);
             ks.store(fos, pass);
             isCreateKS = true;
-        } catch (Exception e) {
-            e.printStackTrace(System.out);
         } finally {
             if (fos != null) {
                 try {
@@ -129,8 +129,6 @@
         deleteKS();
     }
 
-    
-
     /*
      * Test for method:
      * <code>newInstance(KeyStore keyStore, ProtectionParameter protectionParameter)</code>
@@ -269,8 +267,7 @@
      * 
      */
     public void testNewInstanceStringProviderFileProtectionParameter()
-            throws KeyStoreException, NoSuchAlgorithmException, IOException,
-            CertificateException {
+            throws Exception {
         if (!JKSSupported) {
             fail(defaultType + " type is not supported");
             return;
@@ -397,13 +394,8 @@
             iter = ks1.aliases();
             while (iter.hasMoreElements()) {
                 aName = (String) iter.nextElement();
-                try {
-                    assertEquals("Incorrect ProtectionParameter", ksB1
-                            .getProtectionParameter(aName), pp[i]);
-                } catch (Exception e) {
-                    fail("Unexpected: " + e.toString()
-                            + " was thrown for alias: " + aName);
-                }
+                assertEquals("Incorrect ProtectionParameter", ksB1
+                        .getProtectionParameter(aName), pp[i]);
             }
 
             try {
@@ -534,10 +526,7 @@
             }
         }
     }
-    
-    public static void main(String args[]) {
-        junit.textui.TestRunner.run(KSBuilderTest.class);    
-    }
+
     /**
      * Additional class for creation Certificate object 
      */

Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl1Test.java (from r412639, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KeyStore1Test.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl1Test.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl1Test.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KeyStore1Test.java&r1=412639&r2=413841&rev=413841&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KeyStore1Test.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl1Test.java Tue Jun 13 01:58:11 2006
@@ -19,18 +19,22 @@
 * @version $Revision$
 */
 
-package java.security;
+package org.apache.harmony.security.tests.java.security;
 
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.KeyStoreSpi;
+import java.security.NoSuchProviderException;
+import java.security.PrivateKey;
+import java.security.Provider;
+import java.security.UnrecoverableEntryException;
+import java.security.UnrecoverableKeyException;
 import java.security.cert.Certificate;
-import java.security.cert.CertificateEncodingException;
-import java.security.cert.CertificateException;
-import java.security.spec.InvalidKeySpecException;
-
-import javax.crypto.SecretKey;
-import javax.security.auth.DestroyFailedException;
+import java.util.Arrays;
 
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport;
 import org.apache.harmony.security.tests.support.MyKeyStoreSpi;
 import org.apache.harmony.security.tests.support.MyLoadStoreParams;
 import org.apache.harmony.security.tests.support.SpiEngUtils;
@@ -43,107 +47,31 @@
  * 
  */
 
-public class KeyStore1Test extends TestCase {
+public class KeyStore_Impl1Test extends TestCase {
     
-    public static final String srvKeyStore = "KeyStore";
-    public static String[] validValues =  {
-            "bks", "BKS", "bKS", "Bks", "bKs", "BkS"
-    };
+    public static final String srvKeyStore = KeyStoreTestSupport.srvKeyStore;
+    public static String[] validValues =  KeyStoreTestSupport.validValues;
+
     private static final String[] aliases = { "", "alias", "Alias", "ALIAS",
             "new alias", "another alias", "ADDITIONAL", "THE SAME ALIAS" };
 
-
     private static String[] invalidValues =  SpiEngUtils.invalidValues;
-    public static String defaultType = "bks";
 
-    public static boolean JKSSupported = false;
-
-    public static String defaultProviderName = null;
-
-    public static Provider defaultProvider = null;
-        
-    private static String NotSupportMsg = "";
-
-    static {
-        defaultProvider = SpiEngUtils.isSupport(
-                defaultType, srvKeyStore);
-        JKSSupported = (defaultProvider != null);
-        defaultProviderName = (JKSSupported ? defaultProvider.getName() : null);
-        NotSupportMsg = defaultType.concat(" type does not supported");
-    }
-
-    /**
-     * Constructor for KeyStoreTest.
-     * 
-     * @param arg0
-     */
-    public KeyStore1Test(String arg0) {
-        super(arg0);
-    }
-    
-    public KeyStore [] createKS() {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return null;
-        }
+    public static String defaultType = KeyStoreTestSupport.defaultType;
+    public static boolean JKSSupported = KeyStoreTestSupport.JKSSupported;
+    public static String defaultProviderName = KeyStoreTestSupport.defaultProviderName;
+    public static Provider defaultProvider = KeyStoreTestSupport.defaultProvider;
+       
+    private static String NotSupportMsg = "Default KeyStore type is not supported";
+       
+    public KeyStore[] createKS() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
         KeyStore[] kpg = new KeyStore[3];
-        try {
-            kpg[0] = KeyStore.getInstance(defaultType);
-            kpg[1] = KeyStore.getInstance(defaultType, defaultProvider);
-            kpg[2] = KeyStore.getInstance(defaultType, defaultProviderName);
-            return kpg;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
 
-    /**
-     * Test for <code>getDefaultType()</code> method Assertion: returns
-     * default security key store type or "jks" string
-     */
-    public void testKeyStore01() {
-        String propName = "keystore.type";
-        String defKSType = Security.getProperty(propName);
-        String dType = KeyStore.getDefaultType();
-        String resType = defKSType;
-        if (resType == null) {
-            resType = defaultType;
-        }
-        assertNotNull("Default type have not be null", dType);
-        assertEquals("Incorrect default type", dType, resType);
-        
-        if (defKSType == null) {
-            Security.setProperty(propName, defaultType);
-            dType = KeyStore.getDefaultType();
-            resType = Security.getProperty(propName);
-            assertNotNull("Incorrect default type", resType);
-            assertNotNull("Default type have not be null", dType);
-            assertEquals("Incorrect default type", dType, resType);
-        }
-    }
-
-    /**
-     * Test for <code>getInstance(String type)</code> method 
-     * Assertion: 
-     * throws NullPointerException when type is null 
-     * throws KeyStoreException when type is not available
-     * 
-     */
-    public void testKeyStore02() throws KeyStoreException {
-        try {
-            KeyStore.getInstance(null);
-          fail("NullPointerException or must be thrown when type is null");
-          } catch (NullPointerException e) {
-          }
-        for (int i = 0; i < invalidValues.length; i++) {
-            try {
-                KeyStore.getInstance(invalidValues[i]);
-                fail("KeyStoreException must be thrown (type: ".concat(
-                        invalidValues[i]).concat(" )"));
-            } catch (KeyStoreException e) {
-            }
-        }
+        kpg[0] = KeyStore.getInstance(defaultType);
+        kpg[1] = KeyStore.getInstance(defaultType, defaultProvider);
+        kpg[2] = KeyStore.getInstance(defaultType, defaultProviderName);
+        return kpg;
     }
 
     /**
@@ -152,10 +80,7 @@
      * returns KeyStoreException object
      */
     public void testKeyStore03() throws KeyStoreException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+        assertTrue(NotSupportMsg, JKSSupported);
         KeyStore ks;
         for (int i = 0; i < validValues.length; i++) {
             ks = KeyStore.getInstance(validValues[i]);
@@ -167,12 +92,8 @@
      * Test for <code>getInstance(String type, String provider)</code> method
      * Assertion: throws IllegalArgumentException when provider is null or empty
      */
-    public void testKeyStore04() throws NoSuchProviderException,
-            KeyStoreException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+    public void testKeyStore04() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
         String provider = null;
         for (int i = 0; i < validValues.length; i++) {
             try {
@@ -195,10 +116,7 @@
      * Assertion: throws NoSuchProviderException when provider is not available
      */
     public void testKeyStore05() throws KeyStoreException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+        assertTrue(NotSupportMsg, JKSSupported);
         for (int i = 0; i < validValues.length; i++) {
             for (int j = 1; j < invalidValues.length; j++) {
                 try {
@@ -219,10 +137,7 @@
      * throws KeyStoreException when type is not available
      */
     public void testKeyStore06() throws NoSuchProviderException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+        assertTrue(NotSupportMsg, JKSSupported);
         try {
             KeyStore.getInstance(null, defaultProviderName);
             fail("KeyStoreException must be thrown  when type is null");
@@ -244,12 +159,8 @@
      * Test for <code>getInstance(String type, String provider)</code> method
      * Assertion: returns KeyStore object
      */
-    public void testKeyStore07() throws NoSuchProviderException,
-            KeyStoreException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+    public void testKeyStore07() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
         KeyStore ks;
         for (int i = 0; i < validValues.length; i++) {
             ks = KeyStore.getInstance(validValues[i], defaultProviderName);
@@ -264,10 +175,7 @@
      * Assertion: throws IllegalArgumentException when provider is null 
      */
     public void testKeyStore08() throws KeyStoreException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+        assertTrue(NotSupportMsg, JKSSupported);
         Provider provider = null;
         for (int i = 0; i < validValues.length; i++) {
             try {
@@ -287,10 +195,7 @@
      * throws KeyStoreException when type is not available
      */
     public void testKeyStore09() {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+        assertTrue(NotSupportMsg, JKSSupported);
         try {
             KeyStore.getInstance(null, defaultProvider);
             fail("KeyStoreException must be thrown when type is null");
@@ -314,10 +219,7 @@
      * Assertion: returns KeyStore object
      */
     public void testKeyStore10() throws KeyStoreException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+        assertTrue(NotSupportMsg, JKSSupported);
         KeyStore ks;
         for (int i = 0; i < validValues.length; i++) {
             ks = KeyStore.getInstance(validValues[i], defaultProvider);
@@ -346,13 +248,8 @@
      * <code>store(OutputStream stream, char[] password)</code>
      * Assertion: throws KeyStoreException when KeyStore was not initialized
      */
-    public void testKeyStore11() throws KeyStoreException, CertificateException,
-            NoSuchAlgorithmException, UnrecoverableKeyException,
-            IOException, UnrecoverableEntryException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+    public void testKeyStore11() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
         String msgF ="KeyStoreException must be thrown because KeyStore was not initialized";
         KeyStore [] kss = createKS();
         assertNotNull("KeyStore objects were not created", kss);
@@ -440,7 +337,7 @@
             } catch (KeyStoreException e) {
             }
             KeyStore.TrustedCertificateEntry entry = new KeyStore.TrustedCertificateEntry(
-                    new MCertificate("type", new byte[0]));
+                    new KeyStoreTestSupport.MCertificate("type", new byte[0]));
             try {
                 kss[i].setEntry("aaa", entry, null);
                 fail(msgF);
@@ -473,14 +370,10 @@
      * used trusted certificate.
      *  
      */
-    public void testEntry01() throws NoSuchAlgorithmException, IOException,
-            CertificateException, KeyStoreException,
-            UnrecoverableEntryException {
-        if (!JKSSupported) {
-            fail(defaultType + " type does not supported");
-            return;
-        }
-        MCertificate trust = new MCertificate("type", new byte[0]);
+    public void testEntry01() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
+        KeyStoreTestSupport.MCertificate trust = new KeyStoreTestSupport.MCertificate(
+                "type", new byte[0]);
         KeyStore.TrustedCertificateEntry entry = new KeyStore.TrustedCertificateEntry(
                 trust);
         KeyStore[] kss = createKS();
@@ -563,18 +456,14 @@
      * KeyStore.PrivateKeyEntry is used.
      * 
      */    
-    public void testEntry02() throws NoSuchAlgorithmException, IOException,
-            CertificateException, KeyStoreException, InvalidKeySpecException,
-            UnrecoverableEntryException, DestroyFailedException,
-            UnrecoverableKeyException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+    public void testEntry02() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
         TestKeyPair tkp = new TestKeyPair("DSA");
-        MCertificate certs[] = {
-                new MCertificate("DSA", tkp.getPrivate().getEncoded()),
-                new MCertificate("DSA", tkp.getPrivate().getEncoded()) };
+        KeyStoreTestSupport.MCertificate certs[] = {
+                new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+                        .getEncoded()),
+                new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+                        .getEncoded()) };
         PrivateKey privKey = tkp.getPrivate();
         KeyStore.PrivateKeyEntry pKey = new KeyStore.PrivateKeyEntry(privKey,
                 certs);
@@ -582,7 +471,7 @@
         KeyStore.PasswordProtection pPath = new KeyStore.PasswordProtection(pwd);
         KeyStore.PasswordProtection anotherPath = new KeyStore.PasswordProtection(
                 new char[0]);
-        ProtPar pPar = new ProtPar();
+        KeyStoreTestSupport.ProtPar pPar = new KeyStoreTestSupport.ProtPar();
         KeyStore[] kss = createKS();
         assertNotNull("KeyStore objects were not created", kss);
         for (int i = 0; i < kss.length; i++) {
@@ -609,13 +498,8 @@
                 }
                 byte[] enc = key.getEncoded();
                 byte[] enc1 = key1.getEncoded();
-                if (enc != null) {
-                    for (int ii = 0; ii < enc.length; ii++) {
-                        if (enc[ii] != enc1[ii]) {
-                            fail("Diff. keys encoding");
-                        }
-                    }
-                }               
+                assertTrue("Diff. keys encoding", Arrays.equals(enc, enc1));
+              
                 cc = ((KeyStore.PrivateKeyEntry) en).getCertificateChain();
                 assertEquals("Incorrect CertificateChain", cc.length,
                         certs.length);
@@ -631,13 +515,7 @@
                 }
                 enc = key.getEncoded();
                 enc1 = key1.getEncoded();
-                if (enc != null) {
-                    for (int ii = 0; ii < enc.length; ii++) {
-                        if (enc[ii] != enc1[ii]) {
-                            fail("Incorrect Entry: Diff. keys encoding");
-                        }
-                    }
-                }
+                assertTrue("Incorrect Entry: Diff. keys encoding", Arrays.equals(enc, enc1));
                   
                 cc = kss[i].getCertificateChain(aliases[j]);
                 assertEquals("Incorrect CertificateChain", cc.length,
@@ -695,23 +573,17 @@
      * FIXME: this test should be changed to verify SecretKeyEntry.
      * It is not supoorted.  
      */    
-    public void testEntry03() throws NoSuchAlgorithmException, 
-            IOException, CertificateException, 
-            KeyStoreException, InvalidKeySpecException, 
-            UnrecoverableEntryException, DestroyFailedException,
-            UnrecoverableKeyException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+    public void testEntry03() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
         TestKeyPair tkp = new TestKeyPair("DSA");
-        SKey secKey = new SKey("DSA",tkp.getPrivate().getEncoded());
+        KeyStoreTestSupport.SKey secKey = new KeyStoreTestSupport.SKey("DSA",
+                tkp.getPrivate().getEncoded());
         KeyStore.SecretKeyEntry sKey = new KeyStore.SecretKeyEntry(
                 secKey);        
         char [] pwd = {'p', 'a', 's', 's', 'w', 'd'};
         KeyStore.PasswordProtection pPath = new KeyStore.PasswordProtection(pwd);
-        AnotherEntry aEntry = new AnotherEntry();
-        ProtPar pPar = new ProtPar();
+        KeyStoreTestSupport.AnotherEntry aEntry = new KeyStoreTestSupport.AnotherEntry();
+        KeyStoreTestSupport.ProtPar pPar = new KeyStoreTestSupport.ProtPar();
         KeyStore [] kss = createKS();
         assertNotNull("KeyStore objects were not created", kss);
         for (int i = 0; i < kss.length; i++) {
@@ -742,13 +614,7 @@
                 }
                 byte[] enc = secKey.getEncoded();
                 byte[] enc1 = key1.getEncoded();
-                if (enc != null) {
-                    for (int ii = 0; ii < enc.length; ii++) {
-                        if (enc[ii] != enc1[ii]) {
-                            fail("Diff. keys encoding");
-                        }
-                    }
-                }
+                assertTrue("Diff. keys encoding", Arrays.equals(enc, enc1));
                 assertNull("Incorrect CertificateChain", kss[i].getCertificateChain(aliases[j]));
             }
         }
@@ -789,14 +655,10 @@
      * setCertificateEntry(..) stores used entry and getCertificate(..) returns it 
      * 
      */
-    public void testEntry04() throws NoSuchAlgorithmException, 
-            IOException, CertificateException, KeyStoreException, 
-            UnrecoverableEntryException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
-        MCertificate cert = new MCertificate("type", new byte[0]);
+    public void testEntry04() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
+        KeyStoreTestSupport.MCertificate cert = new KeyStoreTestSupport.MCertificate(
+                "type", new byte[0]);
         KeyStore [] kss = createKS();
         assertNotNull("KeyStore objects were not created", kss);
         
@@ -863,18 +725,13 @@
      * returns cert 
      * 
      */
-    public void testEntry05() throws NoSuchAlgorithmException, 
-            IOException, CertificateException, KeyStoreException, InvalidKeySpecException,
-            UnrecoverableKeyException {
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
-        MCertificate certs[] = {
-                new MCertificate("type1", new byte[10]),
-                new MCertificate("type2", new byte[10])
-        };
-        MCertificate cert = new MCertificate("type", new byte[0]);
+    public void testEntry05() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
+        KeyStoreTestSupport.MCertificate certs[] = {
+                new KeyStoreTestSupport.MCertificate("type1", new byte[10]),
+                new KeyStoreTestSupport.MCertificate("type2", new byte[10]) };
+        KeyStoreTestSupport.MCertificate cert = new KeyStoreTestSupport.MCertificate(
+                "type", new byte[0]);
         char[] pwd = new char[0];
         TestKeyPair tkp = new TestKeyPair("DSA");
         PrivateKey key = tkp.getPrivate();
@@ -899,7 +756,8 @@
             } catch (KeyStoreException e) {
             }
             try {
-                kss[i].setKeyEntry("ZZZ", key, pwd, new MCertificate[0]);
+                kss[i].setKeyEntry("ZZZ", key, pwd,
+                        new KeyStoreTestSupport.MCertificate[0]);
                 fail("KeyStoreException or IllegalArgumentException should be thrown "
                         + "when chain is empty and key is private");
             } catch (KeyStoreException e) {
@@ -943,13 +801,7 @@
                 }
                 byte[] enc = key.getEncoded();
                 byte[] enc1 = key1.getEncoded();
-                if (enc != null) {
-                    for (int ii = 0; ii < enc.length; ii++) {
-                        if (enc[ii] != enc1[ii]) {
-                            fail("Diff. keys encoding");
-                        }
-                    }
-                }
+                assertTrue("Diff. keys encoding", Arrays.equals(enc, enc1));
                 Certificate [] cc = kss[i].getCertificateChain(aliases[j]);
                 assertEquals("Incorrect chain", cc.length, certs.length);
                 for (int t = 0; t < cc.length; t++) {
@@ -980,20 +832,17 @@
      * deletes entry from KeyStore.
      * 
      */    
-    public void testEntry06() throws NoSuchAlgorithmException, IOException,
-            CertificateException, KeyStoreException, InvalidKeySpecException,
-            UnrecoverableEntryException, UnrecoverableKeyException {
-        if (!JKSSupported) {
-            fail(defaultType + " type does not supported");
-            return;
-        }
+    public void testEntry06() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
         KeyStore.TrustedCertificateEntry tCert = new KeyStore.TrustedCertificateEntry(
-                new MCertificate("type", new byte[0]));
+                new KeyStoreTestSupport.MCertificate("type", new byte[0]));
 
         TestKeyPair tkp = new TestKeyPair("DSA");
-        MCertificate certs[] = {
-                new MCertificate("DSA", tkp.getPrivate().getEncoded()),
-                new MCertificate("DSA", tkp.getPrivate().getEncoded()) };
+        KeyStoreTestSupport.MCertificate certs[] = {
+                new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+                        .getEncoded()),
+                new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+                        .getEncoded()) };
         KeyStore.PrivateKeyEntry pKey = new KeyStore.PrivateKeyEntry(tkp
                 .getPrivate(), certs);
         char[] pwd = { 'p', 'a', 's', 's', 'w', 'd' };
@@ -1050,18 +899,14 @@
      * KeyStore.PrivateKeyEntry is used.
      * 
      */    
-    public void testEntry07() throws NoSuchAlgorithmException, 
-            IOException, CertificateException, InvalidKeySpecException, 
-            KeyStoreException {  
-        if (!JKSSupported) {
-            fail(NotSupportMsg);
-            return;
-        }
+    public void testEntry07() throws Exception {  
+        assertTrue(NotSupportMsg, JKSSupported);
         TestKeyPair tkp = new TestKeyPair("DSA");
-        MCertificate certs[] = {
-            new MCertificate("DSA", tkp.getPrivate().getEncoded()),
-            new MCertificate("DSA", tkp.getPrivate().getEncoded())
-        };
+        KeyStoreTestSupport.MCertificate certs[] = {
+                new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+                        .getEncoded()),
+                new KeyStoreTestSupport.MCertificate("DSA", tkp.getPrivate()
+                        .getEncoded()) };
         PrivateKey privKey = tkp.getPrivate();
         KeyStore.PrivateKeyEntry pKey = new KeyStore.PrivateKeyEntry(privKey, certs);        
         char [] pwd = {'p', 'a', 's', 's', 'w', 'd'};
@@ -1110,13 +955,8 @@
      * constructor
      * Assertion: constructs KeyStore object
      */
-    public void testKeyStoreConstr() throws NoSuchAlgorithmException,
-            KeyStoreException, IOException,
-            NoSuchAlgorithmException, CertificateException {
-        if (!JKSSupported) {
-            fail(defaultType + " type does not supported");
-            return;
-        }
+    public void testKeyStoreConstr() throws Exception {
+        assertTrue(NotSupportMsg, JKSSupported);
         KeyStoreSpi spi = new MyKeyStoreSpi();
         KeyStore keySt = new tmpKeyStore(spi, defaultProvider,
                 defaultType);
@@ -1138,119 +978,7 @@
         } catch (NullPointerException e) {
         }
     }
-    public static void main(String args[]) {
-        junit.textui.TestRunner.run(KeyStore1Test.class);
-    }
-    
-    /**
-     * Additional class to create SecretKey object
-     */
-   public class SKey implements SecretKey {
-        private String type;
-
-        private byte[] encoded;
-
-        public SKey(String type, byte[] encoded) {
-            this.type = type;
-            this.encoded = encoded;
-        }
-
-        public String getAlgorithm() {
-            return type;
-        }
-
-        public byte[] getEncoded() {
-            return encoded;
-        }
-
-        public String getFormat() {
-            return "test";
-        }
-    }
-   /**
-    * Additional class to create PrivateKey object
-    */   
-   public class MyPrivateKey implements PrivateKey {
-       private String algorithm;
-       private String format;
-       private byte [] encoded;
-       
-       public MyPrivateKey(String algorithm, String format, byte[] encoded) {
-           this.algorithm = algorithm;
-           this.format = format;
-           this.encoded = encoded;
-       }
-       public String getAlgorithm() {
-           return algorithm;
-       }
-       public String getFormat() {
-           return format;
-       }
-       public byte[] getEncoded() {
-           return encoded;
-       }
-   }
-   
-   /**
-    * Additional class to create Certificate and Key objects
-    */
-   public class MCertificate extends Certificate {
-       private final byte[] encoding;
-
-       private final String type;
-
-       public MCertificate(String type, byte[] encoding) {
-           super(type);
-           this.encoding = encoding;
-           this.type = type;
-       }
-
-       public byte[] getEncoded() throws CertificateEncodingException {
-           return encoding.clone();
-       }
-
-       public void verify(PublicKey key) throws CertificateException,
-               NoSuchAlgorithmException, InvalidKeyException,
-               NoSuchProviderException, SignatureException {
-       }
-
-       public void verify(PublicKey key, String sigProvider)
-               throws CertificateException, NoSuchAlgorithmException,
-               InvalidKeyException, NoSuchProviderException, SignatureException {
-       }
-
-       public String toString() {
-           return "[MCertificate, type: " + getType() + "]";
-       }
-
-       public PublicKey getPublicKey() {
-           return new PublicKey() {
-               public String getAlgorithm() {
-                   return type;
-               }
-
-               public byte[] getEncoded() {
-                   return encoding;
-               }
-
-               public String getFormat() {
-                   return "test";
-               }
-           };
-       }
-   }
-
-    /**
-     * Additional class to create ProtectionParameter object
-     */
-    public class ProtPar implements KeyStore.ProtectionParameter {        
-    }
 
-    /**
-     * Additional class to create KeyStore.Entry object
-     */
-    public class AnotherEntry implements KeyStore.Entry {
-    }
 }
 
 /**

Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl2Test.java (from r412639, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KeyStore2Test.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl2Test.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl2Test.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KeyStore2Test.java&r1=412639&r2=413841&rev=413841&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KeyStore2Test.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl2Test.java Tue Jun 13 01:58:11 2006
@@ -19,35 +19,40 @@
 * @version $Revision$
 */
 
-package java.security;
+package org.apache.harmony.security.tests.java.security;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
 import java.security.NoSuchProviderException;
 import java.security.Provider;
 import java.security.Security;
+import java.security.UnrecoverableEntryException;
+import java.security.UnrecoverableKeyException;
 import java.security.cert.Certificate;
 import java.security.cert.CertificateException;
+import java.util.Date;
 
 import javax.crypto.spec.SecretKeySpec;
 
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport;
 import org.apache.harmony.security.tests.support.MyLoadStoreParams;
 import org.apache.harmony.security.tests.support.SpiEngUtils;
 import org.apache.harmony.security.tests.support.cert.MyCertificate;
 
 import junit.framework.TestCase;
 
-import java.util.Date;
-
-
 /**
  * Tests for <code>KeyStore</code> constructor and methods
  * 
  */
 
-public class KeyStore2Test extends TestCase {
+public class KeyStore_Impl2Test extends TestCase {
 
-    private static final String KeyStoreProviderClass = "org.apache.harmony.security.tests.support.MyKeyStoreSpi";
+    private static final String KeyStoreProviderClass = 
+        "org.apache.harmony.security.tests.support.MyKeyStoreSpi";
 
     private static final String defaultAlg = "KeyStore";
 
@@ -68,7 +73,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         mProv = (new SpiEngUtils()).new MyProvider("MyKSProvider",
-                "Testing provider", KeyStore1Test.srvKeyStore.concat(".").concat(
+                "Testing provider", KeyStoreTestSupport.srvKeyStore.concat(".").concat(
                         defaultAlg), KeyStoreProviderClass);
         Security.insertProviderAt(mProv, 2);
     }
@@ -81,15 +86,6 @@
         Security.removeProvider(mProv.getName());
     }
 
-    /**
-     * Constructor for SecurityManagerFactoryTest2.
-     * 
-     * @param arg0
-     */
-    public KeyStore2Test(String arg0) {
-        super(arg0);
-    }
-
     private void checkResult(KeyStore keyS) throws KeyStoreException,
             IOException, CertificateException, NoSuchAlgorithmException,
             UnrecoverableKeyException {
@@ -432,9 +428,6 @@
             checkKeyStoreException(keyS);
             checkResult(keyS);
         }
-    }
-    public static void main(String args[]) {
-        junit.textui.TestRunner.run(KeyStore2Test.class);
     }
 
 }

Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl3Test.java (from r412639, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KeyStore3Test.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl3Test.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl3Test.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KeyStore3Test.java&r1=412639&r2=413841&rev=413841&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/KeyStore3Test.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/KeyStore_Impl3Test.java Tue Jun 13 01:58:11 2006
@@ -19,29 +19,30 @@
 * @version $Revision$
 */
 
-package java.security;
+package org.apache.harmony.security.tests.java.security;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.security.KeyStore;
+import java.security.PrivateKey;
 import java.security.Provider;
 import java.security.Security;
 import java.security.cert.Certificate;
 
-import org.apache.harmony.security.tests.support.MyLoadStoreParams;
+import org.apache.harmony.security.tests.support.KeyStoreTestSupport;
 import org.apache.harmony.security.tests.support.SpiEngUtils;
 
 import junit.framework.TestCase;
 
-
 /**
  * Tests for <code>KeyStore</code> constructor and methods
  * 
  */
 
-public class KeyStore3Test extends TestCase {
+public class KeyStore_Impl3Test extends TestCase {
 
-    private static final String KeyStoreProviderClass = "java.security.MyKeyStore";
+    private static final String KeyStoreProviderClass = "org.apache.harmony.security.tests.support.MyKeyStore";
 
     private static final String defaultType = "KeyStore";
 
@@ -56,9 +57,7 @@
     Provider mProv;
 
     public KeyStore[] createKS() throws Exception {
-        if (!KSSupported) {
-            fail(NotSupportMsg);
-        }
+        assertTrue(NotSupportMsg, KSSupported);
         KeyStore[] kpg = new KeyStore[3];
 
         kpg[0] = KeyStore.getInstance(defaultType);
@@ -70,11 +69,11 @@
     protected void setUp() throws Exception {
         super.setUp();
         mProv = (new SpiEngUtils()).new MyProvider("MyKSProvider",
-                "Testing provider", KeyStore1Test.srvKeyStore.concat(".")
+                "Testing provider", KeyStoreTestSupport.srvKeyStore.concat(".")
                         .concat(defaultType), KeyStoreProviderClass);
         Security.insertProviderAt(mProv, 2);
         defaultProvider = SpiEngUtils.isSupport(defaultType,
-                KeyStore1Test.srvKeyStore);
+                KeyStoreTestSupport.srvKeyStore);
         KSSupported = (defaultProvider != null);
         defaultProviderName = (KSSupported ? defaultProvider.getName() : null);
     }
@@ -88,15 +87,6 @@
     }
 
     /**
-     * Constructor for SecurityManagerFactoryTest2.
-     * 
-     * @param arg0
-     */
-    public KeyStore3Test(String arg0) {
-        super(arg0);
-    }
-
-    /**
      * Test for <code>load(InputStream stream, char[] password)</code> 
      * <code>store(InputStream stream, char[] password)</code> 
      * <code>size()</code>
@@ -110,19 +100,16 @@
      */
 
     public void testLoadStore01() throws Exception {
-        if (!KSSupported) {
-            fail(NotSupportMsg);
-        }
+        assertTrue(NotSupportMsg, KSSupported);
 
         String tType = "TestType";
-        KeyStore1Test keyStoreT1 = new KeyStore1Test("proba");
         KeyStore.TrustedCertificateEntry tCert = new KeyStore.TrustedCertificateEntry(
-                keyStoreT1.new MCertificate("type", new byte[0]));
+                new KeyStoreTestSupport.MCertificate("type", new byte[0]));
 
         Certificate certs[] = {
-                keyStoreT1.new MCertificate(tType, new byte[10]),
-                keyStoreT1.new MCertificate(tType, new byte[20]) };
-        PrivateKey pk = keyStoreT1.new MyPrivateKey(tType, "", new byte[10]);
+                new KeyStoreTestSupport.MCertificate(tType, new byte[10]),
+                new KeyStoreTestSupport.MCertificate(tType, new byte[20]) };
+        PrivateKey pk = new KeyStoreTestSupport.MyPrivateKey(tType, "", new byte[10]);
         KeyStore.PrivateKeyEntry pKey = new KeyStore.PrivateKeyEntry(pk, certs);
         char[] pwd = { 'p', 'a', 's', 's', 'w', 'd' };
         KeyStore.PasswordProtection pPath = new KeyStore.PasswordProtection(pwd);
@@ -212,92 +199,5 @@
             assertEquals("Incorrect date", kss[i].getCreationDate(aliases[4]),
                     kss1[i].getCreationDate(aliases[4]));
         }
-    }
-
-    /**
-     * Test for <code>load(LoadStoreParameter param)</code> 
-     * <code>store(LoadStoreParameter param)</code>
-     * methods 
-     * Assertions: throw IllegalArgumentException if param is null;
-     */
-    public void testLoadStore02() throws Exception {
-        if (!KSSupported) {
-            fail(NotSupportMsg);
-        }
-
-        KeyStore[] kss = createKS();
-        assertNotNull("KeyStore objects were not created", kss);
-
-        for (int i = 0; i < kss.length; i++) {
-            try {
-                kss[i].load(null);
-                fail("IOException or IllegalArgumentException should be thrown for null parameter");
-            } catch (IOException e) {
-            } catch (IllegalArgumentException e) {
-            }
-            kss[i].load(null, null);
-            try {
-                kss[i].store(null);
-                fail("IOException or IllegalArgumentException should be thrown for nill parameter");
-            } catch (IOException e) {
-            } catch (IllegalArgumentException e) {
-            }
-        }
-        KeyStore.LoadStoreParameter lParam = new MyLoadStoreParams(
-                new KeyStore.PasswordProtection(new char[0]));
-        for (int i = 0; i < kss.length; i++) {
-            kss[i].load(lParam);
-            assertEquals("Incorrect result", kss[i].size(), 0);
-            kss[i].store(lParam);
-        }
-    }
-
-    
-    /**
-     * Test for <code>setKeyEntry(String alias, bute[] key, Certificate[] chain)</code> 
-     * method 
-     * Assertion: stores KeyEntry.
-     */
-    public void testSetKeyEntry() throws Exception {
-        if (!KSSupported) {
-            fail(NotSupportMsg);
-        }
-
-        KeyStore[] kss = createKS();
-        assertNotNull("KeyStore objects were not created", kss);
-        byte[] kk = { (byte) 1, (byte) 2, (byte) 127, (byte) 77 };
-        String alias = "keyEntry";
-        char[] pwd = new char[0];
-        byte[] res;
-        KeyStore1Test keyStoreT1 = new KeyStore1Test("proba");
-        Certificate certs[] = {
-                keyStoreT1.new MCertificate(alias, kk),
-                keyStoreT1.new MCertificate(alias, kk) };
-        for (int i = 0; i < kss.length; i++) {
-            kss[i].load(null, null);
-            try {
-                kss[i].setKeyEntry("proba", null, null);
-                fail("KeyStoreException must be thrown");
-            } catch (KeyStoreException e) {
-            }
-            kss[i].setKeyEntry(alias, kk, certs);
-            res = kss[i].getKey(alias, pwd).getEncoded();
-            assertEquals(kk.length, res.length);
-            for (int j = 0; j < res.length; j++) {
-                assertEquals(res[j], kk[j]);
-            }
-            assertEquals(kss[i].getCertificateChain(alias).length, certs.length);
-            kss[i].setKeyEntry(alias, kk, null);
-            res = kss[i].getKey(alias, pwd).getEncoded();
-            assertEquals(kk.length, res.length);
-            for (int j = 0; j < res.length; j++) {
-                assertEquals(res[j], kk[j]);
-            }
-            assertNull(kss[i].getCertificateChain(alias));
-        }
-    }
-    
-    public static void main(String args[]) {
-        junit.textui.TestRunner.run(KeyStore3Test.class);
     }
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/MessageDigest_Impl1Test.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/MessageDigest_Impl1Test.java?rev=413841&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/MessageDigest_Impl1Test.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/MessageDigest_Impl1Test.java Tue Jun 13 01:58:11 2006
@@ -0,0 +1,52 @@
+/*
+ *  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 Boris V. Kuznetsov
+* @version $Revision$
+*/
+
+package org.apache.harmony.security.tests.java.security;
+
+import org.apache.harmony.security.tests.support.MyMessageDigest1;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for <code>MessageDigest</code> constructor and methods
+ * 
+ */
+public class MessageDigest_Impl1Test extends TestCase {
+
+	/*
+	 * Class under test for int digest(byte[], int, int)
+	 */
+	public void testDigestbyteArrayintint() throws Exception {
+		MyMessageDigest1 md = new MyMessageDigest1("ABC");
+		byte[] b = {1, 2, 3, 4, 5};
+		assertEquals("incorrect result", 0, md.digest(b, 2, 3));
+        assertTrue("digest failed", md.runEngineDigest);
+	}
+
+	/*
+	 * Class under test for String toString()
+	 */
+	public void testToString() {
+		MyMessageDigest1 md = new MyMessageDigest1("ABC");
+        assertEquals("incorrect result", "MESSAGE DIGEST ABC", md.toString());
+	}
+}
+



Mime
View raw message