Search in sources :

Example 1 with CertificateExpiredException

use of javax.security.cert.CertificateExpiredException in project robovm by robovm.

the class X509CertificateTest method testCheckValidity2.

/**
     * checkValidity(Date date) method testing.
     * @throws CertificateNotYetValidException
     * @throws CertificateExpiredException
     */
public void testCheckValidity2() throws CertificateNotYetValidException, CertificateExpiredException {
    if (this.cert == null) {
        // Test can not be applied.
        return;
    }
    Date[] date = new Date[8];
    Calendar calendar = Calendar.getInstance();
    for (int i = 0; i < date.length; i++) {
        calendar.set(i * 500, 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);
        }
    }
    Calendar calendarNow = Calendar.getInstance();
    try {
        tbt_cert.checkValidity(calendarNow.getTime());
    } catch (CertificateExpiredException e) {
    //ok
    }
    Calendar calendarPast = GregorianCalendar.getInstance();
    calendarPast.clear();
    try {
        tbt_cert.checkValidity(calendarPast.getTime());
    } catch (CertificateNotYetValidException e) {
    //ok
    }
}
Also used : CertificateNotYetValidException(javax.security.cert.CertificateNotYetValidException) CertificateExpiredException(javax.security.cert.CertificateExpiredException) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 2 with CertificateExpiredException

use of javax.security.cert.CertificateExpiredException in project robovm by robovm.

the class X509CertificateTest method testCheckValidity1.

/**
     * checkValidity() method testing.
     * @throws CertificateNotYetValidException
     * @throws CertificateExpiredException
     * @throws java.security.cert.CertificateExpiredException
     * @throws java.security.cert.CertificateNotYetValidException
     */
public void testCheckValidity1() throws CertificateExpiredException, CertificateNotYetValidException, java.security.cert.CertificateExpiredException, java.security.cert.CertificateNotYetValidException {
    if (this.cert == null) {
        // 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);
    }
    try {
        tbt_cert.checkValidity();
    } catch (CertificateExpiredException e) {
    // ok
    }
    try {
        cert.checkValidity();
    } catch (java.security.cert.CertificateExpiredException e) {
    // ok
    }
}
Also used : CertificateNotYetValidException(javax.security.cert.CertificateNotYetValidException) CertificateExpiredException(javax.security.cert.CertificateExpiredException) Date(java.util.Date)

Example 3 with CertificateExpiredException

use of javax.security.cert.CertificateExpiredException in project robovm by robovm.

the class CertificateExpiredExceptionTest method testCertificateExpiredException02.

/**
     * Test for <code>CertificateExpiredException(String)</code> constructor
     * Assertion: constructs CertificateExpiredException with detail message
     * msg. Parameter <code>msg</code> is not null.
     */
public void testCertificateExpiredException02() {
    CertificateExpiredException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new CertificateExpiredException(msgs[i]);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : CertificateExpiredException(javax.security.cert.CertificateExpiredException)

Example 4 with CertificateExpiredException

use of javax.security.cert.CertificateExpiredException in project robovm by robovm.

the class CertificateExpiredExceptionTest method testCertificateExpiredException01.

/**
     * Test for <code>CertificateExpiredException()</code> constructor
     * Assertion: constructs CertificateExpiredException with no detail message
     */
public void testCertificateExpiredException01() {
    CertificateExpiredException tE = new CertificateExpiredException();
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CertificateExpiredException(javax.security.cert.CertificateExpiredException)

Example 5 with CertificateExpiredException

use of javax.security.cert.CertificateExpiredException in project robovm by robovm.

the class CertificateExpiredExceptionTest method testCertificateExpiredException03.

/**
     * Test for <code>CertificateExpiredException(String)</code> constructor
     * Assertion: constructs CertificateExpiredException when <code>msg</code>
     * is null
     */
public void testCertificateExpiredException03() {
    String msg = null;
    CertificateExpiredException tE = new CertificateExpiredException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CertificateExpiredException(javax.security.cert.CertificateExpiredException)

Aggregations

CertificateExpiredException (javax.security.cert.CertificateExpiredException)9 Date (java.util.Date)3 CertificateNotYetValidException (javax.security.cert.CertificateNotYetValidException)3 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1