001/**
002 * Copyright 2004-2015 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.kpme.core.job;
017
018import java.sql.Time;
019import java.sql.Timestamp;
020import java.util.List;
021
022import junit.framework.Assert;
023
024import org.joda.time.DateTime;
025import org.joda.time.LocalDate;
026import org.junit.Ignore;
027import org.junit.Test;
028import org.kuali.kpme.core.CoreUnitTestCase;
029import org.kuali.kpme.core.IntegrationTest;
030import org.kuali.kpme.core.api.job.Job;
031import org.kuali.kpme.core.calendar.CalendarBo;
032import org.kuali.kpme.core.calendar.entry.CalendarEntryBo;
033import org.kuali.kpme.core.paytype.PayTypeBo;
034import org.kuali.kpme.core.service.HrServiceLocator;
035import org.kuali.kpme.core.util.TKUtils;
036import org.kuali.rice.krad.service.KRADServiceLocator;
037
038/**
039 * This class needs refactored - the name job test implies that it should unit test on the Job object, especially considering it's package location.
040 *
041 *
042 */
043@IntegrationTest
044public class JobTest extends CoreUnitTestCase {
045
046        private static final String CALENDAR_GROUP = "BWN-CAL";
047        private static Long jobId = 23L;//id entered in the bootstrap SQL
048        private static Long jobNumber = 5L;//number entered in the bootstrap SQL
049        public static final String TEST_USER = "admin";
050
051
052        @Test
053        public void testInsertPayCalendar() throws Exception {
054        CalendarBo payCalendar = new CalendarBo();
055                payCalendar.setHrCalendarId("1001");
056                payCalendar.setCalendarName(CALENDAR_GROUP);
057
058                payCalendar.setFlsaBeginDay("Sun");
059                payCalendar.setFlsaBeginTime(Time.valueOf("0:00:00"));
060        payCalendar.setCalendarDescriptions("Test Description");
061
062                KRADServiceLocator.getBusinessObjectService().save(payCalendar);
063                Assert.assertTrue(HrServiceLocator.getCalendarService().getCalendar(payCalendar.getHrCalendarId()) != null);
064
065        }
066
067        @Test
068        public void testInsertPayCalendarDates() throws Exception {
069                CalendarEntryBo payCalendarDates = new CalendarEntryBo();
070                payCalendarDates.setHrCalendarEntryId("1001");
071                payCalendarDates.setHrCalendarId("1001");
072
073                DateTime beginPeriodDateTime = new DateTime(2010, 7, 1, 0, 0, 0);
074                DateTime endPeriodDateTime = new DateTime(2010, 7, 15, 0, 0, 0);
075
076                payCalendarDates.setBeginPeriodFullDateTime(beginPeriodDateTime);
077                payCalendarDates.setEndPeriodFullDateTime(endPeriodDateTime);
078                payCalendarDates.setCalendarName(CALENDAR_GROUP);
079
080                KRADServiceLocator.getBusinessObjectService().save(payCalendarDates);
081                Assert.assertTrue(HrServiceLocator.getCalendarEntryService().getCalendarEntry(payCalendarDates.getHrCalendarEntryId()) != null);
082
083        }
084
085        @Test
086        public void testInsertPayType() throws Exception {
087                PayTypeBo payType = new PayTypeBo();
088                payType.setHrPayTypeId("1001");
089                payType.setPayType("BW");
090                payType.setRegEarnCode("RGN");
091                payType.setEffectiveLocalDate(LocalDate.now());
092                payType.setTimestamp(new Timestamp(System.currentTimeMillis()));
093                // KPME-2252
094//              payType.setGroupKeyCode("*-*");
095                payType.setFlsaStatus("NE");
096                payType.setPayFrequency("M");
097        payType.setUserPrincipalId("admin");
098
099                payType = (PayTypeBo) KRADServiceLocator.getBusinessObjectService().save(payType);
100                Assert.assertTrue(HrServiceLocator.getPayTypeService().getPayType(payType.getPayType(), payType.getEffectiveLocalDate()) != null);
101                KRADServiceLocator.getBusinessObjectService().delete(payType);
102        }
103
104        @Ignore
105        @Test
106        public void testGetJobs() {
107                /**
108                 * This test is conducted in JobServiceImplTest.java
109                 */
110                DateTime payPeriodEndDate = new DateTime(2010,7,30,1,0,0,0, TKUtils.getSystemDateTimeZone());
111                List<Job> jobs = HrServiceLocator.getJobService().getJobs(TEST_USER, payPeriodEndDate.toLocalDate());
112                Assert.assertNotNull("Jobs was null", jobs);
113                Assert.assertEquals("Incorrect number of jobs", 2, jobs.size());
114        }
115
116
117        @Test
118        public void testSaveAndFetchObject() throws Exception{
119                //Confirming the save and fetch
120                //save an object and confirm that it can be fetched
121        }
122}
123