<commit_before>/*
 * Copyright 2005-2007 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.rice.kew.actions;


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

import org.junit.Test;
import org.kuali.rice.kew.actionitem.ActionItem;
import org.kuali.rice.kew.actionlist.service.ActionListService;
import org.kuali.rice.kew.dto.ActionTakenDTO;
import org.kuali.rice.kew.dto.NetworkIdDTO;
import org.kuali.rice.kew.dto.WorkflowGroupIdDTO;
import org.kuali.rice.kew.service.KEWServiceLocator;
import org.kuali.rice.kew.service.WorkflowDocument;
import org.kuali.rice.kew.service.WorkflowInfo;
import org.kuali.rice.kew.test.KEWTestCase;
import org.kuali.rice.kew.util.KEWConstants;
import org.kuali.rice.kew.workgroup.GroupNameId;
import org.kuali.rice.kew.workgroup.Workgroup;


/**
 * @author Kuali Rice Team (<EMAIL>)
 *
 *<authenticationId>ewestfal</authenticationId>
					<authenticationId>rkirkend</authenticationId>
					<authenticationId>jhopf</authenticationId>
					<authenticationId>bmcgough</authenticationId>
					<authenticationId>temay</authenticationId>
					<authenticationId>xqi</authenticationId>
					<authenticationId>natjohns</authenticationId>
					<authenticationId>pmckown</authenticationId>
					<authenticationId>jthomas</authenticationId>
					<authenticationId>jitrue</authenticationId>
 *
 */
public class TakeWorkgroupAuthorityTest extends KEWTestCase {

    public static final String DOC_TYPE = "TakeWorkgroupAuthorityDoc";
    public static List<String> WORKGROUP_MEMBERS = new ArrayList<String>();
    
    static {
        WORKGROUP_MEMBERS.add("ewestfal");
        WORKGROUP_MEMBERS.add("rkirkend");
        WORKGROUP_MEMBERS.add("jhopf");
        WORKGROUP_MEMBERS.add("bmcgough");
        WORKGROUP_MEMBERS.add("temay");
        WORKGROUP_MEMBERS.add("xqi");
        WORKGROUP_MEMBERS.add("natjohns");
        WORKGROUP_MEMBERS.add("pmckown");
        WORKGROUP_MEMBERS.add("jthomas");
        WORKGROUP_MEMBERS.add("jitrue");
    }
    
    protected void loadTestData() throws Exception {
        loadXmlFile("ActionsConfig.xml");
    }
    
    @Test public void testTakeWorkgroupAuthorityAction() throws Exception {
        
        WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("user1"), DOC_TYPE);
        doc.routeDocument("");
        
        Workgroup workgroup = KEWServiceLocator.getWorkgroupService().getWorkgroup(new GroupNameId("TestWorkgroup"));
        
        //verify that all members have the action item
        ActionListService aiService = KEWServiceLocator.getActionListService();
        Collection actionItems = aiService.findByRouteHeaderId(doc.getRouteHeaderId());
        assertTrue("There should be more than one action item", actionItems.size() > 1);
        for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
            ActionItem actionItem = (ActionItem) iter.next();
            assertTrue("Action Item not to workgroup member", WORKGROUP_MEMBERS.contains(actionItem.getUser().getAuthenticationUserId().getAuthenticationId()));
        }
        
        //have member rkirkend take authority
        doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), doc.getRouteHeaderId());
        doc.takeWorkgroupAuthority("", new WorkflowGroupIdDTO(workgroup.getWorkflowGroupId().getGroupId()));
        
        //verify that only rkirkend has an action item now.
        actionItems = aiService.findByRouteHeaderId(doc.getRouteHeaderId());
        assertEquals("There should only be a single action item to rkirkend", 1, actionItems.size());
        for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
            ActionItem actionItem = (ActionItem) iter.next();
            assertEquals("Action item should be to rkirkend", "rkirkend", actionItem.getUser().getAuthenticationUserId().getAuthenticationId());
        }
        
        //verify the action was recorded and by rkirkend
        WorkflowInfo wUtil = new WorkflowInfo();
        ActionTakenDTO[] actionsTaken = wUtil.getActionsTaken(doc.getRouteHeaderId());
        boolean rkirkendATFound = false;
        for (int i = 0; i < actionsTaken.length; i++) {
            ActionTakenDTO at = actionsTaken[i];
            if (at.getUserDTO().getNetworkId().equals("rkirkend")) {
                assertEquals("Incorrect action code recorded", KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, at.getActionTaken());
                rkirkendATFound = true;
            }
        }
        <commit_msg>KULRICE-2437 replaced kew workgroup with kim group<commit_after>/*
 * Copyright 2005-2007 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.rice.kew.actions;


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

import org.junit.Test;
import org.kuali.rice.kew.actionitem.ActionItem;
import org.kuali.rice.kew.actionlist.service.ActionListService;
import org.kuali.rice.kew.dto.ActionTakenDTO;
import org.kuali.rice.kew.dto.NetworkIdDTO;
import org.kuali.rice.kew.dto.WorkflowGroupIdDTO;
import org.kuali.rice.kew.service.KEWServiceLocator;
import org.kuali.rice.kew.service.WorkflowDocument;
import org.kuali.rice.kew.service.WorkflowInfo;
import org.kuali.rice.kew.test.KEWTestCase;
import org.kuali.rice.kew.util.KEWConstants;
import org.kuali.rice.kew.workgroup.GroupNameId;
import org.kuali.rice.kew.workgroup.Workgroup;
import org.kuali.rice.kim.bo.group.dto.GroupInfo;


/**
 * @author Kuali Rice Team (<EMAIL>)
 *
 *<authenticationId>ewestfal</authenticationId>
					<authenticationId>rkirkend</authenticationId>
					<authenticationId>jhopf</authenticationId>
					<authenticationId>bmcgough</authenticationId>
					<authenticationId>temay</authenticationId>
					<authenticationId>xqi</authenticationId>
					<authenticationId>natjohns</authenticationId>
					<authenticationId>pmckown</authenticationId>
					<authenticationId>jthomas</authenticationId>
					<authenticationId>jitrue</authenticationId>
 *
 */
public class TakeWorkgroupAuthorityTest extends KEWTestCase {

    public static final String DOC_TYPE = "TakeWorkgroupAuthorityDoc";
    public static List<String> WORKGROUP_MEMBERS = new ArrayList<String>();
    
    static {
        WORKGROUP_MEMBERS.add("ewestfal");
        WORKGROUP_MEMBERS.add("rkirkend");
        WORKGROUP_MEMBERS.add("jhopf");
        WORKGROUP_MEMBERS.add("bmcgough");
        WORKGROUP_MEMBERS.add("temay");
        WORKGROUP_MEMBERS.add("xqi");
        WORKGROUP_MEMBERS.add("natjohns");
        WORKGROUP_MEMBERS.add("pmckown");
        WORKGROUP_MEMBERS.add("jthomas");
        WORKGROUP_MEMBERS.add("jitrue");
    }
    
    protected void loadTestData() throws Exception {
        loadXmlFile("ActionsConfig.xml");
    }
    
    @Test public void testTakeWorkgroupAuthorityAction() throws Exception {
        
        WorkflowDocument doc = new WorkflowDocument(new NetworkIdDTO("user1"), DOC_TYPE);
        doc.routeDocument("");
        
        GroupInfo grpInfo=new GroupInfo();
        grpInfo.setGroupName("TestWorkgroup");
        
        //verify that all members have the action item
        ActionListService aiService = KEWServiceLocator.getActionListService();
        Collection actionItems = aiService.findByRouteHeaderId(doc.getRouteHeaderId());
        assertTrue("There should be more than one action item", actionItems.size() > 1);
        for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
            ActionItem actionItem = (ActionItem) iter.next();
            assertTrue("Action Item not to workgroup member", WORKGROUP_MEMBERS.contains(actionItem.getUser().getAuthenticationUserId().getAuthenticationId()));
        }
        
        //have member rkirkend take authority
        doc = new WorkflowDocument(new NetworkIdDTO("rkirkend"), doc.getRouteHeaderId());
        doc.takeGroupAuthority("", grpInfo);
        
        //verify that only rkirkend has an action item now.
        actionItems = aiService.findByRouteHeaderId(doc.getRouteHeaderId());
        assertEquals("There should only be a single action item to rkirkend", 1, actionItems.size());
        for (Iterator iter = actionItems.iterator(); iter.hasNext();) {
            ActionItem actionItem = (ActionItem) iter.next();
            assertEquals("Action item should be to rkirkend", "rkirkend", actionItem.getUser().getAuthenticationUserId().getAuthenticationId());
        }
        
        //verify the action was recorded and by rkirkend
        WorkflowInfo wUtil = new WorkflowInfo();
        ActionTakenDTO[] actionsTaken = wUtil.getActionsTaken(doc.getRouteHeaderId());
        boolean rkirkendATFound = false;
        for (int i = 0; i < actionsTaken.length; i++) {
            ActionTakenDTO at = actionsTaken[i];
            if (at.getUserDTO().getNetworkId().equals("rkirkend")) {
                assertEquals("Incorrect action code recorded", KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, at.getActionTaken());
                rkirkendATFound = true;
            }
        }
        
{'fraction_non_alphanumeric': 0.10407062285434036, 'fraction_numerical': 0.003334968121628249, 'mean_word_length': 3.6052393857271907, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '2895398', 'n_tokens_mistral': 3136, 'n_tokens_neox': 2983, 'n_words': 643}