harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r415555 [14/17] - in /incubator/harmony/enhanced/classlib/trunk/modules/security: make/common/ src/test/api/java.injected/java/security/acl/ src/test/api/java.injected/java/security/cert/ src/test/api/java.injected/java/security/interfaces/...
Date Tue, 20 Jun 2006 08:11:19 GMT
Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/CertificateParsingExceptionTest.java (from r414728, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/javax/security/cert/CertificateParsingExceptionTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/CertificateParsingExceptionTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/CertificateParsingExceptionTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/javax/security/cert/CertificateParsingExceptionTest.java&r1=414728&r2=415555&rev=415555&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/javax/security/cert/CertificateParsingExceptionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/CertificateParsingExceptionTest.java Tue Jun 20 01:11:04 2006
@@ -1,111 +1,111 @@
-/*
- *  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 javax.security.cert;
-
-import javax.security.cert.CertificateParsingException;
-
-import junit.framework.TestCase;
-
-
-/**
- * Tests for <code>DigestException</code> class constructors and methods.
- * 
- */
-public class CertificateParsingExceptionTest extends TestCase {
-
-    public static void main(String[] args) {
-    }
-
-    /**
-     * Constructor for CertificateParsingExceptionTests.
-     * 
-     * @param arg0
-     */
-    public CertificateParsingExceptionTest(String arg0) {
-        super(arg0);
-    }
-
-    static String[] msgs = {
-            "",
-            "Check new message",
-            "Check new message Check new message Check new message Check new message Check new message" };
-
-    static Throwable tCause = new Throwable("Throwable for exception");
-
-    static String createErr(Exception tE, Exception eE) {
-        return "CertificateParsingException: ".concat(tE.toString()).concat(
-                " is not equal to caught exception: ").concat(eE.toString());
-    }
-
-    /**
-     * Test for <code>CertificateParsingException()</code> constructor
-     * Assertion: constructs CertificateParsingException with no detail message
-     */
-    public void testCertificateParsingException01() {
-        CertificateParsingException tE = new CertificateParsingException();
-        assertNull("getMessage() must return null.", tE.getMessage());
-        assertNull("getCause() must return null", tE.getCause());
-        try {
-            throw tE;
-        } catch (Exception e) {
-            assertTrue(createErr(tE, e), tE.equals(e));
-        }
-    }
-
-    /**
-     * Test for <code>CertificateParsingException(String)</code> constructor
-     * Assertion: constructs CertificateParsingException with detail message
-     * msg. Parameter <code>msg</code> is not null.
-     */
-    public void testCertificateParsingException02() {
-        CertificateParsingException tE;
-        for (int i = 0; i < msgs.length; i++) {
-            tE = new CertificateParsingException(msgs[i]);
-            assertEquals("getMessage() must return: ".concat(msgs[i]), tE
-                    .getMessage(), msgs[i]);
-            assertNull("getCause() must return null", tE.getCause());
-            try {
-                throw tE;
-            } catch (Exception e) {
-                assertTrue(createErr(tE, e), tE.equals(e));
-            }
-        }
-    }
-
-    /**
-     * Test for <code>CertificateParsingException(String)</code> constructor
-     * Assertion: constructs CertificateParsingException when <code>msg</code>
-     * is null
-     */
-    public void testCertificateParsingException03() {
-        String msg = null;
-        CertificateParsingException tE = new CertificateParsingException(msg);
-        assertNull("getMessage() must return null.", tE.getMessage());
-        assertNull("getCause() must return null", tE.getCause());
-        try {
-            throw tE;
-        } catch (Exception e) {
-            assertTrue(createErr(tE, e), tE.equals(e));
-        }
-    }
-
-}
+/*
+ *  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.javax.security.cert;
+
+import javax.security.cert.CertificateParsingException;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Tests for <code>DigestException</code> class constructors and methods.
+ * 
+ */
+public class CertificateParsingExceptionTest extends TestCase {
+
+    public static void main(String[] args) {
+    }
+
+    /**
+     * Constructor for CertificateParsingExceptionTests.
+     * 
+     * @param arg0
+     */
+    public CertificateParsingExceptionTest(String arg0) {
+        super(arg0);
+    }
+
+    static String[] msgs = {
+            "",
+            "Check new message",
+            "Check new message Check new message Check new message Check new message Check new message" };
+
+    static Throwable tCause = new Throwable("Throwable for exception");
+
+    static String createErr(Exception tE, Exception eE) {
+        return "CertificateParsingException: ".concat(tE.toString()).concat(
+                " is not equal to caught exception: ").concat(eE.toString());
+    }
+
+    /**
+     * Test for <code>CertificateParsingException()</code> constructor
+     * Assertion: constructs CertificateParsingException with no detail message
+     */
+    public void testCertificateParsingException01() {
+        CertificateParsingException tE = new CertificateParsingException();
+        assertNull("getMessage() must return null.", tE.getMessage());
+        assertNull("getCause() must return null", tE.getCause());
+        try {
+            throw tE;
+        } catch (Exception e) {
+            assertTrue(createErr(tE, e), tE.equals(e));
+        }
+    }
+
+    /**
+     * Test for <code>CertificateParsingException(String)</code> constructor
+     * Assertion: constructs CertificateParsingException with detail message
+     * msg. Parameter <code>msg</code> is not null.
+     */
+    public void testCertificateParsingException02() {
+        CertificateParsingException tE;
+        for (int i = 0; i < msgs.length; i++) {
+            tE = new CertificateParsingException(msgs[i]);
+            assertEquals("getMessage() must return: ".concat(msgs[i]), tE
+                    .getMessage(), msgs[i]);
+            assertNull("getCause() must return null", tE.getCause());
+            try {
+                throw tE;
+            } catch (Exception e) {
+                assertTrue(createErr(tE, e), tE.equals(e));
+            }
+        }
+    }
+
+    /**
+     * Test for <code>CertificateParsingException(String)</code> constructor
+     * Assertion: constructs CertificateParsingException when <code>msg</code>
+     * is null
+     */
+    public void testCertificateParsingException03() {
+        String msg = null;
+        CertificateParsingException tE = new CertificateParsingException(msg);
+        assertNull("getMessage() must return null.", tE.getMessage());
+        assertNull("getCause() must return null", tE.getCause());
+        try {
+            throw tE;
+        } catch (Exception e) {
+            assertTrue(createErr(tE, e), tE.equals(e));
+        }
+    }
+
+}

Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/CertificateTest.java (from r414728, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/javax/security/cert/CertificateTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/CertificateTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/CertificateTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/javax/security/cert/CertificateTest.java&r1=414728&r2=415555&rev=415555&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/javax/security/cert/CertificateTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/CertificateTest.java Tue Jun 20 01:11:04 2006
@@ -1,154 +1,156 @@
-/*
- *  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 javax.security.cert;
-
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.PublicKey;
-import java.security.SignatureException;
-import javax.security.cert.CertificateEncodingException;
-import javax.security.cert.CertificateException;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- */
-
-public class CertificateTest extends TestCase {
-
-    /**
-     * The stub class used for testing of non abstract methods.
-     */
-    private class TBTCert extends Certificate {
-        public byte[] getEncoded()
-                throws CertificateEncodingException {
-            return null;
-        } 
-
-        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 null;
-        }
-
-        public PublicKey getPublicKey() {
-            return null;
-        }
-    }
-
-    /**
-     * equals(Object obj) method testing. Tests the correctnel of equal
-     * operation: it should be reflexive, symmetric, transitive, consistent
-     * and should be false on null object.
-     */
-    public void testEquals() {
-        TBTCert tbt_cert = new TBTCert() {
-            public byte[] getEncoded() {
-                return new byte[] {1, 2, 3};
-            }
-        };
-
-        TBTCert tbt_cert_1 = new TBTCert() {
-            public byte[] getEncoded() {
-                return new byte[] {1, 2, 3};
-            }
-        };
-
-        TBTCert tbt_cert_2 = new TBTCert() {
-            public byte[] getEncoded() {
-                return new byte[] {1, 2, 3};
-            }
-        };
-
-        TBTCert tbt_cert_3 = new TBTCert() {
-            public byte[] getEncoded() {
-                return new byte[] {3, 2, 1};
-            }
-        };
-
-        // checking for reflexive law:
-        assertTrue("The equivalence relation should be reflexive.",
-                                                tbt_cert.equals(tbt_cert));
-
-        assertEquals("The Certificates with equal encoded form should be equal",
-                                                tbt_cert, tbt_cert_1);
-        // checking for symmetric law:
-        assertTrue("The equivalence relation should be symmetric.",
-                                                tbt_cert_1.equals(tbt_cert));
-
-        assertEquals("The Certificates with equal encoded form should be equal",
-                                                tbt_cert_1, tbt_cert_2);
-        // checking for transitive law:
-        assertTrue("The equivalence relation should be transitive.",
-                                                tbt_cert.equals(tbt_cert_2));
-
-        assertFalse("Should not be equal to null object.",
-                                                tbt_cert.equals(null));
-
-        assertFalse("The Certificates with differing encoded form "
-                    + "should not be equal", tbt_cert.equals(tbt_cert_3));
-        assertFalse("The Certificates should not be equals to the object "
-                    + "which is not an instance of Certificate", 
-                                                tbt_cert.equals(new Object()));
-    }
-
-    /**
-     * hashCode() method testing.
-     */
-    public void testHashCode() {
-        TBTCert tbt_cert = new TBTCert() {
-            public byte[] getEncoded() {
-                return new byte[] {1, 2, 3};
-            }
-        };
-        TBTCert tbt_cert_1 = new TBTCert() {
-            public byte[] getEncoded() {
-                return new byte[] {1, 2, 3};
-            }
-        };
-
-        assertTrue("Equal objects should have the same hash codes.",
-                                    tbt_cert.hashCode() == tbt_cert_1.hashCode());
-    }
-
-    public static Test suite() {
-        return new TestSuite(CertificateTest.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 org.apache.harmony.security.tests.javax.security.cert;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.PublicKey;
+import java.security.SignatureException;
+
+import javax.security.cert.Certificate;
+import javax.security.cert.CertificateEncodingException;
+import javax.security.cert.CertificateException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ */
+
+public class CertificateTest extends TestCase {
+
+    /**
+     * The stub class used for testing of non abstract methods.
+     */
+    private class TBTCert extends Certificate {
+        public byte[] getEncoded()
+                throws CertificateEncodingException {
+            return null;
+        } 
+
+        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 null;
+        }
+
+        public PublicKey getPublicKey() {
+            return null;
+        }
+    }
+
+    /**
+     * equals(Object obj) method testing. Tests the correctnel of equal
+     * operation: it should be reflexive, symmetric, transitive, consistent
+     * and should be false on null object.
+     */
+    public void testEquals() {
+        TBTCert tbt_cert = new TBTCert() {
+            public byte[] getEncoded() {
+                return new byte[] {1, 2, 3};
+            }
+        };
+
+        TBTCert tbt_cert_1 = new TBTCert() {
+            public byte[] getEncoded() {
+                return new byte[] {1, 2, 3};
+            }
+        };
+
+        TBTCert tbt_cert_2 = new TBTCert() {
+            public byte[] getEncoded() {
+                return new byte[] {1, 2, 3};
+            }
+        };
+
+        TBTCert tbt_cert_3 = new TBTCert() {
+            public byte[] getEncoded() {
+                return new byte[] {3, 2, 1};
+            }
+        };
+
+        // checking for reflexive law:
+        assertTrue("The equivalence relation should be reflexive.",
+                                                tbt_cert.equals(tbt_cert));
+
+        assertEquals("The Certificates with equal encoded form should be equal",
+                                                tbt_cert, tbt_cert_1);
+        // checking for symmetric law:
+        assertTrue("The equivalence relation should be symmetric.",
+                                                tbt_cert_1.equals(tbt_cert));
+
+        assertEquals("The Certificates with equal encoded form should be equal",
+                                                tbt_cert_1, tbt_cert_2);
+        // checking for transitive law:
+        assertTrue("The equivalence relation should be transitive.",
+                                                tbt_cert.equals(tbt_cert_2));
+
+        assertFalse("Should not be equal to null object.",
+                                                tbt_cert.equals(null));
+
+        assertFalse("The Certificates with differing encoded form "
+                    + "should not be equal", tbt_cert.equals(tbt_cert_3));
+        assertFalse("The Certificates should not be equals to the object "
+                    + "which is not an instance of Certificate", 
+                                                tbt_cert.equals(new Object()));
+    }
+
+    /**
+     * hashCode() method testing.
+     */
+    public void testHashCode() {
+        TBTCert tbt_cert = new TBTCert() {
+            public byte[] getEncoded() {
+                return new byte[] {1, 2, 3};
+            }
+        };
+        TBTCert tbt_cert_1 = new TBTCert() {
+            public byte[] getEncoded() {
+                return new byte[] {1, 2, 3};
+            }
+        };
+
+        assertTrue("Equal objects should have the same hash codes.",
+                                    tbt_cert.hashCode() == tbt_cert_1.hashCode());
+    }
+
+    public static Test suite() {
+        return new TestSuite(CertificateTest.class);
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(suite());
+    }
+}
+

Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/X509CertificateTest.java (from r414728, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/javax/security/cert/X509CertificateTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/X509CertificateTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/X509CertificateTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/javax/security/cert/X509CertificateTest.java&r1=414728&r2=415555&rev=415555&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/javax/security/cert/X509CertificateTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/javax/security/cert/X509CertificateTest.java Tue Jun 20 01:11:04 2006
@@ -1,322 +1,327 @@
-/*
- *  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 javax.security.cert;
-
-import java.io.ByteArrayInputStream;
-import java.security.cert.CertificateFactory;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import javax.security.cert.CertificateEncodingException;
-import javax.security.cert.CertificateException;
-import javax.security.cert.X509Certificate;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- */
-
-public class X509CertificateTest extends TestCase {
-
-    // Testing data was generated by using of classes 
-    // from org.apache.harmony.security.asn1 package encoded
-    // by org.apache.harmony.misc.Base64 class.
-
-    private static String base64cert = 
-        "-----BEGIN CERTIFICATE-----\n" +
-        "MIIC+jCCAragAwIBAgICAiswDAYHKoZIzjgEAwEBADAdMRswGQYDVQQKExJDZXJ0a" +
-        "WZpY2F0ZSBJc3N1ZXIwIhgPMTk3MDAxMTIxMzQ2NDBaGA8xOTcwMDEyNDAzMzMyMF" +
-        "owHzEdMBsGA1UEChMUU3ViamVjdCBPcmdhbml6YXRpb24wGTAMBgcqhkjOOAQDAQE" +
-        "AAwkAAQIDBAUGBwiBAgCqggIAVaOCAhQwggIQMA8GA1UdDwEB/wQFAwMBqoAwEgYD" +
-        "VR0TAQH/BAgwBgEB/wIBBTAUBgNVHSABAf8ECjAIMAYGBFUdIAAwZwYDVR0RAQH/B" +
-        "F0wW4EMcmZjQDgyMi5OYW1lggdkTlNOYW1lpBcxFTATBgNVBAoTDE9yZ2FuaXphdG" +
-        "lvboYaaHR0cDovL3VuaWZvcm0uUmVzb3VyY2UuSWSHBP///wCIByoDolyDsgMwDAY" +
-        "DVR0eAQH/BAIwADAMBgNVHSQBAf8EAjAAMIGZBgNVHSUBAf8EgY4wgYsGBFUdJQAG" +
-        "CCsGAQUFBwMBBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMDBggrBgEFBQcDB" +
-        "AYIKwYBBQUHAwUGCCsGAQUFBwMGBggrBgEFBQcDBwYIKwYBBQUHAwgGCCsGAQUFBw" +
-        "MJBggrBgEFBQgCAgYKKwYBBAGCNwoDAwYJYIZIAYb4QgQBMA0GA1UdNgEB/wQDAgE" +
-        "BMA4GBCpNhgkBAf8EAwEBATBkBgNVHRIEXTBbgQxyZmNAODIyLk5hbWWCB2ROU05h" +
-        "bWWkFzEVMBMGA1UEChMMT3JnYW5pemF0aW9uhhpodHRwOi8vdW5pZm9ybS5SZXNvd" +
-        "XJjZS5JZIcE////AIgHKgOiXIOyAzAJBgNVHR8EAjAAMAoGA1UdIwQDAQEBMAoGA1" +
-        "UdDgQDAQEBMAoGA1UdIQQDAQEBMAwGByqGSM44BAMBAQADMAAwLQIUAL4QvoazNWP" +
-        "7jrj84/GZlhm09DsCFQCBKGKCGbrP64VtUt4JPmLjW1VxQA==\n" +
-        "-----END CERTIFICATE-----"; 
-
-    private java.security.cert.X509Certificate cert;
-    private javax.security.cert.X509Certificate tbt_cert;
-
-    protected void setUp() throws Exception {
-        try {
-            ByteArrayInputStream bais =
-                new ByteArrayInputStream(base64cert.getBytes());
-
-            CertificateFactory cf = CertificateFactory.getInstance("X.509");
-            this.cert = (java.security.cert.X509Certificate)
-                                                cf.generateCertificate(bais);
-            this.tbt_cert = X509Certificate.getInstance(cert.getEncoded());
-        } catch (java.security.cert.CertificateException e) {
-            // The requested certificate type is not available.
-            // Test pass..
-            this.cert = null;
-        } catch (javax.security.cert.CertificateException e) {
-            // The requested certificate type is not available.
-            // Test pass..
-            this.cert = null;
-        }
-    }
-
-    /**
-     * getInstance(InputStream inStream) method testing.
-     */
-    public void testGetInstance1() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        try {
-            ByteArrayInputStream bais =
-                new ByteArrayInputStream(cert.getEncoded());
-
-            X509Certificate.getInstance(bais);
-        } catch (java.security.cert.CertificateEncodingException e) {
-            e.printStackTrace();
-            fail("Unexpected CertificateEncodingException was thrown.");
-        } catch (CertificateEncodingException e) {
-            e.printStackTrace();
-            fail("Unexpected CertificateEncodingException was thrown.");
-        } catch (CertificateException e) {
-            // The requested certificate type is not available.
-            // Test pass..
-        }
-    }
-
-    /**
-     * getInstance(byte[] certData) method testing.
-     */
-    public void testGetInstance2() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        try {
-            X509Certificate.getInstance(cert.getEncoded());
-        } catch (java.security.cert.CertificateEncodingException e) {
-            e.printStackTrace();
-            fail("Unexpected CertificateEncodingException was thrown.");
-        } catch (CertificateException e) {
-            // The requested certificate type is not available.
-            // Test pass..
-        }
-    }
-
-    /**
-     * checkValidity() method testing.
-     */
-    public void testCheckValidity1() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        Date date = new Date();
-        Date nb_date = tbt_cert.getNotBefore();
-        Date na_date = tbt_cert.getNotAfter();
-        try {
-            tbt_cert.checkValidity();
-            assertFalse("CertificateExpiredException expected",
-                                            date.compareTo(na_date) > 0);
-            assertFalse("CertificateNotYetValidException expected",
-                                            date.compareTo(nb_date) < 0);
-        } catch (CertificateExpiredException e) {
-            assertTrue("Unexpected CertificateExpiredException was thrown",
-                                            date.compareTo(na_date) > 0);
-        } catch (CertificateNotYetValidException e) {
-            assertTrue("Unexpected CertificateNotYetValidException was thrown",
-                                            date.compareTo(nb_date) < 0);
-        }
-    }
-
-    /**
-     * checkValidity(Date date) method testing.
-     */
-    public void testCheckValidity2() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        Date[] date = new Date[4];
-        Calendar calendar = Calendar.getInstance();
-        for (int i=0; i<date.length; i++) {
-            calendar.set(i*50, Calendar.JANUARY, 1);
-            date[i] = calendar.getTime();
-        }
-        Date nb_date = tbt_cert.getNotBefore();
-        Date na_date = tbt_cert.getNotAfter();
-        for (int i=0; i<date.length; i++) {
-            try {
-                tbt_cert.checkValidity(date[i]);
-                assertFalse("CertificateExpiredException expected",
-                                                date[i].compareTo(na_date) > 0);
-                assertFalse("CertificateNotYetValidException expected",
-                                                date[i].compareTo(nb_date) < 0);
-            } catch (CertificateExpiredException e) {
-                assertTrue("Unexpected CertificateExpiredException was thrown",
-                                                date[i].compareTo(na_date) > 0);
-            } catch (CertificateNotYetValidException e) {
-                assertTrue("Unexpected CertificateNotYetValidException "
-                                + "was thrown", date[i].compareTo(nb_date) < 0);
-            }
-        }
-    }
-
-    /**
-     * getVersion() method testing.
-     */
-    public void testGetVersion() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        assertEquals("The version is not correct.",
-                                                tbt_cert.getVersion(), 2);
-    }
-
-    /**
-     * getSerialNumber() method testing.
-     */
-    public void testGetSerialNumber() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        assertEquals("The serial number is not correct.",
-                            tbt_cert.getSerialNumber(), cert.getSerialNumber());
-    }
-
-    /**
-     * getIssuerDN() method testing.
-     */
-    public void testGetIssuerDN() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        assertEquals("The issuer DN is not correct.",
-                                    tbt_cert.getIssuerDN(), cert.getIssuerDN());
-    }
-
-    /**
-     * getSubjectDN() method testing.
-     */
-    public void testGetSubjectDN() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        assertEquals("The subject DN is not correct.",
-                                tbt_cert.getSubjectDN(), cert.getSubjectDN());
-    }
-
-    /**
-     * getNotBefore() method testing.
-     */
-    public void testGetNotBefore() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        assertEquals("The NotBefore date is not correct.",
-                                tbt_cert.getNotBefore(), cert.getNotBefore());
-    }
-
-    /**
-     * getNotAfter() method testing.
-     */
-    public void testGetNotAfter() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        assertEquals("The NotAfter date is not correct.",
-                                tbt_cert.getNotAfter(), cert.getNotAfter());
-    }
-
-    /**
-     * getSigAlgName() method testing.
-     */
-    public void testGetSigAlgName() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        assertEquals("The name of signature algorithm is not correct.",
-                                tbt_cert.getSigAlgName(), cert.getSigAlgName());
-    }
-
-    /**
-     * getSigAlgOID() method testing.
-     */
-    public void testGetSigAlgOID() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        assertEquals("The name of OID of signature algorithm is not correct.",
-                                tbt_cert.getSigAlgOID(), cert.getSigAlgOID());
-    }
-
-    /**
-     * getSigAlgParams() method testing.
-     */
-    public void testGetSigAlgParams() {
-        if (this.cert == null) {
-            // The requested certificate type is not available.
-            // Test can not be applied.
-            return;
-        }
-        assertTrue("The byte array with encoded algorithm parameters "
-                + "is not correct.", Arrays.equals(tbt_cert.getSigAlgParams(),
-                                                    cert.getSigAlgParams()));
-    }
-
-    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 org.apache.harmony.security.tests.javax.security.cert;
+
+import java.io.ByteArrayInputStream;
+import java.security.cert.CertificateFactory;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.security.cert.CertificateEncodingException;
+import javax.security.cert.CertificateException;
+import javax.security.cert.CertificateExpiredException;
+import javax.security.cert.CertificateNotYetValidException;
+import javax.security.cert.X509Certificate;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+
+/**
+ */
+
+public class X509CertificateTest extends TestCase {
+
+    // Testing data was generated by using of classes 
+    // from org.apache.harmony.security.asn1 package encoded
+    // by org.apache.harmony.misc.Base64 class.
+
+    private static String base64cert = 
+        "-----BEGIN CERTIFICATE-----\n" +
+        "MIIC+jCCAragAwIBAgICAiswDAYHKoZIzjgEAwEBADAdMRswGQYDVQQKExJDZXJ0a" +
+        "WZpY2F0ZSBJc3N1ZXIwIhgPMTk3MDAxMTIxMzQ2NDBaGA8xOTcwMDEyNDAzMzMyMF" +
+        "owHzEdMBsGA1UEChMUU3ViamVjdCBPcmdhbml6YXRpb24wGTAMBgcqhkjOOAQDAQE" +
+        "AAwkAAQIDBAUGBwiBAgCqggIAVaOCAhQwggIQMA8GA1UdDwEB/wQFAwMBqoAwEgYD" +
+        "VR0TAQH/BAgwBgEB/wIBBTAUBgNVHSABAf8ECjAIMAYGBFUdIAAwZwYDVR0RAQH/B" +
+        "F0wW4EMcmZjQDgyMi5OYW1lggdkTlNOYW1lpBcxFTATBgNVBAoTDE9yZ2FuaXphdG" +
+        "lvboYaaHR0cDovL3VuaWZvcm0uUmVzb3VyY2UuSWSHBP///wCIByoDolyDsgMwDAY" +
+        "DVR0eAQH/BAIwADAMBgNVHSQBAf8EAjAAMIGZBgNVHSUBAf8EgY4wgYsGBFUdJQAG" +
+        "CCsGAQUFBwMBBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMDBggrBgEFBQcDB" +
+        "AYIKwYBBQUHAwUGCCsGAQUFBwMGBggrBgEFBQcDBwYIKwYBBQUHAwgGCCsGAQUFBw" +
+        "MJBggrBgEFBQgCAgYKKwYBBAGCNwoDAwYJYIZIAYb4QgQBMA0GA1UdNgEB/wQDAgE" +
+        "BMA4GBCpNhgkBAf8EAwEBATBkBgNVHRIEXTBbgQxyZmNAODIyLk5hbWWCB2ROU05h" +
+        "bWWkFzEVMBMGA1UEChMMT3JnYW5pemF0aW9uhhpodHRwOi8vdW5pZm9ybS5SZXNvd" +
+        "XJjZS5JZIcE////AIgHKgOiXIOyAzAJBgNVHR8EAjAAMAoGA1UdIwQDAQEBMAoGA1" +
+        "UdDgQDAQEBMAoGA1UdIQQDAQEBMAwGByqGSM44BAMBAQADMAAwLQIUAL4QvoazNWP" +
+        "7jrj84/GZlhm09DsCFQCBKGKCGbrP64VtUt4JPmLjW1VxQA==\n" +
+        "-----END CERTIFICATE-----"; 
+
+    private java.security.cert.X509Certificate cert;
+    private javax.security.cert.X509Certificate tbt_cert;
+
+    protected void setUp() throws Exception {
+        try {
+            ByteArrayInputStream bais =
+                new ByteArrayInputStream(base64cert.getBytes());
+
+            CertificateFactory cf = CertificateFactory.getInstance("X.509");
+            this.cert = (java.security.cert.X509Certificate)
+                                                cf.generateCertificate(bais);
+            this.tbt_cert = X509Certificate.getInstance(cert.getEncoded());
+        } catch (java.security.cert.CertificateException e) {
+            // The requested certificate type is not available.
+            // Test pass..
+            this.cert = null;
+        } catch (javax.security.cert.CertificateException e) {
+            // The requested certificate type is not available.
+            // Test pass..
+            this.cert = null;
+        }
+    }
+
+    /**
+     * getInstance(InputStream inStream) method testing.
+     */
+    public void testGetInstance1() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        try {
+            ByteArrayInputStream bais =
+                new ByteArrayInputStream(cert.getEncoded());
+
+            X509Certificate.getInstance(bais);
+        } catch (java.security.cert.CertificateEncodingException e) {
+            e.printStackTrace();
+            fail("Unexpected CertificateEncodingException was thrown.");
+        } catch (CertificateEncodingException e) {
+            e.printStackTrace();
+            fail("Unexpected CertificateEncodingException was thrown.");
+        } catch (CertificateException e) {
+            // The requested certificate type is not available.
+            // Test pass..
+        }
+    }
+
+    /**
+     * getInstance(byte[] certData) method testing.
+     */
+    public void testGetInstance2() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        try {
+            X509Certificate.getInstance(cert.getEncoded());
+        } catch (java.security.cert.CertificateEncodingException e) {
+            e.printStackTrace();
+            fail("Unexpected CertificateEncodingException was thrown.");
+        } catch (CertificateException e) {
+            // The requested certificate type is not available.
+            // Test pass..
+        }
+    }
+
+    /**
+     * checkValidity() method testing.
+     */
+    public void testCheckValidity1() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        Date date = new Date();
+        Date nb_date = tbt_cert.getNotBefore();
+        Date na_date = tbt_cert.getNotAfter();
+        try {
+            tbt_cert.checkValidity();
+            assertFalse("CertificateExpiredException expected",
+                                            date.compareTo(na_date) > 0);
+            assertFalse("CertificateNotYetValidException expected",
+                                            date.compareTo(nb_date) < 0);
+        } catch (CertificateExpiredException e) {
+            assertTrue("Unexpected CertificateExpiredException was thrown",
+                                            date.compareTo(na_date) > 0);
+        } catch (CertificateNotYetValidException e) {
+            assertTrue("Unexpected CertificateNotYetValidException was thrown",
+                                            date.compareTo(nb_date) < 0);
+        }
+    }
+
+    /**
+     * checkValidity(Date date) method testing.
+     */
+    public void testCheckValidity2() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        Date[] date = new Date[4];
+        Calendar calendar = Calendar.getInstance();
+        for (int i=0; i<date.length; i++) {
+            calendar.set(i*50, Calendar.JANUARY, 1);
+            date[i] = calendar.getTime();
+        }
+        Date nb_date = tbt_cert.getNotBefore();
+        Date na_date = tbt_cert.getNotAfter();
+        for (int i=0; i<date.length; i++) {
+            try {
+                tbt_cert.checkValidity(date[i]);
+                assertFalse("CertificateExpiredException expected",
+                                                date[i].compareTo(na_date) > 0);
+                assertFalse("CertificateNotYetValidException expected",
+                                                date[i].compareTo(nb_date) < 0);
+            } catch (CertificateExpiredException e) {
+                assertTrue("Unexpected CertificateExpiredException was thrown",
+                                                date[i].compareTo(na_date) > 0);
+            } catch (CertificateNotYetValidException e) {
+                assertTrue("Unexpected CertificateNotYetValidException "
+                                + "was thrown", date[i].compareTo(nb_date) < 0);
+            }
+        }
+    }
+
+    /**
+     * getVersion() method testing.
+     */
+    public void testGetVersion() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        assertEquals("The version is not correct.",
+                                                tbt_cert.getVersion(), 2);
+    }
+
+    /**
+     * getSerialNumber() method testing.
+     */
+    public void testGetSerialNumber() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        assertEquals("The serial number is not correct.",
+                            tbt_cert.getSerialNumber(), cert.getSerialNumber());
+    }
+
+    /**
+     * getIssuerDN() method testing.
+     */
+    public void testGetIssuerDN() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        assertEquals("The issuer DN is not correct.",
+                                    tbt_cert.getIssuerDN(), cert.getIssuerDN());
+    }
+
+    /**
+     * getSubjectDN() method testing.
+     */
+    public void testGetSubjectDN() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        assertEquals("The subject DN is not correct.",
+                                tbt_cert.getSubjectDN(), cert.getSubjectDN());
+    }
+
+    /**
+     * getNotBefore() method testing.
+     */
+    public void testGetNotBefore() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        assertEquals("The NotBefore date is not correct.",
+                                tbt_cert.getNotBefore(), cert.getNotBefore());
+    }
+
+    /**
+     * getNotAfter() method testing.
+     */
+    public void testGetNotAfter() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        assertEquals("The NotAfter date is not correct.",
+                                tbt_cert.getNotAfter(), cert.getNotAfter());
+    }
+
+    /**
+     * getSigAlgName() method testing.
+     */
+    public void testGetSigAlgName() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        assertEquals("The name of signature algorithm is not correct.",
+                                tbt_cert.getSigAlgName(), cert.getSigAlgName());
+    }
+
+    /**
+     * getSigAlgOID() method testing.
+     */
+    public void testGetSigAlgOID() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        assertEquals("The name of OID of signature algorithm is not correct.",
+                                tbt_cert.getSigAlgOID(), cert.getSigAlgOID());
+    }
+
+    /**
+     * getSigAlgParams() method testing.
+     */
+    public void testGetSigAlgParams() {
+        if (this.cert == null) {
+            // The requested certificate type is not available.
+            // Test can not be applied.
+            return;
+        }
+        assertTrue("The byte array with encoded algorithm parameters "
+                + "is not correct.", Arrays.equals(tbt_cert.getSigAlgParams(),
+                                                    cert.getSigAlgParams()));
+    }
+
+    public static Test suite() {
+        return new TestSuite(X509CertificateTest.class);
+    }
+
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(suite());
+    }
+}
+

Modified: 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=415555&r1=415554&r2=415555&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/CodeSource_ImplTest.java Tue Jun 20 01:11:04 2006
@@ -1,210 +1,222 @@
-/*
- *  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();
-        }
-    }
-
-}
+/*
+ *  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();
+        }
+    }
+    
+
+    /**
+     * @tests java.security.CodeSource#toString()
+     */
+    public void test_toString() throws Exception {
+        // Test for method java.lang.String java.security.CodeSource.toString()
+        CodeSource cs = new CodeSource(new java.net.URL("file:///test"),
+                (Certificate[]) null);
+        assertEquals("toString did not return expected value.",
+                "CodeSource, url=file:/test, <no certificates>", cs.toString());
+    }
+
+}



Mime
View raw message