<commit_before>/*
 * Copyright 2006-2008 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.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.osedu.org/licenses/ECL-2.0
 * 
 * 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.kra.workflow.attribute;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.kuali.core.UserSession;
import org.kuali.core.service.BusinessObjectService;
import org.kuali.core.service.DocumentService;
import org.kuali.core.util.GlobalVariables;
import org.kuali.core.workflow.service.KualiWorkflowDocument;
import org.kuali.kra.KraTestBase;
import org.kuali.kra.infrastructure.KraServiceLocator;
import org.kuali.kra.proposaldevelopment.bo.ProposalPerson;
import org.kuali.kra.proposaldevelopment.document.ProposalDevelopmentDocument;
import org.kuali.kra.workflow.ProposalPersonRoleAttribute;
import org.kuali.rice.KNSServiceLocator;
import edu.iu.uis.eden.Id;
import edu.iu.uis.eden.KEWServiceLocator;
import edu.iu.uis.eden.engine.RouteContext;
import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
import edu.iu.uis.eden.routetemplate.ResolvedQualifiedRole;
import edu.iu.uis.eden.routetemplate.Role;
import edu.iu.uis.eden.user.AuthenticationUserId;
public class ProposalPersonRoleAttributeTest extends KraTestBase{
    
    private DocumentService documentService = null;
    private static final Role PROPOSAL_INVESTIGATOR_ROLE = new Role(ProposalPersonRoleAttribute.class, "PROPOSALINVESTIGATOR", "Proposal Investigator");
    private static final Role CO_INVESTIGATOR_ROLE = new Role(ProposalPersonRoleAttribute.class, "COINVESTIGATOR", "Co-Investigator");
    private static final Role INVESTIGATORS = new Role(ProposalPersonRoleAttribute.class, "INVESTIGATORS", "Investigators");
    private static final Role KEY_PERSON_ROLE = new Role(ProposalPersonRoleAttribute.class, "KEYPERSON", "Key Person");
    private static final Role PROPOSAL_PERSON_ROLE = new Role(ProposalPersonRoleAttribute.class, "PROPOSALPERSONS", "Proposal Person");
    private BusinessObjectService bos;
    @Before
    public void setUp() throws Exception {
        super.setUp();
        GlobalVariables.setUserSession(new UserSession("quickstart"));
        documentService = KNSServiceLocator.getDocumentService();
        bos = KraServiceLocator.getService(BusinessObjectService.class);
    }

    @After
    public void tearDown() throws Exception {
        GlobalVariables.setUserSession(null);
        documentService = null;
        super.tearDown();
    }
    @Test
    public void proposalpersontest() throws Exception {
        ProposalDevelopmentDocument proposaldevelopmentdocument = (ProposalDevelopmentDocument) documentService.getNewDocument("ProposalDevelopmentDocument");
        setDocumentFields(proposaldevelopmentdocument);
        documentService.saveDocument(proposaldevelopmentdocument);
        DocumentRouteHeaderValue routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(proposaldevelopmentdocument.getDocumentHeader().getWorkflowDocument().getRouteHeaderId());
        RouteContext routecontext=RouteContext.createNewRouteContext();  
        routecontext.setDocument(routeHeader);
        ProposalPersonRoleAttribute roleattribute=new ProposalPersonRoleAttribute();
        ResolvedQualifiedRole resolvedrole=roleattribute.resolveQualifiedRole(routecontext, PROPOSAL_INVESTIGATOR_ROLE.getName(), PROPOSAL_INVESTIGATOR_ROLE.getBaseName());
       
        for (Iterator<Id> ids = resolvedrole.getRecipients().iterator(); ids.hasNext();) {
            AuthenticationUserId authid = (AuthenticationUserId) ids.next();
            assertEquals(authid.getId(),"tdurkin");
        }

        ResolvedQualifiedRole resolvedrole1=roleattribute.resolveQualifiedRole(routecontext, CO_INVESTIGATOR_ROLE.getName(), CO_INVESTIGATOR_ROLE.getBaseName());
         for (Iterator<Id> ids = resolvedrole1.getRecipients().iterator(); ids.hasNext();) {
            AuthenticationUserId authid = (AuthenticationUserId) ids.next();
            assertEquals(authid.getId(),"jtester");
        }
        ResolvedQualifiedRole resolvedrole2=roleattribute.resolveQualifiedRole(routecontext, KEY_PERSON_ROLE.getName(), KEY_PERSON_ROLE.getBaseName());
         for (Iterator<Id> ids = resolvedrole2.getRecipients().iterator(); ids.hasNext();) {
            AuthenticationUserId authid = (AuthenticationUserId) ids.next();
            assertEquals(authid.getId(),"bhutchinson");
        }
         

    
    }
    private void setDocumentFields(ProposalDevelopmentDocument document) {
        Date requestedStartDateInitial = new Date(System.currentTimeMillis());
        Date requestedEndDateInitial = new Date(System.currentTimeMillis());
        List<ProposalPerson> ProposalPersons= new ArrayList<ProposalPerson>();

        ProposalPerson person = new ProposalPerson();
        person.setProposalNumber("7");
        person.setProposalPersonNumber(1);
        person.setProposalPersonRoleId("PI");
        person.setPersonId("000000001");
        person.setUserName("tdurkin");
        person.setOptInCertificationStatus("Y");
        person.setOptInUnitStatus("Y");


        ProposalPerson person2 = new ProposalPerson();
        person2.setProposalNumber("7");
        person2.setProposalPersonNumber(3);
        person2.setProposalPersonRoleId("COI");
        person2.setPersonId("000000008");
        person2.setUserName("jtester");
        person2.setOptInCertificationStatus("Y");
        person2.setOptInUnitStatus("Y");
                
        ProposalPerson person3= new ProposalPerson();
        person3.setProposalNumber("7");
        person3.setProposalPersonNumber(5);
        person3.setProposalPersonRoleId("KP");
        person3.setPersonId("000000005");
        person3.setUserName("bhutchinson");
        person3.setOptInCertificationStatus("Y");
        person3.setOptInUnitStatus("Y");
        person3.setProjectRole("test");
        ProposalPersons.add(person);
       <commit_msg>KRACOEUS-2069 : Username was too long (> 10 chars); changed bhutchinson to aslusar<commit_after>/*
 * Copyright 2006-2008 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.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.osedu.org/licenses/ECL-2.0
 * 
 * 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.kra.workflow.attribute;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.kuali.core.UserSession;
import org.kuali.core.service.BusinessObjectService;
import org.kuali.core.service.DocumentService;
import org.kuali.core.util.GlobalVariables;
import org.kuali.core.workflow.service.KualiWorkflowDocument;
import org.kuali.kra.KraTestBase;
import org.kuali.kra.infrastructure.KraServiceLocator;
import org.kuali.kra.proposaldevelopment.bo.ProposalPerson;
import org.kuali.kra.proposaldevelopment.document.ProposalDevelopmentDocument;
import org.kuali.kra.workflow.ProposalPersonRoleAttribute;
import org.kuali.rice.KNSServiceLocator;
import edu.iu.uis.eden.Id;
import edu.iu.uis.eden.KEWServiceLocator;
import edu.iu.uis.eden.engine.RouteContext;
import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
import edu.iu.uis.eden.routetemplate.ResolvedQualifiedRole;
import edu.iu.uis.eden.routetemplate.Role;
import edu.iu.uis.eden.user.AuthenticationUserId;
public class ProposalPersonRoleAttributeTest extends KraTestBase{
    
    private DocumentService documentService = null;
    private static final Role PROPOSAL_INVESTIGATOR_ROLE = new Role(ProposalPersonRoleAttribute.class, "PROPOSALINVESTIGATOR", "Proposal Investigator");
    private static final Role CO_INVESTIGATOR_ROLE = new Role(ProposalPersonRoleAttribute.class, "COINVESTIGATOR", "Co-Investigator");
    private static final Role INVESTIGATORS = new Role(ProposalPersonRoleAttribute.class, "INVESTIGATORS", "Investigators");
    private static final Role KEY_PERSON_ROLE = new Role(ProposalPersonRoleAttribute.class, "KEYPERSON", "Key Person");
    private static final Role PROPOSAL_PERSON_ROLE = new Role(ProposalPersonRoleAttribute.class, "PROPOSALPERSONS", "Proposal Person");
    private BusinessObjectService bos;
    @Before
    public void setUp() throws Exception {
        super.setUp();
        GlobalVariables.setUserSession(new UserSession("quickstart"));
        documentService = KNSServiceLocator.getDocumentService();
        bos = KraServiceLocator.getService(BusinessObjectService.class);
    }

    @After
    public void tearDown() throws Exception {
        GlobalVariables.setUserSession(null);
        documentService = null;
        super.tearDown();
    }
    @Test
    public void proposalpersontest() throws Exception {
        ProposalDevelopmentDocument proposaldevelopmentdocument = (ProposalDevelopmentDocument) documentService.getNewDocument("ProposalDevelopmentDocument");
        setDocumentFields(proposaldevelopmentdocument);
        documentService.saveDocument(proposaldevelopmentdocument);
        DocumentRouteHeaderValue routeHeader = KEWServiceLocator.getRouteHeaderService().getRouteHeader(proposaldevelopmentdocument.getDocumentHeader().getWorkflowDocument().getRouteHeaderId());
        RouteContext routecontext=RouteContext.createNewRouteContext();  
        routecontext.setDocument(routeHeader);
        ProposalPersonRoleAttribute roleattribute=new ProposalPersonRoleAttribute();
        ResolvedQualifiedRole resolvedrole=roleattribute.resolveQualifiedRole(routecontext, PROPOSAL_INVESTIGATOR_ROLE.getName(), PROPOSAL_INVESTIGATOR_ROLE.getBaseName());
       
        for (Iterator<Id> ids = resolvedrole.getRecipients().iterator(); ids.hasNext();) {
            AuthenticationUserId authid = (AuthenticationUserId) ids.next();
            assertEquals(authid.getId(),"tdurkin");
        }

        ResolvedQualifiedRole resolvedrole1=roleattribute.resolveQualifiedRole(routecontext, CO_INVESTIGATOR_ROLE.getName(), CO_INVESTIGATOR_ROLE.getBaseName());
         for (Iterator<Id> ids = resolvedrole1.getRecipients().iterator(); ids.hasNext();) {
            AuthenticationUserId authid = (AuthenticationUserId) ids.next();
            assertEquals(authid.getId(),"jtester");
        }
        ResolvedQualifiedRole resolvedrole2=roleattribute.resolveQualifiedRole(routecontext, KEY_PERSON_ROLE.getName(), KEY_PERSON_ROLE.getBaseName());
         for (Iterator<Id> ids = resolvedrole2.getRecipients().iterator(); ids.hasNext();) {
            AuthenticationUserId authid = (AuthenticationUserId) ids.next();
            assertEquals(authid.getId(),"aslusar");
        }
         

    
    }
    private void setDocumentFields(ProposalDevelopmentDocument document) {
        Date requestedStartDateInitial = new Date(System.currentTimeMillis());
        Date requestedEndDateInitial = new Date(System.currentTimeMillis());
        List<ProposalPerson> ProposalPersons= new ArrayList<ProposalPerson>();

        ProposalPerson person = new ProposalPerson();
        person.setProposalNumber("7");
        person.setProposalPersonNumber(1);
        person.setProposalPersonRoleId("PI");
        person.setPersonId("000000001");
        person.setUserName("tdurkin");
        person.setOptInCertificationStatus("Y");
        person.setOptInUnitStatus("Y");


        ProposalPerson person2 = new ProposalPerson();
        person2.setProposalNumber("7");
        person2.setProposalPersonNumber(3);
        person2.setProposalPersonRoleId("COI");
        person2.setPersonId("000000008");
        person2.setUserName("jtester");
        person2.setOptInCertificationStatus("Y");
        person2.setOptInUnitStatus("Y");
                
        ProposalPerson person3= new ProposalPerson();
        person3.setProposalNumber("7");
        person3.setProposalPersonNumber(5);
        person3.setProposalPersonRoleId("KP");
        person3.setPersonId("000000005");
        person3.setUserName("aslusar");
        person3.setOptInCertificationStatus("Y");
        person3.setOptInUnitStatus("Y");
        person3.setProjectRole("test");
        ProposalPersons.add(person);
       
{'fraction_non_alphanumeric': 0.09659395331037123, 'fraction_numerical': 0.010562571756601608, 'mean_word_length': 4.412593206296603, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7395512', 'n_tokens_mistral': 3753, 'n_tokens_neox': 3632, 'n_words': 678}