1 package se.anatom.ejbca.approval; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.ObjectOutputStream ; 5 import java.security.cert.X509Certificate ; 6 import java.util.ArrayList ; 7 import java.util.Collection ; 8 import java.util.Date ; 9 import java.util.Iterator ; 10 11 import junit.framework.TestCase; 12 13 import org.ejbca.core.model.approval.Approval; 14 import org.ejbca.core.model.approval.ApprovalDataUtil; 15 import org.ejbca.util.Base64; 16 import org.ejbca.util.CertTools; 17 18 23 24 public class TestApproval extends TestCase { 25 26 private static byte[] testcertenc = Base64.decode(("MIIDATCCAmqgAwIBAgIIczEoghAwc3EwDQYJKoZIhvcNAQEFBQAwLzEPMA0GA1UE" 27 + "AxMGVGVzdENBMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNFMB4XDTAzMDky" 28 + "NDA2NDgwNFoXDTA1MDkyMzA2NTgwNFowMzEQMA4GA1UEAxMHcDEydGVzdDESMBAG" 29 + "A1UEChMJUHJpbWVUZXN0MQswCQYDVQQGEwJTRTCBnTANBgkqhkiG9w0BAQEFAAOB" 30 + "iwAwgYcCgYEAnPAtfpU63/0h6InBmesN8FYS47hMvq/sliSBOMU0VqzlNNXuhD8a" 31 + "3FypGfnPXvjJP5YX9ORu1xAfTNao2sSHLtrkNJQBv6jCRIMYbjjo84UFab2qhhaJ" 32 + "wqJgkQNKu2LHy5gFUztxD8JIuFPoayp1n9JL/gqFDv6k81UnDGmHeFcCARGjggEi" 33 + "MIIBHjAPBgNVHRMBAf8EBTADAQEAMA8GA1UdDwEB/wQFAwMHoAAwOwYDVR0lBDQw" 34 + "MgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEFBQcDBAYIKwYBBQUHAwUGCCsGAQUF" 35 + "BwMHMB0GA1UdDgQWBBTnT1aQ9I0Ud4OEfNJkSOgJSrsIoDAfBgNVHSMEGDAWgBRj" 36 + "e/R2qFQkjqV0pXdEpvReD1eSUTAiBgNVHREEGzAZoBcGCisGAQQBgjcUAgOgCQwH" 37 + "Zm9vQGZvbzASBgNVHSAECzAJMAcGBSkBAQEBMEUGA1UdHwQ+MDwwOqA4oDaGNGh0" 38 + "dHA6Ly8xMjcuMC4wLjE6ODA4MC9lamJjYS93ZWJkaXN0L2NlcnRkaXN0P2NtZD1j" 39 + "cmwwDQYJKoZIhvcNAQEFBQADgYEAU4CCcLoSUDGXJAOO9hGhvxQiwjGD2rVKCLR4" 40 + "emox1mlQ5rgO9sSel6jHkwceaq4A55+qXAjQVsuy76UJnc8ncYX8f98uSYKcjxo/" 41 + "ifn1eHMbL8dGLd5bc2GNBZkmhFIEoDvbfn9jo7phlS8iyvF2YhC4eso8Xb+T7+BZ" 42 + "QUOBOvc=").getBytes()); 43 44 protected void setUp() throws Exception { 45 super.setUp(); 46 CertTools.installBCProvider(); 47 } 48 49 public void testWriteExternal() throws Exception { 50 X509Certificate testcert = CertTools.getCertfromByteArray(testcertenc); 51 ArrayList approvals = new ArrayList (); 52 53 Approval ap = new Approval("test"); 54 Date apDate = ap.getApprovalDate(); 55 ap.setApprovalCertificateAndUsername(true,testcert, "USERNAME"); 56 approvals.add(ap); 57 58 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 59 ObjectOutputStream oos = new ObjectOutputStream (baos); 60 61 int size = approvals.size(); 62 oos.writeInt(size); 63 Iterator iter = approvals.iterator(); 64 while(iter.hasNext()){ 65 Approval next = (Approval) iter.next(); 66 oos.writeObject(next); 67 } 68 oos.flush(); 69 String result = new String (Base64.encode(baos.toByteArray(),false)); 70 71 72 Collection readapprovals = ApprovalDataUtil.getApprovals(result); 73 assertTrue(readapprovals.size() == 1); 74 75 Approval rap = (Approval) readapprovals.iterator().next(); 76 assertTrue(rap.getAdminCertIssuerDN().equals(CertTools.getIssuerDN(testcert))); 77 assertTrue(rap.getAdminCertSerialNumber().equals(testcert.getSerialNumber())); 78 assertTrue(rap.getUsername().equals("USERNAME")); 79 assertTrue(rap.isApproved()); 80 assertTrue(rap.getComment().equals("test")); 81 assertTrue(rap.getApprovalDate().equals(apDate)); 82 } 83 84 } 85 | Popular Tags |