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 Alexander Y. Kleymenov
20*/
21
22package org.apache.harmony.security.tests.java.security.cert;
23
24import java.io.IOException;
25import java.security.cert.X509CRLSelector;
26import java.util.Iterator;
27import java.util.TreeSet;
28
29import javax.security.auth.x500.X500Principal;
30
31import junit.framework.TestCase;
32
33/**
34 */
35
36public class X509CRLSelectorTest extends TestCase {
37
38    /**
39     * @tests java.security.cert.X509CRLSelector#addIssuer(javax.security.auth.x500.X500Principal)
40     */
41    public void test_addIssuerLjavax_security_auth_x500_X500Principal()
42            throws Exception {
43        //Regression for HARMONY-465
44        X509CRLSelector obj = new X509CRLSelector();
45        try {
46            obj.addIssuer((X500Principal) null);
47            fail("NullPointerException expected");
48        } catch (NullPointerException e) {
49            // expected
50        }
51    }
52
53    /**
54     * @tests java.security.cert.X509CRLSelector#addIssuerName(java.lang.String)
55     */
56    public void test_addIssuerNameLjava_lang_String() throws Exception {
57        //Regression for HARMONY-465
58        X509CRLSelector obj = new X509CRLSelector();
59        try {
60            obj.addIssuerName("234");
61            fail("IOException expected");
62        } catch (IOException e) {
63            // expected
64        }
65
66        // Regression for HARMONY-1076
67        try {
68            new X509CRLSelector().addIssuerName("w=y");
69            fail("IOException expected");
70        } catch (IOException e) {
71            // expected
72        }
73    }
74
75    /**
76     * @tests java.security.cert.X509CRLSelector#addIssuerName(byte[])
77     */
78    public void test_addIssuerName$B_3() throws Exception {
79        //Regression for HARMONY-465
80        X509CRLSelector obj = new X509CRLSelector();
81        try {
82            obj.addIssuerName(new byte[] { (byte) 2, (byte) 3, (byte) 4 });
83            fail("IOException expected");
84        } catch (IOException e) {
85            // expected
86        }
87    }
88
89    /**
90     * @tests java.security.cert.X509CRLSelector#addIssuerName(byte[])
91     */
92    public void test_addIssuerName$B_4() throws Exception {
93        //Regression for HARMONY-465
94        X509CRLSelector obj = new X509CRLSelector();
95        try {
96            obj.addIssuerName((byte[]) null);
97            fail("NullPointerException expected");
98        } catch (NullPointerException e) {
99            // expected
100        }
101    }
102
103    /**
104     * @tests addIssuerName(String name)
105     */
106    public void testAddIssuerName() throws IOException {
107        //Regression for HARMONY-736
108        X509CRLSelector selector = new X509CRLSelector();
109        try {
110            selector.addIssuerName("a");
111            fail("IOException expected");
112        } catch (IOException e) {}
113
114        //no exception for null
115        selector.addIssuerName((String) null);
116    }
117
118    /**
119     * @tests setIssuerNames(Collection <?> names)
120     */
121    public void testSetIssuerNames1() throws IOException {
122        // Regression for HARMONY-737
123        X509CRLSelector selector = new X509CRLSelector();
124        selector.setIssuerNames(new TreeSet() {
125            public Iterator iterator() {
126                return null;
127            }
128        });
129    }
130}
131