<commit_before>/*
 * Copyright 2009 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.coa.identity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.kuali.kfs.coa.businessobject.Chart;
import org.kuali.kfs.coa.service.ChartService;
import org.kuali.kfs.sys.ConfigureContext;
import org.kuali.kfs.sys.KFSConstants;
import org.kuali.kfs.sys.context.KualiTestBase;
import org.kuali.kfs.sys.context.SpringContext;
import org.kuali.kfs.sys.identity.KfsKimAttributes;
import org.kuali.rice.kim.bo.Person;
import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo;
import org.kuali.rice.kim.bo.types.dto.AttributeSet;
import org.kuali.rice.kim.service.IdentityManagementService;
import org.kuali.rice.kim.service.PersonService;
import org.kuali.rice.kim.service.RoleManagementService;

@ConfigureContext
public class ChartManagerRoleTest extends KualiTestBase {


    public void testGettingPersonForChartManagers() {
        IdentityManagementService idm = SpringContext.getBean(IdentityManagementService.class);
        RoleManagementService rms = SpringContext.getBean(RoleManagementService.class);
        List<String> roleIds = new ArrayList<String>();

        AttributeSet qualification = new AttributeSet();
        
        for ( String chart : SpringContext.getBean(ChartService.class).getAllChartCodes() ) {
        
            qualification.put(KfsKimAttributes.CHART_OF_ACCOUNTS_CODE, chart);
            
//            System.out.println( chart );
            roleIds.add(rms.getRoleIdByName(KFSConstants.ParameterNamespaces.KFS, "Chart Manager"));
            Collection<RoleMembershipInfo> chartManagers = rms.getRoleMembers(roleIds, qualification);
//            System.out.println( chartManagers );

            assertEquals( "There should be only one chart manager per chart: " + chart, 1, chartManagers.size() );
            
            for ( RoleMembershipInfo rmi : chartManagers ) {
                Person chartManager = SpringContext.getBean(PersonService.class).getPerson( rmi.getMemberId() );
                assertNotNull( "unable to retrieve person object for principalId: " + rmi.getMemberId(), chartManager );
            }
        }
    }
}
<commit_msg>Updated test to look at the returned object a little more thoroughly.<commit_after>/*
 * Copyright 2009 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.coa.identity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.kuali.kfs.coa.businessobject.Chart;
import org.kuali.kfs.coa.service.ChartService;
import org.kuali.kfs.sys.ConfigureContext;
import org.kuali.kfs.sys.KFSConstants;
import org.kuali.kfs.sys.context.KualiTestBase;
import org.kuali.kfs.sys.context.SpringContext;
import org.kuali.kfs.sys.identity.KfsKimAttributes;
import org.kuali.rice.kim.bo.Person;
import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo;
import org.kuali.rice.kim.bo.types.dto.AttributeSet;
import org.kuali.rice.kim.service.IdentityManagementService;
import org.kuali.rice.kim.service.PersonService;
import org.kuali.rice.kim.service.RoleManagementService;

@ConfigureContext
public class ChartManagerRoleTest extends KualiTestBase {


    public void testGettingPersonForChartManagers() {
        IdentityManagementService idm = SpringContext.getBean(IdentityManagementService.class);
        RoleManagementService rms = SpringContext.getBean(RoleManagementService.class);
        List<String> roleIds = new ArrayList<String>();

        AttributeSet qualification = new AttributeSet();
        
        for ( String chart : SpringContext.getBean(ChartService.class).getAllChartCodes() ) {
        
            qualification.put(KfsKimAttributes.CHART_OF_ACCOUNTS_CODE, chart);
            
//            System.out.println( chart );
            roleIds.add(rms.getRoleIdByName(KFSConstants.ParameterNamespaces.KFS, "Chart Manager"));
            Collection<RoleMembershipInfo> chartManagers = rms.getRoleMembers(roleIds, qualification);
//            System.out.println( chartManagers );

            assertEquals( "There should be only one chart manager per chart: " + chart, 1, chartManagers.size() );
            
            for ( RoleMembershipInfo rmi : chartManagers ) {
                Person chartManager = SpringContext.getBean(PersonService.class).getPerson( rmi.getMemberId() );
                System.out.println( chartManager );                
                assertNotNull( "unable to retrieve person object for principalId: " + rmi.getMemberId(), chartManager );
                assertFalse( "name should not have been blank", chartManager.getName().equals("") );
                assertFalse( "campus code should not have been blank", chartManager.getCampusCode().equals("") );
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09180977542932629, 'fraction_numerical': 0.002642007926023778, 'mean_word_length': 3.1945983379501386, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '829197', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1695, 'n_words': 410}