001/**
002 * Copyright 2004-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.hr.time.workflow;
017
018import java.util.List;
019
020import org.apache.log4j.Logger;
021import org.joda.time.DateTime;
022import org.junit.Assert;
023import org.junit.Ignore;
024import org.junit.Test;
025import org.kuali.hr.KPMEWebTestCase;
026import org.kuali.kpme.core.FunctionalTest;
027import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
028import org.kuali.kpme.core.api.job.Job;
029import org.kuali.kpme.core.calendar.entry.CalendarEntryBo;
030import org.kuali.kpme.core.service.HrServiceLocator;
031import org.kuali.kpme.core.util.TKUtils;
032import org.kuali.kpme.tklm.time.service.TkServiceLocator;
033import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
034import org.kuali.kpme.tklm.time.timesheet.service.TimesheetService;
035import org.kuali.rice.kew.service.KEWServiceLocator;
036import org.kuali.rice.krad.util.GlobalVariables;
037@Ignore
038@FunctionalTest
039public class WorkflowTimesheetTest extends KPMEWebTestCase {
040
041        private static final Logger LOG = Logger.getLogger(WorkflowTimesheetTest.class);
042        
043        @Test
044        public void testRouting() throws Exception {
045                TimesheetService timesheetService = TkServiceLocator.getTimesheetService();
046                Assert.assertNotNull("timesheet service null", timesheetService);
047
048                DateTime asOfDate = new DateTime(2010, 8, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone());
049
050                List<Job> jobs = HrServiceLocator.getJobService().getJobs(GlobalVariables.getUserSession().getPrincipalId(), asOfDate.toLocalDate());
051                Assert.assertNotNull("No jobs", jobs);
052                Assert.assertTrue("Should only be two Jobs.", jobs.size() == 2);
053                CalendarEntry pcd =  HrServiceLocator.getCalendarEntryService().getCurrentCalendarDates(GlobalVariables.getUserSession().getPrincipalId(), asOfDate);
054                Assert.assertNotNull("No PayCalendarDates", pcd);
055                
056                TimesheetDocument tdoc = timesheetService.openTimesheetDocument(GlobalVariables.getUserSession().getPrincipalId(), pcd);
057                String kewSourceDocumentStatus = KEWServiceLocator.getRouteHeaderService().getDocumentStatus(tdoc.getDocumentHeader().getDocumentId());
058                String tkSourceDocumentStatus  = tdoc.getDocumentHeader().getDocumentStatus();
059                Assert.assertEquals("Status should be equal.", kewSourceDocumentStatus, tkSourceDocumentStatus);
060                Assert.assertEquals("Document is already routed.", "I", tkSourceDocumentStatus);
061                timesheetService.routeTimesheet(GlobalVariables.getUserSession().getPrincipalId(), tdoc);
062                LOG.debug("Routing document: " + tdoc.getDocumentHeader().getDocumentId());
063                
064                kewSourceDocumentStatus = KEWServiceLocator.getRouteHeaderService().getDocumentStatus(tdoc.getDocumentHeader().getDocumentId());
065                tkSourceDocumentStatus  = tdoc.getDocumentHeader().getDocumentStatus();
066                
067                Assert.assertEquals("Status should be equal.", kewSourceDocumentStatus, tkSourceDocumentStatus);
068        }
069
070}