1 13 14 package org.ejbca.core.model.ca.certextensions; 15 16 import java.util.Properties ; 17 18 import junit.framework.TestCase; 19 20 import org.bouncycastle.asn1.DERPrintableString; 21 22 30 31 public class TestCertificateExtensionManager extends TestCase { 32 33 34 35 public void test01CertificateExtensionFactory() throws Exception { 36 Properties props = new Properties (); 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 (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 (2))); 87 88 certExt = fact.getCertificateExtensions(new Integer (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 |