KickJava   Java API By Example, From Geeks To Geeks.

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


1 package se.anatom.ejbca.approval;
2
3 import junit.framework.TestCase;
4
5 import org.ejbca.core.model.approval.ApprovalExecutorUtil;
6 import org.ejbca.core.model.approval.ApprovalOveradableClassName;
7 import org.ejbca.core.model.approval.approvalrequests.ChangeStatusEndEntityApprovalRequest;
8 import org.ejbca.core.model.log.Admin;
9 import org.ejbca.core.model.ra.UserDataConstants;
10
11 public class TestApprovalExecutorUtil extends TestCase {
12
13     private static final Admin admin = new Admin(Admin.TYPE_INTERNALUSER);
14     
15     protected void setUp() throws Exception JavaDoc {
16         super.setUp();
17     }
18     
19     public void testNoOfApprovals() {
20         int numOfApprovalsRequired = 1;
21         ChangeStatusEndEntityApprovalRequest ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_GENERATED, UserDataConstants.STATUS_NEW, admin, null, numOfApprovalsRequired, 1, 1);
22         boolean approvalRequired = ApprovalExecutorUtil.requireApproval(ar, null);
23         assertTrue(approvalRequired);
24         numOfApprovalsRequired = 0;
25         ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_GENERATED, UserDataConstants.STATUS_NEW, admin, null, numOfApprovalsRequired, 1, 1);
26         approvalRequired = ApprovalExecutorUtil.requireApproval(ar, null);
27         assertFalse(approvalRequired);
28     }
29     
30     public void testGloballyExcludedClasses() {
31         int numOfApprovalsRequired = 1;
32         ChangeStatusEndEntityApprovalRequest ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_GENERATED, UserDataConstants.STATUS_NEW, admin, null, numOfApprovalsRequired, 1, 1);
33         boolean approvalRequired = ApprovalExecutorUtil.requireApproval(ar, null);
34         assertTrue(approvalRequired);
35         ApprovalJunitHelper.JunitApprovalExecutorUtil1.init();
36         approvalRequired = ApprovalJunitHelper.JunitApprovalExecutorUtil1.requireApproval(ar, null);
37         assertFalse(approvalRequired);
38         ApprovalJunitHelper.JunitApprovalExecutorUtil2.init();
39         approvalRequired = ApprovalJunitHelper.JunitApprovalExecutorUtil2.requireApproval(ar, null);
40         assertFalse(approvalRequired);
41         ApprovalJunitHelper.JunitApprovalExecutorUtil3.init();
42         approvalRequired = ApprovalJunitHelper.JunitApprovalExecutorUtil3.requireApproval(ar, null);
43         assertTrue(approvalRequired);
44     }
45     
46     public void testOverridableClassNames() {
47         ApprovalOveradableClassName[] NONAPPROVABLECLASSNAMES_SETUSERSTATUS = {
48             new ApprovalOveradableClassName("org.ejbca.core.ejb.ra.LocalUserAdminSessionBean","revokeUser"),
49             new ApprovalOveradableClassName("org.ejbca.core.ejb.ra.LocalUserAdminSessionBean","revokeCert"),
50             new ApprovalOveradableClassName("org.ejbca.ui.web.admin.rainterface.RAInterfaceBean","unrevokeCert"),
51             new ApprovalOveradableClassName("org.ejbca.ui.web.admin.rainterface.RAInterfaceBean","markForRecovery"),
52             new ApprovalOveradableClassName("org.ejbca.extra.caservice.ExtRACAProcess","processExtRARevocationRequest"),
53             new ApprovalOveradableClassName("se.primeKey.cardPersonalization.ra.connection.ejbca.EjbcaConnection",null)
54         };
55
56         int numOfApprovalsRequired = 1;
57         ChangeStatusEndEntityApprovalRequest ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_GENERATED, UserDataConstants.STATUS_NEW, admin, null, numOfApprovalsRequired, 1, 1);
58         boolean approvalRequired = ApprovalExecutorUtil.requireApproval(ar, NONAPPROVABLECLASSNAMES_SETUSERSTATUS);
59         assertTrue(approvalRequired);
60         ApprovalOveradableClassName[] NONAPPROVABLECLASSNAMES_SETUSERSTATUS1 = {
61                 new ApprovalOveradableClassName("org.ejbca.core.ejb.ra.LocalUserAdminSessionBean","revokeUser"),
62                 new ApprovalOveradableClassName("org.ejbca.core.ejb.ra.LocalUserAdminSessionBean","revokeCert"),
63                 new ApprovalOveradableClassName("se.anatom.ejbca.approval.TestApprovalExecutorUtil","foo"),
64                 new ApprovalOveradableClassName("org.ejbca.ui.web.admin.rainterface.RAInterfaceBean","markForRecovery"),
65                 new ApprovalOveradableClassName("org.ejbca.extra.caservice.ExtRACAProcess","processExtRARevocationRequest"),
66                 new ApprovalOveradableClassName("se.primeKey.cardPersonalization.ra.connection.ejbca.EjbcaConnection",null)
67             };
68         ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_GENERATED, UserDataConstants.STATUS_NEW, admin, null, numOfApprovalsRequired, 1, 1);
69         approvalRequired = ApprovalExecutorUtil.requireApproval(ar, NONAPPROVABLECLASSNAMES_SETUSERSTATUS1);
70         assertTrue(approvalRequired);
71         ApprovalOveradableClassName[] NONAPPROVABLECLASSNAMES_SETUSERSTATUS2 = {
72                 new ApprovalOveradableClassName("org.ejbca.core.ejb.ra.LocalUserAdminSessionBean","revokeUser"),
73                 new ApprovalOveradableClassName("org.ejbca.core.ejb.ra.LocalUserAdminSessionBean","revokeCert"),
74                 new ApprovalOveradableClassName("se.anatom.ejbca.approval.TestApprovalExecutorUtil",null),
75                 new ApprovalOveradableClassName("org.ejbca.ui.web.admin.rainterface.RAInterfaceBean","markForRecovery"),
76                 new ApprovalOveradableClassName("org.ejbca.extra.caservice.ExtRACAProcess","processExtRARevocationRequest"),
77                 new ApprovalOveradableClassName("se.primeKey.cardPersonalization.ra.connection.ejbca.EjbcaConnection",null)
78             };
79         ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_GENERATED, UserDataConstants.STATUS_NEW, admin, null, numOfApprovalsRequired, 1, 1);
80         approvalRequired = ApprovalExecutorUtil.requireApproval(ar, NONAPPROVABLECLASSNAMES_SETUSERSTATUS2);
81         assertFalse(approvalRequired);
82         ApprovalOveradableClassName[] NONAPPROVABLECLASSNAMES_SETUSERSTATUS3 = {
83                 new ApprovalOveradableClassName("org.ejbca.core.ejb.ra.LocalUserAdminSessionBean","revokeUser"),
84                 new ApprovalOveradableClassName("org.ejbca.core.ejb.ra.LocalUserAdminSessionBean","revokeCert"),
85                 new ApprovalOveradableClassName("se.anatom.ejbca.approval.TestApprovalExecutorUtil","testOverridableClassNames"),
86                 new ApprovalOveradableClassName("org.ejbca.ui.web.admin.rainterface.RAInterfaceBean","markForRecovery"),
87                 new ApprovalOveradableClassName("org.ejbca.extra.caservice.ExtRACAProcess","processExtRARevocationRequest"),
88                 new ApprovalOveradableClassName("se.primeKey.cardPersonalization.ra.connection.ejbca.EjbcaConnection",null)
89             };
90         ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_GENERATED, UserDataConstants.STATUS_NEW, admin, null, numOfApprovalsRequired, 1, 1);
91         approvalRequired = ApprovalExecutorUtil.requireApproval(ar, NONAPPROVABLECLASSNAMES_SETUSERSTATUS3);
92         assertFalse(approvalRequired);
93
94     }
95     
96     public void testAllowedTransitions() {
97         int numOfApprovalsRequired = 1;
98         ChangeStatusEndEntityApprovalRequest ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_NEW, UserDataConstants.STATUS_INPROCESS, admin, null, numOfApprovalsRequired, 1, 1);
99         boolean approvalRequired = ApprovalExecutorUtil.requireApproval(ar, null);
100         assertFalse(approvalRequired);
101         ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_GENERATED, UserDataConstants.STATUS_NEW, admin, null, numOfApprovalsRequired, 1, 1);
102         approvalRequired = ApprovalExecutorUtil.requireApproval(ar, null);
103         assertTrue(approvalRequired);
104         ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_INPROCESS, UserDataConstants.STATUS_GENERATED, admin, null, numOfApprovalsRequired, 1, 1);
105         approvalRequired = ApprovalExecutorUtil.requireApproval(ar, null);
106         assertFalse(approvalRequired);
107         ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_INPROCESS, UserDataConstants.STATUS_FAILED, admin, null, numOfApprovalsRequired, 1, 1);
108         approvalRequired = ApprovalExecutorUtil.requireApproval(ar, null);
109         assertFalse(approvalRequired);
110         ar = new ChangeStatusEndEntityApprovalRequest("foo", UserDataConstants.STATUS_REVOKED, UserDataConstants.STATUS_NEW, admin, null, numOfApprovalsRequired, 1, 1);
111         approvalRequired = ApprovalExecutorUtil.requireApproval(ar, null);
112         assertTrue(approvalRequired);
113         
114     }
115 }
116
Popular Tags