Clover Coverage Report - kew-test 2.0.0-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
22   91   8   5.5
6   52   0.36   4
4     2  
1    
 
  MockRole       Line # 45 22 0% 8 32 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16    package org.kuali.rice.kew.rule;
17   
18    import java.util.ArrayList;
19    import java.util.Collections;
20    import java.util.List;
21   
22    import org.apache.commons.lang.StringUtils;
23    import org.kuali.rice.kew.engine.RouteContext;
24    import org.kuali.rice.kew.identity.Id;
25    import org.kuali.rice.kew.rule.ResolvedQualifiedRole;
26    import org.kuali.rice.kew.rule.Role;
27    import org.kuali.rice.kew.rule.UnqualifiedRoleAttribute;
28    import org.kuali.rice.kew.identity.PrincipalName;
29    import org.kuali.rice.kew.workgroup.GroupNameId;
30   
31   
32   
33    /**
34    * A RoleAttribute implementation that can be used in tests to easily provide canned/pre-configured
35    * recipients. The role name should be a comma-delimited list of user authentication ids:
36    * <pre>
37    * <responsibilities>
38    * <responsibility>
39    * <role>org.kuali.rice.kew.rule.MockRole!user1,user2,user3</role>
40    * </responsibility>
41    * </responsibilities>
42    * </pre>
43    * @author Kuali Rice Team (rice.collab@kuali.org)
44    */
 
45    public class MockRole extends UnqualifiedRoleAttribute {
46    private static final Role ROLE = new Role(MockRole.class, "List of authentication ids", "List of authentication ids");
47    private static final List<Role> ROLES;
 
48  0 toggle static {
49  0 ArrayList<Role> roles = new ArrayList<Role>(1);
50  0 roles.add(ROLE);
51  0 ROLES = Collections.unmodifiableList(roles);
52    }
53   
 
54  0 toggle public MockRole() {
55  0 super(ROLES);
56    }
57   
58    /**
59    * Overridden to accept any role name
60    * @see org.kuali.rice.kew.rule.UnqualifiedRoleAttribute#isValidRoleName(java.lang.String)
61    */
 
62  0 toggle @Override
63    protected boolean isValidRoleName(String roleName) {
64  0 return true;
65    }
66   
 
67  0 toggle @Override
68    protected ResolvedQualifiedRole resolveRole(RouteContext routeContext, String roleName) {
69  0 String[] ids = roleName.split("[,\\s+]");
70  0 ResolvedQualifiedRole rqr = new ResolvedQualifiedRole();
71  0 for (String id: ids) {
72  0 String type = "user";
73  0 String[] components = id.split(":", 2);
74  0 if (components.length > 1 && !StringUtils.isEmpty(components[0])) {
75  0 type = components[0].trim();
76    }
77  0 Id recipientId;
78  0 if ("user".equals(type)) {
79  0 recipientId = new PrincipalName(id);
80  0 } else if ("group".equals(type)) {
81  0 recipientId = new GroupNameId(id);
82    } else {
83  0 throw new RuntimeException("Unknown role recipient type: '" + type + "'. Must be 'user' or 'group'.");
84    }
85  0 rqr.getRecipients().add(recipientId);
86    }
87  0 rqr.setQualifiedRoleLabel("Recipients from parsing mock role: " + roleName);
88  0 rqr.setAnnotation("Recipients from parsing mock role: " + roleName);
89  0 return rqr;
90    }
91    }