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
18package org.apache.harmony.security.tests.java.security.cert;
19
20import java.io.InputStream;
21import java.security.cert.CertificateFactory;
22import java.security.cert.X509Certificate;
23import java.util.Iterator;
24import java.util.Vector;
25
26import tests.support.resource.Support_Resources;
27
28import junit.framework.TestCase;
29
30public class X509CRLEntry2Test extends junit.framework.TestCase {
31
32    private X509Certificate pemCert = null;
33
34    protected void setUp() throws Exception {
35
36        InputStream is = Support_Resources
37                .getResourceStream("hyts_certificate_PEM.txt");
38
39        CertificateFactory certFact = CertificateFactory.getInstance("X509");
40        pemCert = (X509Certificate) certFact.generateCertificate(is);
41    }
42
43    /**
44     * @tests java.security.cert.X509CRLEntry#getExtensionValue(java.lang.String)
45     */
46    public void test_getExtensionValueLjava_lang_String() {
47        if (pemCert != null) {
48            Vector extensionOids = new Vector();
49            extensionOids.addAll(pemCert.getCriticalExtensionOIDs());
50            extensionOids.addAll(pemCert.getNonCriticalExtensionOIDs());
51            Iterator i = extensionOids.iterator();
52            while (i.hasNext()) {
53                String oid = (String) i.next();
54                byte[] value = pemCert.getExtensionValue(oid);
55                if (value != null && value.length > 0) {
56                    // check that it is an encoded as a OCTET STRING
57                    assertTrue("The extension value for the oid " + oid
58                            + " was not encoded as an OCTET STRING",
59                            value[0] == 0x04);
60                }
61            }// end while
62        } else {
63            fail("Unable to obtain X509Certificate");
64        }
65    }
66}