KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > se > anatom > ejbca > approval > TestApprovalRequest


1 package se.anatom.ejbca.approval;
2
3 import java.io.ByteArrayOutputStream JavaDoc;
4 import java.io.ObjectOutputStream JavaDoc;
5 import java.security.cert.X509Certificate JavaDoc;
6
7 import junit.framework.TestCase;
8
9 import org.ejbca.core.model.approval.ApprovalDataUtil;
10 import org.ejbca.core.model.approval.ApprovalDataVO;
11 import org.ejbca.core.model.approval.ApprovalRequest;
12 import org.ejbca.core.model.approval.approvalrequests.DummyApprovalRequest;
13 import org.ejbca.core.model.log.Admin;
14 import org.ejbca.util.Base64;
15 import org.ejbca.util.CertTools;
16
17 public class TestApprovalRequest extends TestCase {
18
19     private static byte[] testcertenc = Base64.decode(("MIIDATCCAmqgAwIBAgIIczEoghAwc3EwDQYJKoZIhvcNAQEFBQAwLzEPMA0GA1UE"
20             + "AxMGVGVzdENBMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNFMB4XDTAzMDky"
21             + "NDA2NDgwNFoXDTA1MDkyMzA2NTgwNFowMzEQMA4GA1UEAxMHcDEydGVzdDESMBAG"
22             + "A1UEChMJUHJpbWVUZXN0MQswCQYDVQQGEwJTRTCBnTANBgkqhkiG9w0BAQEFAAOB"
23             + "iwAwgYcCgYEAnPAtfpU63/0h6InBmesN8FYS47hMvq/sliSBOMU0VqzlNNXuhD8a"
24             + "3FypGfnPXvjJP5YX9ORu1xAfTNao2sSHLtrkNJQBv6jCRIMYbjjo84UFab2qhhaJ"
25             + "wqJgkQNKu2LHy5gFUztxD8JIuFPoayp1n9JL/gqFDv6k81UnDGmHeFcCARGjggEi"
26             + "MIIBHjAPBgNVHRMBAf8EBTADAQEAMA8GA1UdDwEB/wQFAwMHoAAwOwYDVR0lBDQw"
27             + "MgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEFBQcDBAYIKwYBBQUHAwUGCCsGAQUF"
28             + "BwMHMB0GA1UdDgQWBBTnT1aQ9I0Ud4OEfNJkSOgJSrsIoDAfBgNVHSMEGDAWgBRj"
29             + "e/R2qFQkjqV0pXdEpvReD1eSUTAiBgNVHREEGzAZoBcGCisGAQQBgjcUAgOgCQwH"
30             + "Zm9vQGZvbzASBgNVHSAECzAJMAcGBSkBAQEBMEUGA1UdHwQ+MDwwOqA4oDaGNGh0"
31             + "dHA6Ly8xMjcuMC4wLjE6ODA4MC9lamJjYS93ZWJkaXN0L2NlcnRkaXN0P2NtZD1j"
32             + "cmwwDQYJKoZIhvcNAQEFBQADgYEAU4CCcLoSUDGXJAOO9hGhvxQiwjGD2rVKCLR4"
33             + "emox1mlQ5rgO9sSel6jHkwceaq4A55+qXAjQVsuy76UJnc8ncYX8f98uSYKcjxo/"
34             + "ifn1eHMbL8dGLd5bc2GNBZkmhFIEoDvbfn9jo7phlS8iyvF2YhC4eso8Xb+T7+BZ"
35             + "QUOBOvc=").getBytes());
36     
37     public void testWriteExternal() throws Exception JavaDoc {
38         X509Certificate JavaDoc testcert = CertTools.getCertfromByteArray(testcertenc);
39         DummyApprovalRequest ar = new DummyApprovalRequest(new Admin(testcert),null,1,2, false);
40         
41         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
42         ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
43         oos.writeObject(ar);
44         oos.flush();
45         String JavaDoc result = new String JavaDoc(Base64.encode(baos.toByteArray(),false));
46
47         
48         ApprovalRequest readrequest = ApprovalDataUtil.getApprovalRequest(result);
49         assertTrue(readrequest.getApprovalType() == ApprovalDataVO.APPROVALTYPE_DUMMY);
50         assertTrue(readrequest.getApprovalRequestType() == ApprovalRequest.REQUESTTYPE_SIMPLE);
51         assertTrue(readrequest.getRequestSignature() == null);
52         assertTrue(readrequest.getRequestAdminCert().getSerialNumber().equals(testcert.getSerialNumber()));
53         assertTrue(readrequest.getCAId() == 1);
54         assertTrue(readrequest.getEndEntityProfileId() == 2);
55         assertTrue(!readrequest.isExecutable());
56         
57     }
58
59     protected void setUp() throws Exception JavaDoc {
60         super.setUp();
61         CertTools.installBCProvider();
62     }
63
64 }
65
Popular Tags