KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ca > certextensions > TestCertificateExtensionManager


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13
14 package org.ejbca.core.model.ca.certextensions;
15
16 import java.util.Properties JavaDoc;
17
18 import junit.framework.TestCase;
19
20 import org.bouncycastle.asn1.DERPrintableString;
21
22 /**
23  *
24  * Test the functionality of the CertificateExtensionManager
25  *
26  * @author Philip Vendil 2007 jan 7
27  *
28  * @version $Id: TestCertificateExtensionManager.java,v 1.1 2007/01/09 16:47:20 herrvendil Exp $
29  */

30
31 public class TestCertificateExtensionManager extends TestCase {
32     
33
34     
35     public void test01CertificateExtensionFactory() throws Exception JavaDoc{
36         Properties JavaDoc props = new Properties JavaDoc();
37         props.put("id1.oid", "1.2.3.4");
38         props.put("id1.classpath", "org.ejbca.core.model.ca.certextensions.BasicCertificateExtension");
39         props.put("id1.displayname", "TESTEXTENSION");
40         props.put("id1.used", "TRUE");
41         props.put("id1.translatable", "FALSE");
42         props.put("id1.critical", "TRUE");
43         props.put("id1.property.encoding", "DERPRINTABLESTRING");
44         props.put("id1.property.value", "Test 123");
45         
46         props.put("id2.oid", "2.2.3.4");
47         props.put("id2.classpath", "org.ejbca.core.model.ca.certextensions.BasicCertificateExtension");
48         props.put("id2.displayname", "TESTEXTENSION2");
49         props.put("id2.used", "false");
50         props.put("id2.translatable", "FALSE");
51         props.put("id2.critical", "TRUE");
52         props.put("id2.property.encoding", "DERPRINTABLESTRING");
53         props.put("id2.property.value", "Test 123");
54
55         props.put("id3.oid", "3.2.3.4");
56         props.put("id3.classpath", "org.ejbca.core.model.ca.certextensions.DummyAdvancedCertificateExtension");
57         props.put("id3.displayname", "TESTEXTENSION3");
58         props.put("id3.used", "TRUE");
59         props.put("id3.translatable", "TRUE");
60         props.put("id3.critical", "FALSE");
61         props.put("id3.property.value", "Test 321");
62         
63         CertificateExtensionFactory fact = CertificateExtensionFactory.getInstance(props);
64         
65         assertTrue(fact.getAvailableCertificateExtensions().size()+"",fact.getAvailableCertificateExtensions().size() ==2);
66         AvailableCertificateExtension availExt = (AvailableCertificateExtension) fact.getAvailableCertificateExtensions().get(0);
67         assertTrue(availExt.getId() == 1);
68         assertTrue(availExt.getOID().equals("1.2.3.4"));
69         assertTrue(availExt.getDisplayName().equals("TESTEXTENSION"));
70         assertTrue(availExt.isTranslatable() == false);
71         
72         availExt = (AvailableCertificateExtension) fact.getAvailableCertificateExtensions().get(1);
73         assertTrue(availExt.getId() == 3);
74         assertTrue(availExt.getOID().equals("3.2.3.4"));
75         assertTrue(availExt.getDisplayName().equals("TESTEXTENSION3"));
76         assertTrue(availExt.isTranslatable() == true);
77         
78         CertificateExtension certExt = fact.getCertificateExtensions(new Integer JavaDoc(1));
79         assertTrue(certExt != null);
80         assertTrue(certExt.getId() == 1);
81         assertTrue(certExt.getOID().equals("1.2.3.4"));
82         assertTrue(certExt.isCriticalFlag());
83         assertTrue(certExt.getValue(null, null, null) instanceof DERPrintableString);
84         assertTrue(((DERPrintableString) certExt.getValue(null, null, null)).getString().equals("Test 123"));
85         
86         assertNull(fact.getCertificateExtensions(new Integer JavaDoc(2)));
87         
88         certExt = fact.getCertificateExtensions(new Integer JavaDoc(3));
89         assertTrue(certExt != null);
90         assertTrue(certExt.getId() == 3);
91         assertTrue(certExt.getOID().equals("3.2.3.4"));
92         assertTrue(!certExt.isCriticalFlag());
93         assertTrue(certExt.getValue(null, null, null) instanceof DERPrintableString);
94         assertTrue(((DERPrintableString) certExt.getValue(null, null, null)).getString().equals("Test 321"));
95         
96     }
97     
98
99
100 }
101
Popular Tags