Home | History | Annotate | Download | only in cert
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 /**
     19 * @author Vladimir N. Molotkov
     20 * @version $Revision$
     21 */
     22 
     23 package tests.security.cert;
     24 
     25 import junit.framework.TestCase;
     26 
     27 import java.security.cert.CRL;
     28 import java.security.cert.Certificate;
     29 
     30 import org.apache.harmony.security.tests.support.SpiEngUtils;
     31 
     32 /**
     33  * Tests for <code>java.security.cert.CRL</code> fields and methods
     34  *
     35  */
     36 public class CRLTest extends TestCase {
     37 
     38     public static final String[] validValues = { "X.509", "x.509" };
     39 
     40     private final static String[] invalidValues = SpiEngUtils.invalidValues;
     41 
     42     //
     43     // Tests
     44     //
     45 
     46     /**
     47      * Test for <code>CRL(String type)</code> constructor<br>
     48      */
     49     public final void testConstructor() {
     50         for (int i = 0; i< validValues.length; i++) {
     51             CRL crl = new MyCRL(validValues[i]);
     52             assertEquals(validValues[i], crl.getType());
     53         }
     54 
     55         for (int i = 0; i< invalidValues.length; i++) {
     56             CRL crl = new MyCRL(invalidValues[i]);
     57             assertEquals(invalidValues[i], crl.getType());
     58         }
     59 
     60         try {
     61             CRL crl = new MyCRL(null);
     62         } catch (Exception e) {
     63             fail("Unexpected exception for NULL parameter");
     64         }
     65     }
     66 
     67 
     68     /**
     69      * Test #1 for <code>getType()</code> method<br>
     70      * Assertion: returns <code>CRL</code> type
     71      */
     72     public final void testGetType01() {
     73         CRL crl = new MyCRL("TEST_TYPE");
     74         assertEquals("TEST_TYPE", crl.getType());
     75     }
     76 
     77     /**
     78      * Test #2 for <code>getType()</code> method<br>
     79      * Assertion: returns <code>CRL</code> type
     80      */
     81     public final void testGetType02() {
     82         CRL crl = new MyCRL(null);
     83         assertNull(crl.getType());
     84     }
     85 
     86     //
     87     // the following tests just call methods
     88     // that are abstract in <code>Certificate</code>
     89     // (So they just like signature tests)
     90     //
     91 
     92     /**
     93      * Test for <code>toString()</code> method
     94      */
     95     public final void testToString() {
     96         CRL crl = new MyCRL("TEST_TYPE");
     97         crl.toString();
     98     }
     99 
    100     /**
    101      * Test for <code>isRevoked()</code> method
    102      */
    103     public final void testIsRevoked() {
    104         CRL crl = new MyCRL("TEST_TYPE");
    105         crl.isRevoked(null);
    106     }
    107 
    108     class MyCRL extends CRL {
    109 
    110         protected MyCRL(String type) {
    111             super(type);
    112         }
    113 
    114         @Override
    115         public boolean isRevoked(Certificate cert) {
    116             return false;
    117         }
    118 
    119         @Override
    120         public String toString() {
    121             return null;
    122         }
    123 
    124     }
    125 }
    126