<commit_before>/*
 * Copyright 2010 The Kuali Foundation.
 * 
 * Licensed under the Educational Community License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.opensource.org/licenses/ecl1.php
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kfs.sys.identity;

import java.util.Arrays;
import java.util.Collection;

import org.kuali.kfs.sys.context.KualiTestBase;
import org.kuali.kfs.sys.context.SpringContext;
import org.kuali.rice.kim.bo.role.dto.KimRoleInfo;
import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo;
import org.kuali.rice.kim.bo.types.dto.AttributeSet;
import org.kuali.rice.kim.service.PersonService;
import org.kuali.rice.kim.service.RoleManagementService;
import org.kuali.rice.kns.util.GlobalVariables;

public abstract class RoleTestBase extends KualiTestBase {

    
    protected Collection<RoleMembershipInfo> getRoleMembers(String roleNamespace, String roleName, AttributeSet roleQualifications) {
        final RoleManagementService roleManagementService = SpringContext.getBean(RoleManagementService.class);
        final KimRoleInfo roleInfo = roleManagementService.getRoleByName(roleNamespace, roleName);
        return roleManagementService.getRoleMembers(Arrays.asList(new String[] { roleInfo.getRoleId() }), roleQualifications);
    }
    
    protected String getPrincipalIdByName(String principalName) {
        return SpringContext.getBean(PersonService.class).getPersonByPrincipalName(principalName).getPrincipalId();
    }
    
    
    protected void assertUserIsRoleMember(String principalId, String roleNamespace, String roleName, AttributeSet roleQualifications) {
        final Collection<RoleMembershipInfo> roleMembers = getRoleMembers(roleNamespace, roleName, roleQualifications);
        
        int memberCount = 0;
        for (RoleMembershipInfo roleMember : roleMembers) {
            if (roleMember.getMemberTypeCode().equals("P") && roleMember.getMemberId().equals(principalId)) {
                memberCount += 1;
            }
        }
        assertTrue("Principal "+SpringContext.getBean(PersonService.class).getPerson(principalId).getName()+" not found in role: "+roleNamespace+" "+roleName, memberCount > 0);
        GlobalVariables.getErrorMap().clearErrorMessages();
    }
    
    protected void assertUserIsNotRoleMember(String principalId, String roleNamespace, String roleName, AttributeSet roleQualifications) {
        final Collection<RoleMembershipInfo> roleMembers = getRoleMembers(roleNamespace, roleName, roleQualifications);
        
        int memberCount = 0;
        for (RoleMembershipInfo roleMember : roleMembers) {
            if (roleMember.getMemberTypeCode().equals("P") && roleMember.getMemberId().equals(principalId)) {
                memberCount += 1;
            }
        }
        assertTrue("Principal "+SpringContext.getBean(PersonService.class).getPerson(principalId).getName()+" found in role: "+roleNamespace+" "+roleName, memberCount == 0);
    }<commit_msg>KFSMI-6987 Employee Benefit Expense Calc port<commit_after>/*
 * Copyright 2010 The Kuali Foundation.
 * 
 * Licensed under the Educational Community License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.opensource.org/licenses/ecl1.php
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kfs.sys.identity;

import java.util.Arrays;
import java.util.Collection;

import org.kuali.kfs.sys.context.KualiTestBase;
import org.kuali.kfs.sys.context.SpringContext;
import org.kuali.rice.kim.bo.role.dto.KimRoleInfo;
import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo;
import org.kuali.rice.kim.bo.types.dto.AttributeSet;
import org.kuali.rice.kim.service.PersonService;
import org.kuali.rice.kim.service.RoleManagementService;

public abstract class RoleTestBase extends KualiTestBase {

    
    protected Collection<RoleMembershipInfo> getRoleMembers(String roleNamespace, String roleName, AttributeSet roleQualifications) {
        final RoleManagementService roleManagementService = SpringContext.getBean(RoleManagementService.class);
        final KimRoleInfo roleInfo = roleManagementService.getRoleByName(roleNamespace, roleName);
        return roleManagementService.getRoleMembers(Arrays.asList(new String[] { roleInfo.getRoleId() }), roleQualifications);
    }
    
    protected String getPrincipalIdByName(String principalName) {
        return SpringContext.getBean(PersonService.class).getPersonByPrincipalName(principalName).getPrincipalId();
    }
    
    
    protected void assertUserIsRoleMember(String principalId, String roleNamespace, String roleName, AttributeSet roleQualifications) {
        final Collection<RoleMembershipInfo> roleMembers = getRoleMembers(roleNamespace, roleName, roleQualifications);
        
        int memberCount = 0;
        for (RoleMembershipInfo roleMember : roleMembers) {
            if (roleMember.getMemberTypeCode().equals("P") && roleMember.getMemberId().equals(principalId)) {
                memberCount += 1;
            }
        }
        assertTrue("Principal "+SpringContext.getBean(PersonService.class).getPerson(principalId).getName()+" not found in role: "+roleNamespace+" "+roleName, memberCount > 0);
    }
    
    protected void assertUserIsNotRoleMember(String principalId, String roleNamespace, String roleName, AttributeSet roleQualifications) {
        final Collection<RoleMembershipInfo> roleMembers = getRoleMembers(roleNamespace, roleName, roleQualifications);
        
        int memberCount = 0;
        for (RoleMembershipInfo roleMember : roleMembers) {
            if (roleMember.getMemberTypeCode().equals("P") && roleMember.getMemberId().equals(principalId)) {
                memberCount += 1;
            }
        }
        assertTrue("Principal "+SpringContext.getBean(PersonService.class).getPerson(principalId).getName()+" found in role: "+roleNamespace+" "+roleName, memberCount == 0);
    }
{'fraction_non_alphanumeric': 0.09178164367126575, 'fraction_numerical': 0.004499100179964007, 'mean_word_length': 4.133949191685912, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4823716', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1763, 'n_words': 436}