Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 46861 invoked from network); 20 Jun 2006 08:12:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Jun 2006 08:12:22 -0000 Received: (qmail 12365 invoked by uid 500); 20 Jun 2006 08:12:20 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 12280 invoked by uid 500); 20 Jun 2006 08:12:19 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 11878 invoked by uid 99); 20 Jun 2006 08:12:16 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jun 2006 01:12:16 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jun 2006 01:12:12 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id C016B1A984E; Tue, 20 Jun 2006 01:11:51 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r415555 [5/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 -0000 To: harmony-commits@incubator.apache.org From: mloenko@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060620081151.C016B1A984E@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidator3Test.java (from r414728, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertPathValidator3Test.java) URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidator3Test.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidator3Test.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertPathValidator3Test.java&r1=414728&r2=415555&rev=415555&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertPathValidator3Test.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidator3Test.java Tue Jun 20 01:11:04 2006 @@ -1,117 +1,123 @@ -/* - * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** -* @author Vera Y. Petrashkova -* @version $Revision$ -*/ - -package java.security.cert; - - -import java.security.InvalidAlgorithmParameterException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Provider; - -import org.apache.harmony.security.tests.support.SpiEngUtils; -import org.apache.harmony.security.tests.support.cert.MyCertPath; -import org.apache.harmony.security.tests.support.cert.TestUtils; - -import junit.framework.TestCase; - -/** - * Tests for CertPathValidator class methods. - * - */ - -public class CertPathValidator3Test extends TestCase { - - /** - * Constructor for CertPathValidatorTests. - * @param name - */ - public CertPathValidator3Test(String name) { - super(name); - } - private static final String defaultType = CertPathBuilder1Test.defaultType; - - private static boolean PKIXSupport = false; - - private static Provider defaultProvider; - private static String defaultProviderName; - - private static String NotSupportMsg = ""; - - static { - defaultProvider = SpiEngUtils.isSupport(defaultType, - CertPathValidator1Test.srvCertPathValidator); - PKIXSupport = (defaultProvider != null); - defaultProviderName = (PKIXSupport ? defaultProvider.getName() : null); - NotSupportMsg = defaultType.concat(" is not supported"); - } - - private static CertPathValidator[] createCPVs() { - if (!PKIXSupport) { - fail(NotSupportMsg); - return null; - } - try { - CertPathValidator[] certPVs = new CertPathValidator[3]; - certPVs[0] = CertPathValidator.getInstance(defaultType); - certPVs[1] = CertPathValidator.getInstance(defaultType, - defaultProviderName); - certPVs[2] = CertPathValidator.getInstance(defaultType, - defaultProvider); - return certPVs; - } catch (Exception e) { - return null; - } - } - /** - * Test for validate(CertPath certpath, CertPathParameters params) method - * Assertion: throws InvalidAlgorithmParameterException - * when params is instance of PKIXParameters and - * certpath is not X.509 type - * - * FIXME: jrockit-j2re1.4.2_04 throws NullPointerException when certPath is null - */ - public void testValidate01() - throws NoSuchAlgorithmException, NoSuchProviderException, - CertPathValidatorException, InvalidAlgorithmParameterException { - if (!PKIXSupport) { - fail(NotSupportMsg); - return; - } - MyCertPath mCP = new MyCertPath(new byte[0]); - CertPathParameters params = new PKIXParameters(TestUtils.getTrustAnchorSet()); - CertPathValidator [] certPV = createCPVs(); - assertNotNull("CertPathValidator objects were not created", certPV); - for (int i = 0; i < certPV.length; i++) { - try { - certPV[i].validate(mCP, null); - fail("InvalidAlgorithmParameterException must be thrown"); - } catch(InvalidAlgorithmParameterException e) { - } - try { - certPV[i].validate(null, params); - fail("NullPointerException must be thrown"); - } catch(NullPointerException 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.java.security.cert; + + +import java.security.InvalidAlgorithmParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.cert.CertPathParameters; +import java.security.cert.CertPathValidator; +import java.security.cert.CertPathValidatorException; +import java.security.cert.PKIXParameters; + +import org.apache.harmony.security.tests.java.security.cert.CertPathBuilder1Test; +import org.apache.harmony.security.tests.java.security.cert.CertPathValidator1Test; +import org.apache.harmony.security.tests.support.SpiEngUtils; +import org.apache.harmony.security.tests.support.cert.MyCertPath; +import org.apache.harmony.security.tests.support.cert.TestUtils; + +import junit.framework.TestCase; + +/** + * Tests for CertPathValidator class methods. + * + */ + +public class CertPathValidator3Test extends TestCase { + + /** + * Constructor for CertPathValidatorTests. + * @param name + */ + public CertPathValidator3Test(String name) { + super(name); + } + private static final String defaultType = CertPathBuilder1Test.defaultType; + + private static boolean PKIXSupport = false; + + private static Provider defaultProvider; + private static String defaultProviderName; + + private static String NotSupportMsg = ""; + + static { + defaultProvider = SpiEngUtils.isSupport(defaultType, + CertPathValidator1Test.srvCertPathValidator); + PKIXSupport = (defaultProvider != null); + defaultProviderName = (PKIXSupport ? defaultProvider.getName() : null); + NotSupportMsg = defaultType.concat(" is not supported"); + } + + private static CertPathValidator[] createCPVs() { + if (!PKIXSupport) { + fail(NotSupportMsg); + return null; + } + try { + CertPathValidator[] certPVs = new CertPathValidator[3]; + certPVs[0] = CertPathValidator.getInstance(defaultType); + certPVs[1] = CertPathValidator.getInstance(defaultType, + defaultProviderName); + certPVs[2] = CertPathValidator.getInstance(defaultType, + defaultProvider); + return certPVs; + } catch (Exception e) { + return null; + } + } + /** + * Test for validate(CertPath certpath, CertPathParameters params) method + * Assertion: throws InvalidAlgorithmParameterException + * when params is instance of PKIXParameters and + * certpath is not X.509 type + * + * FIXME: jrockit-j2re1.4.2_04 throws NullPointerException when certPath is null + */ + public void testValidate01() + throws NoSuchAlgorithmException, NoSuchProviderException, + CertPathValidatorException, InvalidAlgorithmParameterException { + if (!PKIXSupport) { + fail(NotSupportMsg); + return; + } + MyCertPath mCP = new MyCertPath(new byte[0]); + CertPathParameters params = new PKIXParameters(TestUtils.getTrustAnchorSet()); + CertPathValidator [] certPV = createCPVs(); + assertNotNull("CertPathValidator objects were not created", certPV); + for (int i = 0; i < certPV.length; i++) { + try { + certPV[i].validate(mCP, null); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch(InvalidAlgorithmParameterException e) { + } + try { + certPV[i].validate(null, params); + fail("NullPointerException must be thrown"); + } catch(NullPointerException e) { + } + } + } + +} Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidatorExceptionTest.java (from r414728, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertPathValidatorExceptionTest.java) URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidatorExceptionTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidatorExceptionTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertPathValidatorExceptionTest.java&r1=414728&r2=415555&rev=415555&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertPathValidatorExceptionTest.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidatorExceptionTest.java Tue Jun 20 01:11:04 2006 @@ -1,404 +1,442 @@ -/* - * 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 java.security.cert; - -import java.security.cert.CertPathValidatorException; -import java.security.cert.CertPath; - -import junit.framework.TestCase; - - -/** - * Tests for CertPathValidatorException class constructors and - * methods. - * - */ -public class CertPathValidatorExceptionTest extends TestCase { - - public static void main(String[] args) { - } - - /** - * Constructor for CertPathValidatorExceptionTests. - * - * @param arg0 - */ - public CertPathValidatorExceptionTest(String arg0) { - super(arg0); - } - - private static String[] msgs = { - "", - "Check new message", - "Check new message Check new message Check new message Check new message Check new message" }; - - private static Throwable tCause = new Throwable("Throwable for exception"); - - static String createErr(Exception tE, Exception eE) { - return "CertPathValidatorException: ".concat(tE.toString()).concat( - " is not equal to caught exception: ").concat(eE.toString()); - } - - /** - * Test for CertPathValidatorException() constructor - * Assertion: constructs CertPathValidatorException with no detail message - */ - public void testCertPathValidatorException01() { - CertPathValidatorException tE = new CertPathValidatorException(); - 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 CertPathValidatorException(String) constructor - * Assertion: constructs CertPathValidatorException with detail message msg. - * Parameter msg is not null. - */ - public void testCertPathValidatorException02() { - CertPathValidatorException tE; - for (int i = 0; i < msgs.length; i++) { - tE = new CertPathValidatorException(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 CertPathValidatorException(String) constructor - * Assertion: constructs CertPathValidatorException when msg - * is null - */ - public void testCertPathValidatorException03() { - String msg = null; - CertPathValidatorException tE = new CertPathValidatorException(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)); - } - } - - /** - * Test for CertPathValidatorException(Throwable) constructor - * Assertion: constructs CertPathValidatorException when cause - * is null - */ - public void testCertPathValidatorException04() { - Throwable cause = null; - CertPathValidatorException tE = new CertPathValidatorException(cause); - 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 CertPathValidatorException(Throwable) constructor - * Assertion: constructs CertPathValidatorException when cause - * is not null - */ - public void testCertPathValidatorException05() { - CertPathValidatorException tE = new CertPathValidatorException(tCause); - if (tE.getMessage() != null) { - String toS = tCause.toString(); - String getM = tE.getMessage(); - assertTrue("getMessage() should contain ".concat(toS), (getM - .indexOf(toS) != -1)); - } - assertNotNull("getCause() must not return null", tE.getCause()); - assertEquals("getCause() must return ".concat(tCause.toString()), tE - .getCause(), tCause); - try { - throw tE; - } catch (Exception e) { - assertTrue(createErr(tE, e), tE.equals(e)); - } - } - - /** - * Test for CertPathValidatorException(String, Throwable) - * constructor Assertion: constructs CertPathValidatorException when - * cause is null msg is null - */ - public void testCertPathValidatorException06() { - CertPathValidatorException tE = new CertPathValidatorException(null, - null); - 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 CertPathValidatorException(String, Throwable) - * constructor Assertion: constructs CertPathValidatorException when - * cause is null msg is not null - */ - public void testCertPathValidatorException07() { - CertPathValidatorException tE; - for (int i = 0; i < msgs.length; i++) { - tE = new CertPathValidatorException(msgs[i], null); - 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 CertPathValidatorException(String, Throwable) - * constructor Assertion: constructs CertPathValidatorException when - * cause is not null msg is null - */ - public void testCertPathValidatorException08() { - CertPathValidatorException tE = new CertPathValidatorException(null, - tCause); - if (tE.getMessage() != null) { - String toS = tCause.toString(); - String getM = tE.getMessage(); - assertTrue("getMessage() must should ".concat(toS), (getM - .indexOf(toS) != -1)); - } - assertNotNull("getCause() must not return null", tE.getCause()); - assertEquals("getCause() must return ".concat(tCause.toString()), tE - .getCause(), tCause); - try { - throw tE; - } catch (Exception e) { - assertTrue(createErr(tE, e), tE.equals(e)); - } - } - - /** - * Test for CertPathValidatorException(String, Throwable) - * constructor Assertion: constructs CertPathValidatorException when - * cause is not null msg is not null - */ - public void testCertPathValidatorException09() { - CertPathValidatorException tE; - for (int i = 0; i < msgs.length; i++) { - tE = new CertPathValidatorException(msgs[i], tCause); - String getM = tE.getMessage(); - String toS = tCause.toString(); - if (msgs[i].length() > 0) { - assertTrue("getMessage() must contain ".concat(msgs[i]), getM - .indexOf(msgs[i]) != -1); - if (!getM.equals(msgs[i])) { - assertTrue("getMessage() should contain ".concat(toS), getM - .indexOf(toS) != -1); - } - } - assertNotNull("getCause() must not return null", tE.getCause()); - assertEquals("getCause() must return ".concat(tCause.toString()), - tE.getCause(), tCause); - - try { - throw tE; - } catch (Exception e) { - assertTrue(createErr(tE, e), tE.equals(e)); - } - } - } - - /** - * Test for - * CertPathValidatorException(String, Throwable, CertPath, int) - * constructor Assertion: constructs CertPathValidatorException when - * cause is null msg is null - * certPath is null index is -1 - */ - public void testCertPathValidatorException10() { - CertPathValidatorException tE = new CertPathValidatorException(null, - null, null, -1); - assertNull("getMessage() must return null", tE.getMessage()); - assertNull("getCause() must return null", tE.getCause()); - assertNull("getCertPath() must return null", tE.getCertPath()); - assertEquals("getIndex() must be -1", tE.getIndex(), -1); - try { - throw tE; - } catch (Exception e) { - assertTrue(createErr(tE, e), tE.equals(e)); - } - } - - /** - * Test for - * CertPathValidatorException(String, Throwable, CertPath, int) - * constructor Assertion: constructs CertPathValidatorException when - * cause is null msg is null - * certPath is null index not -1 throws: - * IllegalArgumentException - */ - public void testCertPathValidatorException11() { - int[] indx = { 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE }; - for (int j = 0; j < indx.length; j++) { - for (int i = 0; i < msgs.length; i++) { - try { - new CertPathValidatorException(msgs[i], tCause, null, indx[j]); - fail("Error. IllegalArgumentException was not thrown as expected. " - + " msg: " - + msgs[i] - + ", certPath is null and index is " + indx[j]); - } catch (IllegalArgumentException e) { - } - } - } - } - - /** - * Test for - * CertPathValidatorException(String, Throwable, CertPath, int) - * constructor Assertion: constructs CertPathValidatorException when - * cause not null msg not null - * certPath is null index is -1 - */ - public void testCertPathValidatorException12() { - CertPathValidatorException tE; - - for (int i = 0; i < msgs.length; i++) { - try { - tE = new CertPathValidatorException(msgs[i], tCause, null, -1); - String getM = tE.getMessage(); - String toS = tCause.toString(); - if (msgs[i].length() > 0) { - assertTrue("getMessage() must contain ".concat(msgs[i]), - getM.indexOf(msgs[i]) != -1); - if (!getM.equals(msgs[i])) { - assertTrue("getMessage() should contain ".concat(toS), - getM.indexOf(toS) != -1); - } - } - assertNotNull("getCause() must not return null", tE.getCause()); - assertEquals("getCause() must return " - .concat(tCause.toString()), tE.getCause(), tCause); - assertNull("getCertPath() must return null", tE.getCertPath()); - assertEquals("getIndex() must return -1", tE.getIndex(), -1); - try { - throw tE; - } catch (Exception e) { - assertTrue(createErr(tE, e), tE.equals(e)); - } - } catch (IndexOutOfBoundsException e) { - fail("Unexpected exception: " + e.toString() - + " Parameters: msg: " + msgs[i] - + ", certPath is null and index is -1"); - } - } - } - - /** - * Test for - * CertPathValidatorException(String, Throwable, CertPath, int) - * constructor Assertion: constructs CertPathValidatorException when - * cause not null msg not null - * certPath not null index< -1 || >= - * certPath.getCertificates().size() throws: IndexOutOfBoundsException - */ - public void testCertPathValidatorException13() { - myCertPath mcp = new myCertPath("X.509", ""); - CertPath cp = mcp.get("X.509"); - int[] indx = { -2, -100, 0, 1, 100, Integer.MAX_VALUE, - Integer.MIN_VALUE }; - for (int j = 0; j < indx.length; j++) { - for (int i = 0; i < msgs.length; i++) { - try { - new CertPathValidatorException(msgs[i], tCause, cp, indx[j]); - fail("IndexOutOfBoundsException was not thrown as expected. " - + " msg: " - + msgs[i] - + ", certPath is null and index is " + indx[j]); - } catch (IndexOutOfBoundsException e) { - } - } - } - } - - /** - * Test for - * CertPathValidatorException(String, Throwable, CertPath, int) - * constructor Assertion: constructs CertPathValidatorException when - * cause not null msg not null - * certPath not null index< - * certPath.getCertificates().size() - */ - public void testCertPathValidatorException14() { - CertPathValidatorException tE; - myCertPath mcp = new myCertPath("X.509", ""); - CertPath cp = mcp.get("X.509"); - for (int i = 0; i < msgs.length; i++) { - try { - tE = new CertPathValidatorException(msgs[i], tCause, cp, -1); - String getM = tE.getMessage(); - String toS = tCause.toString(); - if (msgs[i].length() > 0) { - assertTrue("getMessage() must contain ".concat(msgs[i]), - getM.indexOf(msgs[i]) != -1); - if (!getM.equals(msgs[i])) { - assertTrue("getMessage() should contain ".concat(toS), - getM.indexOf(toS) != -1); - } - } - assertNotNull("getCause() must not return null", tE.getCause()); - assertEquals("getCause() must return " - .concat(tCause.toString()), tE.getCause(), tCause); - assertNotNull("getCertPath() must not return null", tE - .getCertPath()); - assertEquals( - "getCertPath() must return ".concat(cp.toString()), tE - .getCertPath(), cp); - assertEquals("getIndex() must return -1", tE.getIndex(), -1); - try { - throw tE; - } catch (Exception e) { - assertTrue(createErr(tE, e), tE.equals(e)); - } - - } catch (IndexOutOfBoundsException e) { - fail("Unexpected IndexOutOfBoundsException was thrown. " - + e.toString()); - } - } - } -} +/* + * 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.cert; + +import java.security.cert.CertPathValidatorException; +import java.security.cert.CertPath; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; +import java.util.Vector; + +import junit.framework.TestCase; + + +/** + * Tests for CertPathValidatorException class constructors and + * methods. + * + */ +public class CertPathValidatorExceptionTest extends TestCase { + + public static void main(String[] args) { + } + + /** + * Constructor for CertPathValidatorExceptionTests. + * + * @param arg0 + */ + public CertPathValidatorExceptionTest(String arg0) { + super(arg0); + } + + private static String[] msgs = { + "", + "Check new message", + "Check new message Check new message Check new message Check new message Check new message" }; + + private static Throwable tCause = new Throwable("Throwable for exception"); + + static String createErr(Exception tE, Exception eE) { + return "CertPathValidatorException: ".concat(tE.toString()).concat( + " is not equal to caught exception: ").concat(eE.toString()); + } + + /** + * Test for CertPathValidatorException() constructor + * Assertion: constructs CertPathValidatorException with no detail message + */ + public void testCertPathValidatorException01() { + CertPathValidatorException tE = new CertPathValidatorException(); + 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 CertPathValidatorException(String) constructor + * Assertion: constructs CertPathValidatorException with detail message msg. + * Parameter msg is not null. + */ + public void testCertPathValidatorException02() { + CertPathValidatorException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathValidatorException(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 CertPathValidatorException(String) constructor + * Assertion: constructs CertPathValidatorException when msg + * is null + */ + public void testCertPathValidatorException03() { + String msg = null; + CertPathValidatorException tE = new CertPathValidatorException(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)); + } + } + + /** + * Test for CertPathValidatorException(Throwable) constructor + * Assertion: constructs CertPathValidatorException when cause + * is null + */ + public void testCertPathValidatorException04() { + Throwable cause = null; + CertPathValidatorException tE = new CertPathValidatorException(cause); + 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 CertPathValidatorException(Throwable) constructor + * Assertion: constructs CertPathValidatorException when cause + * is not null + */ + public void testCertPathValidatorException05() { + CertPathValidatorException tE = new CertPathValidatorException(tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() should contain ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + try { + throw tE; + } catch (Exception e) { + assertTrue(createErr(tE, e), tE.equals(e)); + } + } + + /** + * Test for CertPathValidatorException(String, Throwable) + * constructor Assertion: constructs CertPathValidatorException when + * cause is null msg is null + */ + public void testCertPathValidatorException06() { + CertPathValidatorException tE = new CertPathValidatorException(null, + null); + 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 CertPathValidatorException(String, Throwable) + * constructor Assertion: constructs CertPathValidatorException when + * cause is null msg is not null + */ + public void testCertPathValidatorException07() { + CertPathValidatorException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathValidatorException(msgs[i], null); + 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 CertPathValidatorException(String, Throwable) + * constructor Assertion: constructs CertPathValidatorException when + * cause is not null msg is null + */ + public void testCertPathValidatorException08() { + CertPathValidatorException tE = new CertPathValidatorException(null, + tCause); + if (tE.getMessage() != null) { + String toS = tCause.toString(); + String getM = tE.getMessage(); + assertTrue("getMessage() must should ".concat(toS), (getM + .indexOf(toS) != -1)); + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), tE + .getCause(), tCause); + try { + throw tE; + } catch (Exception e) { + assertTrue(createErr(tE, e), tE.equals(e)); + } + } + + /** + * Test for CertPathValidatorException(String, Throwable) + * constructor Assertion: constructs CertPathValidatorException when + * cause is not null msg is not null + */ + public void testCertPathValidatorException09() { + CertPathValidatorException tE; + for (int i = 0; i < msgs.length; i++) { + tE = new CertPathValidatorException(msgs[i], tCause); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), getM + .indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), getM + .indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return ".concat(tCause.toString()), + tE.getCause(), tCause); + + try { + throw tE; + } catch (Exception e) { + assertTrue(createErr(tE, e), tE.equals(e)); + } + } + } + + /** + * Test for + * CertPathValidatorException(String, Throwable, CertPath, int) + * constructor Assertion: constructs CertPathValidatorException when + * cause is null msg is null + * certPath is null index is -1 + */ + public void testCertPathValidatorException10() { + CertPathValidatorException tE = new CertPathValidatorException(null, + null, null, -1); + assertNull("getMessage() must return null", tE.getMessage()); + assertNull("getCause() must return null", tE.getCause()); + assertNull("getCertPath() must return null", tE.getCertPath()); + assertEquals("getIndex() must be -1", tE.getIndex(), -1); + try { + throw tE; + } catch (Exception e) { + assertTrue(createErr(tE, e), tE.equals(e)); + } + } + + /** + * Test for + * CertPathValidatorException(String, Throwable, CertPath, int) + * constructor Assertion: constructs CertPathValidatorException when + * cause is null msg is null + * certPath is null index not -1 throws: + * IllegalArgumentException + */ + public void testCertPathValidatorException11() { + int[] indx = { 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE }; + for (int j = 0; j < indx.length; j++) { + for (int i = 0; i < msgs.length; i++) { + try { + new CertPathValidatorException(msgs[i], tCause, null, indx[j]); + fail("Error. IllegalArgumentException was not thrown as expected. " + + " msg: " + + msgs[i] + + ", certPath is null and index is " + indx[j]); + } catch (IllegalArgumentException e) { + } + } + } + } + + /** + * Test for + * CertPathValidatorException(String, Throwable, CertPath, int) + * constructor Assertion: constructs CertPathValidatorException when + * cause not null msg not null + * certPath is null index is -1 + */ + public void testCertPathValidatorException12() { + CertPathValidatorException tE; + + for (int i = 0; i < msgs.length; i++) { + try { + tE = new CertPathValidatorException(msgs[i], tCause, null, -1); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), + getM.indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), + getM.indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return " + .concat(tCause.toString()), tE.getCause(), tCause); + assertNull("getCertPath() must return null", tE.getCertPath()); + assertEquals("getIndex() must return -1", tE.getIndex(), -1); + try { + throw tE; + } catch (Exception e) { + assertTrue(createErr(tE, e), tE.equals(e)); + } + } catch (IndexOutOfBoundsException e) { + fail("Unexpected exception: " + e.toString() + + " Parameters: msg: " + msgs[i] + + ", certPath is null and index is -1"); + } + } + } + + /** + * Test for + * CertPathValidatorException(String, Throwable, CertPath, int) + * constructor Assertion: constructs CertPathValidatorException when + * cause not null msg not null + * certPath not null index< -1 || >= + * certPath.getCertificates().size() throws: IndexOutOfBoundsException + */ + public void testCertPathValidatorException13() { + myCertPath mcp = new myCertPath("X.509", ""); + CertPath cp = mcp.get("X.509"); + int[] indx = { -2, -100, 0, 1, 100, Integer.MAX_VALUE, + Integer.MIN_VALUE }; + for (int j = 0; j < indx.length; j++) { + for (int i = 0; i < msgs.length; i++) { + try { + new CertPathValidatorException(msgs[i], tCause, cp, indx[j]); + fail("IndexOutOfBoundsException was not thrown as expected. " + + " msg: " + + msgs[i] + + ", certPath is null and index is " + indx[j]); + } catch (IndexOutOfBoundsException e) { + } + } + } + } + + /** + * Test for + * CertPathValidatorException(String, Throwable, CertPath, int) + * constructor Assertion: constructs CertPathValidatorException when + * cause not null msg not null + * certPath not null index< + * certPath.getCertificates().size() + */ + public void testCertPathValidatorException14() { + CertPathValidatorException tE; + myCertPath mcp = new myCertPath("X.509", ""); + CertPath cp = mcp.get("X.509"); + for (int i = 0; i < msgs.length; i++) { + try { + tE = new CertPathValidatorException(msgs[i], tCause, cp, -1); + String getM = tE.getMessage(); + String toS = tCause.toString(); + if (msgs[i].length() > 0) { + assertTrue("getMessage() must contain ".concat(msgs[i]), + getM.indexOf(msgs[i]) != -1); + if (!getM.equals(msgs[i])) { + assertTrue("getMessage() should contain ".concat(toS), + getM.indexOf(toS) != -1); + } + } + assertNotNull("getCause() must not return null", tE.getCause()); + assertEquals("getCause() must return " + .concat(tCause.toString()), tE.getCause(), tCause); + assertNotNull("getCertPath() must not return null", tE + .getCertPath()); + assertEquals( + "getCertPath() must return ".concat(cp.toString()), tE + .getCertPath(), cp); + assertEquals("getIndex() must return -1", tE.getIndex(), -1); + try { + throw tE; + } catch (Exception e) { + assertTrue(createErr(tE, e), tE.equals(e)); + } + + } catch (IndexOutOfBoundsException e) { + fail("Unexpected IndexOutOfBoundsException was thrown. " + + e.toString()); + } + } + } + + class myCertPath extends CertPath { + + public List getCertificates() { + return new Vector(); + } + + public byte[] getEncoded() { + return new byte[0]; + } + + public byte[] getEncoded(String s) { + return new byte[0]; + } + + public Iterator getEncodings() { + return (Iterator) (new StringTokenizer("ss ss ss ss")); + } + + protected myCertPath(String s) { + super(s); + } + + public CertPath get(String s) { + return new myCertPath(s); + } + + public myCertPath(String s, String s1) { + super(s); + } + + } +} + + Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidatorSpiTest.java (from r414728, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertPathValidatorSpiTest.java) URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidatorSpiTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidatorSpiTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertPathValidatorSpiTest.java&r1=414728&r2=415555&rev=415555&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertPathValidatorSpiTest.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertPathValidatorSpiTest.java Tue Jun 20 01:11:04 2006 @@ -1,66 +1,74 @@ -/* - * 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 java.security.cert; - -import junit.framework.TestCase; -import java.security.InvalidAlgorithmParameterException; - -/** - * Tests for CertPathValidatorSpi class constructors and methods. - * - */ - -public class CertPathValidatorSpiTest extends TestCase { - - /** - * Constructor for CertPathValidatorSpiTest. - * - * @param arg0 - */ - public CertPathValidatorSpiTest(String arg0) { - super(arg0); - } - - /** - * Test for CertPathValidatorSpi constructor Assertion: - * constructs CertPathValidatorSpi - */ - public void testCertPathValidatorSpi01() throws CertPathValidatorException, - InvalidAlgorithmParameterException { - CertPathValidatorSpi certPathValid = new MyCertPathValidatorSpi(); - CertPathParameters params = null; - CertPath certPath = null; - CertPathValidatorResult cpvResult = certPathValid.engineValidate( - certPath, params); - assertNull("Not null CertPathValidatorResult", cpvResult); - try { - certPathValid.engineValidate(certPath, params); - fail("CertPathValidatorException must be thrown"); - } catch (CertPathValidatorException e) { - } - try { - certPathValid.engineValidate(certPath, params); - fail("InvalidAlgorithmParameterException must be thrown"); - } catch (InvalidAlgorithmParameterException 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.java.security.cert; + +import java.security.InvalidAlgorithmParameterException; +import java.security.cert.CertPath; +import java.security.cert.CertPathParameters; +import java.security.cert.CertPathValidatorException; +import java.security.cert.CertPathValidatorResult; +import java.security.cert.CertPathValidatorSpi; + +import org.apache.harmony.security.tests.support.cert.MyCertPathValidatorSpi; + +import junit.framework.TestCase; + +/** + * Tests for CertPathValidatorSpi class constructors and methods. + * + */ + +public class CertPathValidatorSpiTest extends TestCase { + + /** + * Constructor for CertPathValidatorSpiTest. + * + * @param arg0 + */ + public CertPathValidatorSpiTest(String arg0) { + super(arg0); + } + + /** + * Test for CertPathValidatorSpi constructor Assertion: + * constructs CertPathValidatorSpi + */ + public void testCertPathValidatorSpi01() throws CertPathValidatorException, + InvalidAlgorithmParameterException { + CertPathValidatorSpi certPathValid = new MyCertPathValidatorSpi(); + CertPathParameters params = null; + CertPath certPath = null; + CertPathValidatorResult cpvResult = certPathValid.engineValidate( + certPath, params); + assertNull("Not null CertPathValidatorResult", cpvResult); + try { + certPathValid.engineValidate(certPath, params); + fail("CertPathValidatorException must be thrown"); + } catch (CertPathValidatorException e) { + } + try { + certPathValid.engineValidate(certPath, params); + fail("InvalidAlgorithmParameterException must be thrown"); + } catch (InvalidAlgorithmParameterException e) { + } + } } Copied: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertStore1Test.java (from r414728, incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertStore1Test.java) URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertStore1Test.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertStore1Test.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertStore1Test.java&r1=414728&r2=415555&rev=415555&view=diff ============================================================================== --- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java.injected/java/security/cert/CertStore1Test.java (original) +++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/cert/CertStore1Test.java Tue Jun 20 01:11:04 2006 @@ -1,508 +1,418 @@ -/* - * 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 java.security.cert; - -import java.security.InvalidAlgorithmParameterException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Provider; -import java.security.Security; -import java.util.Collection; - -import org.apache.harmony.security.tests.support.SpiEngUtils; - -import junit.framework.TestCase; - - - -/** - * Tests for CertStore class constructors and - * methods. - * - */ - -public class CertStore1Test extends TestCase { - - /** - * Constructor for CertStoreTests. - * @param arg0 - */ - public CertStore1Test(String arg0) { - super(arg0); - } - public static final String srvCertStore = "CertStore"; - - private static final String defaultType = "LDAP"; - public static final String [] validValues = { - "LDAP", "ldap", "Ldap", "lDAP", "lDaP" }; - public static String [] validValuesC = null; - - private static String [] invalidValues = SpiEngUtils.invalidValues; - - private static boolean LDAPSupport = false; - private static final String CollectionType = "Collection"; - private static boolean CollectionSupport = false; - - private static Provider defaultProvider; - private static String defaultProviderName; - private static Provider defaultProviderCol; - private static String defaultProviderColName; - - private static String NotSupportMsg = ""; - - static { - defaultProvider = SpiEngUtils.isSupport(defaultType, - srvCertStore); - LDAPSupport = (defaultProvider != null); - defaultProviderName = (LDAPSupport ? defaultProvider.getName() : null); - NotSupportMsg = "LDAP and Collection algorithm are not supported"; - - defaultProviderCol = SpiEngUtils.isSupport(CollectionType, - srvCertStore); - CollectionSupport = (defaultProviderCol != null); - defaultProviderColName = (CollectionSupport ? defaultProviderCol.getName() : null); - if (CollectionSupport) { - validValuesC = new String[3]; - validValuesC[0] = CollectionType; - validValuesC[1] = CollectionType.toUpperCase(); - validValuesC[2] = CollectionType.toLowerCase(); - } - } - - private Provider dProv = null; - private String dName = null; - private String dType = null; - private CertStoreParameters dParams = null; - private String[] dValid; - - private boolean initParams() { - if (!LDAPSupport && !CollectionSupport) { - fail(NotSupportMsg); - return false; - } - dParams = (CollectionSupport ? (CertStoreParameters)new CollectionCertStoreParameters() : - (CertStoreParameters)new LDAPCertStoreParameters()); - dType = (CollectionSupport ? CollectionType : defaultType ); - dProv = (CollectionSupport ? defaultProviderCol : defaultProvider ); - dName = (CollectionSupport ? defaultProviderColName : defaultProviderName ); - dValid = (CollectionSupport ? validValuesC : validValues ); - return true; - } - private CertStore [] createCS() { - if (!LDAPSupport && !CollectionSupport) { - fail(NotSupportMsg); - return null; - } - try { - CertStore [] ss = new CertStore[3]; - ss[0] = CertStore.getInstance(dType, dParams); - ss[1] = CertStore.getInstance(dType, dParams, dProv); - ss[2] = CertStore.getInstance(dType, dParams, dName); - return ss; - } catch (Exception e) { - return null; - } - } - - - /** - * Test for getDefaultType() method - * Assertion: returns security property "certstore.type" or "LDAP" - */ - public void testCertStore01() { - if (!LDAPSupport) { - return; - } - String dt = CertStore.getDefaultType(); - String sn = Security.getProperty("certstore.type"); - String def = "Proba.cert.store.type"; - if (sn == null) { - sn = defaultType; - } - assertNotNull("Default type have not be null", dt); - assertEquals("Incorrect default type", dt, sn); - - Security.setProperty("certstore.type", def); - dt = CertStore.getDefaultType(); - assertEquals("Incorrect default type", dt, def); - Security.setProperty("certstore.type", sn); - assertEquals("Incorrect default type", Security.getProperty("certstore.type"), sn ); - } - /** - * Test for - * CertStore constructor - * Assertion: returns CertStore object - */ - - public void testCertStore02() throws NoSuchAlgorithmException, - InvalidAlgorithmParameterException, CertStoreException { - if (!initParams()) { - return; - } - MyCertStoreParameters pp = new MyCertStoreParameters(); - CertStoreSpi spi = new MyCertStoreSpi(pp); - CertStore certS = new myCertStore(spi, dProv, dType, pp); - assertEquals("Incorrect algorithm", certS.getType(), dType); - assertEquals("Incorrect provider", certS.getProvider(), dProv); - assertTrue("Incorrect parameters", certS.getCertStoreParameters() - instanceof MyCertStoreParameters); - try { - certS.getCertificates(null); - fail("CertStoreException must be thrown"); - } catch (CertStoreException e) { - } - certS = new myCertStore(null, null, null, null); - assertNull("Incorrect algorithm", certS.getType()); - assertNull("Incorrect provider", certS.getProvider()); - assertNull("Incorrect parameters", certS.getCertStoreParameters()); - try { - certS.getCertificates(null); - fail("NullPointerException must be thrown"); - } catch (NullPointerException e) { - } - } - - /** - * Test for getInstance(String type, CertStoreParameters params) method - * Assertion: - * throws NullPointerException when type is null - * throws NoSuchAlgorithmException when type is incorrect; - */ - public void testCertStore03() throws InvalidAlgorithmParameterException { - if (!initParams()) { - return; - } - try { - CertStore.getInstance(null, dParams); - fail("NullPointerException or NoSuchAlgorithmException must be thrown when type is null"); - } catch (NullPointerException e) { - } catch (NoSuchAlgorithmException e) { - } - for (int i = 0; i < invalidValues.length; i++ ) { - try { - CertStore.getInstance(invalidValues[i], dParams); - fail("NoSuchAlgorithmException must be thrown"); - } catch (NoSuchAlgorithmException e) { - } - } - } - /** - * Test for getInstance(String type, CertStoreParameters params) method - * Assertion: throws InvalidAlgorithmParameterException when params is not LDAP - * or null - */ - public void testCertStore04() throws NoSuchAlgorithmException { - if (!initParams()) { - return; - } - CertStoreParameters paramsNull = null; - CertStoreParameters paramsContr = null; - if (CollectionSupport) { - if (LDAPSupport) { - paramsContr = new LDAPCertStoreParameters(); - } - } - for (int i = 0; i < dValid.length; i++ ) { - try { - CertStore.getInstance(dValid[i], paramsNull); - fail("InvalidAlgorithmParameterException must be thrown when params null"); - } catch (InvalidAlgorithmParameterException e) { - } - if (paramsContr != null) { - try { - CertStore.getInstance(dValid[i], paramsContr); - fail("InvalidAlgorithmParameterException must be thrown when params has incorrect type"); - } catch (InvalidAlgorithmParameterException e) { - } - } - } - } - - /** - * Test for getInstance(String type, CertStoreParameters params) method - * Assertion: return CertStore object - */ - public void testCertStore05() - throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { - if (!initParams()) { - return; - } - CertStore certS; - for (int i = 0; i < dValid.length; i++) { - certS = CertStore.getInstance(dValid[i], dParams); - assertEquals("Incorrect type", certS.getType(), dValid[i]); - certS.getCertStoreParameters(); - } - } - /** - * Test for method - * getInstance(String type, CertStoreParameters params, String provider) - * Assertion: throws IllegalArgumentException when provider is null or empty - * - * FIXME: verify IllegalArgumentException when privider is empty - */ - public void testCertStore06() - throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, - NoSuchProviderException { - if (!initParams()) { - return; - } - String provider = null; - for (int i = 0; i < dValid.length; i++) { - try { - CertStore.getInstance(dValid[i], dParams, provider); - fail("IllegalArgumentException must be thrown"); - } catch (IllegalArgumentException e) { - } - try { - CertStore.getInstance(dValid[i], dParams, ""); - fail("IllegalArgumentException must be thrown"); - } catch (IllegalArgumentException e) { - } - } - } - /** - * Test for method - * getInstance(String type, CertStoreParameters params, String provider) - * Assertion: throws NoSuchProviderException when provider has invalid value - */ - public void testCertStore07() - throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { - if (!initParams()) { - return; - } - for (int i = 0; i < dValid.length; i++) { - for (int j = 1; j < invalidValues.length; j++ ) { - try { - CertStore.getInstance(dValid[i], dParams, invalidValues[j]); - fail("NoSuchProviderException must be thrown"); - } catch (NoSuchProviderException e) { - } - } - } - } - /** - * Test for method - * getInstance(String type, CertStoreParameters params, String provider) - * Assertion: - * throws NullPointerException when type is null - * throws NoSuchAlgorithmException when type is incorrect; - */ - public void testCertStore08() - throws InvalidAlgorithmParameterException, NoSuchProviderException, - NoSuchAlgorithmException { - if (!initParams()) { - return; - } - for (int i = 0; i < invalidValues.length; i++) { - try { - CertStore.getInstance(invalidValues[i], dParams, dName); - fail("NoSuchAlgorithmException must be thrown"); - } catch (NoSuchAlgorithmException e){ - } - } - try { - CertStore.getInstance(null, dParams, dName); - fail("NullPointerException or NoSuchAlgorithmException must be thrown when type is null"); - } catch (NullPointerException e) { - } catch (NoSuchAlgorithmException e) { - } - } - /** - * Test for method - * getInstance(String type, CertStoreParameters params, String provider) - * Assertion: throws InvalidAlgorithmParameterException when params is null - * or has invalid value - */ - public void testCertStore09() - throws NoSuchProviderException, NoSuchAlgorithmException, - InvalidAlgorithmParameterException { - if (!initParams()) { - return; - } - CertStoreParameters paramsNull = null; - CertStoreParameters paramsContr = null; - if (CollectionSupport) { - if (LDAPSupport) { - paramsContr = new LDAPCertStoreParameters(); - } - } - for (int i = 0; i < dValid.length; i++ ) { - try { - CertStore.getInstance(dValid[i], paramsNull, dName); - fail("InvalidAlgorithmParameterException must be thrown when params null"); - } catch (InvalidAlgorithmParameterException e) { - } - if (paramsContr != null) { - try { - CertStore.getInstance(dValid[i], paramsContr, dName); - fail("InvalidAlgorithmParameterException must be thrown when params has incorrect type"); - } catch (InvalidAlgorithmParameterException e) { - } - } - } - } - /** - * Test for method - * getInstance(String type, CertStoreParameters params, String provider) - * Assertion: return CertStore object - */ - public void testCertStore10() - throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { - if (!initParams()) { - return; - } - CertStore certS; - for (int i = 0; i < dValid.length; i++) { - certS = CertStore.getInstance(dValid[i], dParams, dName); - assertEquals("Incorrect type", certS.getType(), dValid[i]); - certS.getCertStoreParameters(); - } - } - - /** - * Test for method - * getInstance(String type, CertStoreParameters params, Provider provider) - * Assertion: throws IllegalArgumentException when provider is null - */ - public void testCertStore11() - throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, - NoSuchProviderException { - if (!initParams()) { - return; - } - Provider provider = null; - for (int i = 0; i < dValid.length; i++) { - try { - CertStore.getInstance(dValid[i], dParams, provider); - fail("IllegalArgumentException must be thrown"); - } catch (IllegalArgumentException e) { - } - } - } - /** - * Test for getInstance(String type, CertStoreParameters params, Provider provider) method - * Assertion: - * throws NullPointerException when type is null - * throws NoSuchAlgorithmException when type is incorrect; - */ - public void testCertStore12() - throws InvalidAlgorithmParameterException, - NoSuchAlgorithmException { - if (!initParams()) { - return; - } - try { - CertStore.getInstance(null, dParams, dProv); - fail("NullPointerException or NoSuchAlgorithmException must be thrown when type is null"); - } catch (NullPointerException e) { - } catch (NoSuchAlgorithmException e) { - } - for (int i = 0; i < invalidValues.length; i++ ) { - try { - CertStore.getInstance(invalidValues[i], dParams, dProv); - fail("NoSuchAlgorithmException must be thrown"); - } catch (NoSuchAlgorithmException e) { - } - } - } - /** - * Test for method - * getInstance(String type, CertStoreParameters params, Provider provider) - * Assertion: throws InvalidAlgorithmParameterExceptio when params is null - * or has invalid value - */ - public void testCertStore13() - throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { - if (!initParams()) { - return; - } - CertStoreParameters paramsNull = null; - CertStoreParameters paramsContr = null; - if (CollectionSupport) { - if (LDAPSupport) { - paramsContr = new LDAPCertStoreParameters(); - } - } - for (int i = 0; i < dValid.length; i++ ) { - try { - CertStore.getInstance(dValid[i], paramsNull, dProv); - fail("InvalidAlgorithmParameterException must be thrown when params null"); - } catch (InvalidAlgorithmParameterException e) { - } - if (paramsContr != null) { - try { - CertStore.getInstance(dValid[i], paramsContr, dProv); - fail("InvalidAlgorithmParameterException must be thrown when params has incorrect type"); - } catch (InvalidAlgorithmParameterException e) { - } - } - } - } - /** - * Test for method - * getInstance(String type, CertStoreParameters params, Provider provider) - * Assertion: return CertStore object - */ - public void testCertStore14() - throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { - if (!initParams()) { - return; - } - CertStore certS; - for (int i = 0; i < dValid.length; i++) { - certS = CertStore.getInstance(dValid[i], dParams, dProv); - assertEquals("Incorrect type", certS.getType(), dValid[i]); - certS.getCertStoreParameters(); - } - } - /** - * Test for methods - * getCertificates(CertSelector selector) - * getCRLs(CRLSelector selector) - * Assertion: returns empty Collection when selector is null - */ - public void testCertStore15() - throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, - CertStoreException { - if (!initParams()) { - return; - } - CertStore [] certS = createCS(); - assertNotNull("CertStore object were not created", certS); - Collection coll; - for (int i = 0; i < certS.length; i++) { - coll = certS[i].getCertificates(null); - assertTrue("Result collection not empty",coll.isEmpty()); - coll = certS[i].getCRLs(null); - assertTrue("Result collection not empty",coll.isEmpty()); - } - } -} -/** - * Addifional class to verify CertStore constructor - */ -class myCertStore extends CertStore { - public myCertStore(CertStoreSpi spi, Provider prov, String type, CertStoreParameters params) { - super(spi, prov, type, params); - } -} +/* + * 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.cert; + +import java.security.InvalidAlgorithmParameterException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.Security; +import java.security.cert.CertStore; +import java.security.cert.CertStoreException; +import java.security.cert.CertStoreParameters; +import java.security.cert.CertStoreSpi; +import java.security.cert.CollectionCertStoreParameters; +import java.security.cert.LDAPCertStoreParameters; +import java.util.Collection; + +import org.apache.harmony.security.tests.support.SpiEngUtils; +import org.apache.harmony.security.tests.support.cert.MyCertStoreParameters; +import org.apache.harmony.security.tests.support.cert.MyCertStoreSpi; + +import junit.framework.TestCase; + +/** + * Tests for CertStore class constructors and + * methods. + * + */ + +public class CertStore1Test extends TestCase { + + /** + * Constructor for CertStoreTests. + * @param arg0 + */ + public CertStore1Test(String arg0) { + super(arg0); + } + public static final String srvCertStore = "CertStore"; + + private static final String defaultType = "LDAP"; + public static final String [] validValues = { + "LDAP", "ldap", "Ldap", "lDAP", "lDaP" }; + public static String [] validValuesC = null; + + private static String [] invalidValues = SpiEngUtils.invalidValues; + + private static boolean LDAPSupport = false; + private static final String CollectionType = "Collection"; + private static boolean CollectionSupport = false; + + private static Provider defaultProvider; + private static String defaultProviderName; + private static Provider defaultProviderCol; + private static String defaultProviderColName; + + private static String NotSupportMsg = ""; + + static { + defaultProvider = SpiEngUtils.isSupport(defaultType, + srvCertStore); + LDAPSupport = (defaultProvider != null); + defaultProviderName = (LDAPSupport ? defaultProvider.getName() : null); + NotSupportMsg = "LDAP and Collection algorithm are not supported"; + + defaultProviderCol = SpiEngUtils.isSupport(CollectionType, + srvCertStore); + CollectionSupport = (defaultProviderCol != null); + defaultProviderColName = (CollectionSupport ? defaultProviderCol.getName() : null); + if (CollectionSupport) { + validValuesC = new String[3]; + validValuesC[0] = CollectionType; + validValuesC[1] = CollectionType.toUpperCase(); + validValuesC[2] = CollectionType.toLowerCase(); + } + } + + private Provider dProv = null; + private String dName = null; + private String dType = null; + private CertStoreParameters dParams = null; + private String[] dValid; + + private boolean initParams() { + if (!LDAPSupport && !CollectionSupport) { + fail(NotSupportMsg); + return false; + } + dParams = (CollectionSupport ? (CertStoreParameters)new CollectionCertStoreParameters() : + (CertStoreParameters)new LDAPCertStoreParameters()); + dType = (CollectionSupport ? CollectionType : defaultType ); + dProv = (CollectionSupport ? defaultProviderCol : defaultProvider ); + dName = (CollectionSupport ? defaultProviderColName : defaultProviderName ); + dValid = (CollectionSupport ? validValuesC : validValues ); + return true; + } + private CertStore [] createCS() { + if (!LDAPSupport && !CollectionSupport) { + fail(NotSupportMsg); + return null; + } + try { + CertStore [] ss = new CertStore[3]; + ss[0] = CertStore.getInstance(dType, dParams); + ss[1] = CertStore.getInstance(dType, dParams, dProv); + ss[2] = CertStore.getInstance(dType, dParams, dName); + return ss; + } catch (Exception e) { + return null; + } + } + + + /** + * Test for getDefaultType() method + * Assertion: returns security property "certstore.type" or "LDAP" + */ + public void testCertStore01() { + if (!LDAPSupport) { + return; + } + String dt = CertStore.getDefaultType(); + String sn = Security.getProperty("certstore.type"); + String def = "Proba.cert.store.type"; + if (sn == null) { + sn = defaultType; + } + assertNotNull("Default type have not be null", dt); + assertEquals("Incorrect default type", dt, sn); + + Security.setProperty("certstore.type", def); + dt = CertStore.getDefaultType(); + assertEquals("Incorrect default type", dt, def); + Security.setProperty("certstore.type", sn); + assertEquals("Incorrect default type", Security.getProperty("certstore.type"), sn ); + } + /** + * Test for + * CertStore constructor + * Assertion: returns CertStore object + */ + + public void testCertStore02() throws NoSuchAlgorithmException, + InvalidAlgorithmParameterException, CertStoreException { + if (!initParams()) { + return; + } + MyCertStoreParameters pp = new MyCertStoreParameters(); + CertStoreSpi spi = new MyCertStoreSpi(pp); + CertStore certS = new myCertStore(spi, dProv, dType, pp); + assertEquals("Incorrect algorithm", certS.getType(), dType); + assertEquals("Incorrect provider", certS.getProvider(), dProv); + assertTrue("Incorrect parameters", certS.getCertStoreParameters() + instanceof MyCertStoreParameters); + try { + certS.getCertificates(null); + fail("CertStoreException must be thrown"); + } catch (CertStoreException e) { + } + certS = new myCertStore(null, null, null, null); + assertNull("Incorrect algorithm", certS.getType()); + assertNull("Incorrect provider", certS.getProvider()); + assertNull("Incorrect parameters", certS.getCertStoreParameters()); + try { + certS.getCertificates(null); + fail("NullPointerException must be thrown"); + } catch (NullPointerException e) { + } + } + + /** + * Test for getInstance(String type, CertStoreParameters params) method + * Assertion: + * throws NullPointerException when type is null + * throws NoSuchAlgorithmException when type is incorrect; + */ + public void testCertStore03() throws InvalidAlgorithmParameterException { + if (!initParams()) { + return; + } + try { + CertStore.getInstance(null, dParams); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when type is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++ ) { + try { + CertStore.getInstance(invalidValues[i], dParams); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for getInstance(String type, CertStoreParameters params) method + * Assertion: return CertStore object + */ + public void testCertStore05() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { + if (!initParams()) { + return; + } + CertStore certS; + for (int i = 0; i < dValid.length; i++) { + certS = CertStore.getInstance(dValid[i], dParams); + assertEquals("Incorrect type", certS.getType(), dValid[i]); + certS.getCertStoreParameters(); + } + } + /** + * Test for method + * getInstance(String type, CertStoreParameters params, String provider) + * Assertion: throws IllegalArgumentException when provider is null or empty + * + * FIXME: verify IllegalArgumentException when privider is empty + */ + public void testCertStore06() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, + NoSuchProviderException { + if (!initParams()) { + return; + } + String provider = null; + for (int i = 0; i < dValid.length; i++) { + try { + CertStore.getInstance(dValid[i], dParams, provider); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + try { + CertStore.getInstance(dValid[i], dParams, ""); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + } + } + /** + * Test for method + * getInstance(String type, CertStoreParameters params, String provider) + * Assertion: throws NoSuchProviderException when provider has invalid value + */ + public void testCertStore07() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { + if (!initParams()) { + return; + } + for (int i = 0; i < dValid.length; i++) { + for (int j = 1; j < invalidValues.length; j++ ) { + try { + CertStore.getInstance(dValid[i], dParams, invalidValues[j]); + fail("NoSuchProviderException must be thrown"); + } catch (NoSuchProviderException e) { + } + } + } + } + /** + * Test for method + * getInstance(String type, CertStoreParameters params, String provider) + * Assertion: + * throws NullPointerException when type is null + * throws NoSuchAlgorithmException when type is incorrect; + */ + public void testCertStore08() + throws InvalidAlgorithmParameterException, NoSuchProviderException, + NoSuchAlgorithmException { + if (!initParams()) { + return; + } + for (int i = 0; i < invalidValues.length; i++) { + try { + CertStore.getInstance(invalidValues[i], dParams, dName); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e){ + } + } + try { + CertStore.getInstance(null, dParams, dName); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when type is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + } + + /** + * Test for method + * getInstance(String type, CertStoreParameters params, String provider) + * Assertion: return CertStore object + */ + public void testCertStore10() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { + if (!initParams()) { + return; + } + CertStore certS; + for (int i = 0; i < dValid.length; i++) { + certS = CertStore.getInstance(dValid[i], dParams, dName); + assertEquals("Incorrect type", certS.getType(), dValid[i]); + certS.getCertStoreParameters(); + } + } + + /** + * Test for method + * getInstance(String type, CertStoreParameters params, Provider provider) + * Assertion: throws IllegalArgumentException when provider is null + */ + public void testCertStore11() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, + NoSuchProviderException { + if (!initParams()) { + return; + } + Provider provider = null; + for (int i = 0; i < dValid.length; i++) { + try { + CertStore.getInstance(dValid[i], dParams, provider); + fail("IllegalArgumentException must be thrown"); + } catch (IllegalArgumentException e) { + } + } + } + /** + * Test for getInstance(String type, CertStoreParameters params, Provider provider) method + * Assertion: + * throws NullPointerException when type is null + * throws NoSuchAlgorithmException when type is incorrect; + */ + public void testCertStore12() + throws InvalidAlgorithmParameterException, + NoSuchAlgorithmException { + if (!initParams()) { + return; + } + try { + CertStore.getInstance(null, dParams, dProv); + fail("NullPointerException or NoSuchAlgorithmException must be thrown when type is null"); + } catch (NullPointerException e) { + } catch (NoSuchAlgorithmException e) { + } + for (int i = 0; i < invalidValues.length; i++ ) { + try { + CertStore.getInstance(invalidValues[i], dParams, dProv); + fail("NoSuchAlgorithmException must be thrown"); + } catch (NoSuchAlgorithmException e) { + } + } + } + + /** + * Test for method + * getInstance(String type, CertStoreParameters params, Provider provider) + * Assertion: return CertStore object + */ + public void testCertStore14() + throws InvalidAlgorithmParameterException, NoSuchAlgorithmException { + if (!initParams()) { + return; + } + CertStore certS; + for (int i = 0; i < dValid.length; i++) { + certS = CertStore.getInstance(dValid[i], dParams, dProv); + assertEquals("Incorrect type", certS.getType(), dValid[i]); + certS.getCertStoreParameters(); + } + } + /** + * Test for methods + * getCertificates(CertSelector selector) + * getCRLs(CRLSelector selector) + * Assertion: returns empty Collection when selector is null + */ + public void testCertStore15() + throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, + CertStoreException { + if (!initParams()) { + return; + } + CertStore [] certS = createCS(); + assertNotNull("CertStore object were not created", certS); + Collection coll; + for (int i = 0; i < certS.length; i++) { + coll = certS[i].getCertificates(null); + assertTrue("Result collection not empty",coll.isEmpty()); + coll = certS[i].getCRLs(null); + assertTrue("Result collection not empty",coll.isEmpty()); + } + } +} +/** + * Addifional class to verify CertStore constructor + */ +class myCertStore extends CertStore { + public myCertStore(CertStoreSpi spi, Provider prov, String type, CertStoreParameters params) { + super(spi, prov, type, params); + } +}