001    /**
002     * Copyright 2004-2013 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     */
016    package org.kuali.hr.job;
017    
018    import java.sql.Date;
019    import java.sql.Time;
020    import java.sql.Timestamp;
021    import java.util.List;
022    
023    import junit.framework.Assert;
024    
025    import org.joda.time.DateTime;
026    import org.joda.time.DateTimeZone;
027    import org.junit.Test;
028    import org.kuali.hr.test.KPMETestCase;
029    import org.kuali.hr.time.calendar.Calendar;
030    import org.kuali.hr.time.calendar.CalendarEntries;
031    import org.kuali.hr.time.paytype.PayType;
032    import org.kuali.hr.time.service.base.TkServiceLocator;
033    import org.kuali.hr.time.test.HtmlUnitUtil;
034    import org.kuali.hr.time.test.TkTestConstants;
035    import org.kuali.hr.time.util.TKUtils;
036    import org.kuali.rice.krad.service.KRADServiceLocator;
037    
038    import com.gargoylesoftware.htmlunit.html.HtmlPage;
039    
040    /**
041     * This class needs refactored - the name job test implies that it should unit test on the Job object, especially considering it's package location.
042     *
043     *
044     */
045    public class JobTest extends KPMETestCase {
046    
047            private static final String CALENDAR_GROUP = "BWN-CAL";
048            private static Long jobId = 23L;//id entered in the bootstrap SQL
049            private static Long jobNumber = 5L;//number entered in the bootstrap SQL
050            public static final String TEST_USER = "admin";
051    
052    
053            @Test
054            public void testInsertPayCalendar() throws Exception {
055                    Calendar payCalendar = new Calendar();
056                    payCalendar.setHrCalendarId("1001");
057                    payCalendar.setCalendarName(CALENDAR_GROUP);
058    
059                    payCalendar.setFlsaBeginDay("Sun");
060                    payCalendar.setFlsaBeginTime(Time.valueOf("0:00:00"));
061            payCalendar.setCalendarDescriptions("Test Description");
062    
063                    KRADServiceLocator.getBusinessObjectService().save(payCalendar);
064                    Assert.assertTrue(TkServiceLocator.getCalendarService().getCalendar(payCalendar.getHrCalendarId()) != null);
065    
066            }
067    
068            @Test
069            public void testInsertPayCalendarDates() throws Exception {
070                    CalendarEntries payCalendarDates = new CalendarEntries();
071                    payCalendarDates.setHrCalendarEntriesId("1001");
072                    payCalendarDates.setHrCalendarId("1001");
073    
074                    java.util.Calendar cal = java.util.Calendar.getInstance();
075                    cal.set(java.util.Calendar.MONTH, 7);
076                    cal.set(java.util.Calendar.DATE, 1);
077                    cal.set(java.util.Calendar.YEAR, 2010);
078    
079                    payCalendarDates.setBeginPeriodDateTime(new java.sql.Date(cal.getTime().getTime()));
080                    payCalendarDates.setCalendarName(CALENDAR_GROUP);
081                    cal.set(java.util.Calendar.DATE, 14);
082                    payCalendarDates.setEndPeriodDateTime(new java.sql.Date(cal.getTime().getTime()));
083    
084                    KRADServiceLocator.getBusinessObjectService().save(payCalendarDates);
085                    Assert.assertTrue(TkServiceLocator.getCalendarEntriesService().getCalendarEntries(payCalendarDates.getHrCalendarEntriesId()) != null);
086    
087            }
088    
089            @Test
090            public void testInsertPayType() throws Exception {
091    
092                    long currentTimestamp = java.util.Calendar.getInstance().getTime().getTime();
093    
094                    PayType payType = new PayType();
095                    payType.setHrPayTypeId("1001");
096                    payType.setPayType("BW");
097                    payType.setRegEarnCode("RGN");
098                    payType.setEffectiveDate(new java.sql.Date(currentTimestamp));
099                    payType.setTimestamp(new Timestamp(currentTimestamp));
100    
101                    KRADServiceLocator.getBusinessObjectService().save(payType);
102                    Assert.assertTrue(TkServiceLocator.getPayTypeService().getPayType(payType.getPayType(), payType.getEffectiveDate()) != null);
103            }
104    
105            @Test
106            public void jobMaintenancePage() throws Exception{
107                    HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.JOB_MAINT_URL);
108                    lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
109                    HtmlUnitUtil.createTempFile(lookupPage);
110                    Assert.assertTrue("Page contains admin entry", lookupPage.asText().contains("admin"));
111                    // xichen, changed to edit jobId 23, because clickAnchorContainingText() is a wild search. The test was editing jobId 1, it returned the first entry whose jobId starts with 1.
112                    HtmlPage editPage = HtmlUnitUtil.clickAnchorContainingText(lookupPage, "edit", jobId.toString());
113                    HtmlUnitUtil.createTempFile(editPage);
114                    Assert.assertTrue("Maintenance Page contains the correct job number", editPage.asText().contains(jobNumber.toString()));
115            }
116    
117            @Test
118            public void testGetJobs() {
119                    Date payPeriodEndDate = new Date((new DateTime(2010,7,30,1,0,0,0, TKUtils.getSystemDateTimeZone())).getMillis());
120                    List<Job> jobs = TkServiceLocator.getJobService().getJobs(TEST_USER, payPeriodEndDate);
121                    Assert.assertNotNull("Jobs was null", jobs);
122                    Assert.assertEquals("Incorrect number of jobs", 2, jobs.size());
123            }
124    
125    
126            @Test
127            public void testSaveAndFetchObject() throws Exception{
128                    //Confirming the save and fetch
129                    //save an object and confirm that it can be fetched
130            }
131    
132            @Test
133            public void testMaintenancePageNew() throws Exception {
134                    //create new
135                    //input the data
136                    //confirm submit works
137            }
138    
139            @Test
140            public void testMaintenancePageEdit() throws Exception {
141                    HtmlPage lookupPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.JOB_MAINT_URL);
142                    lookupPage = HtmlUnitUtil.clickInputContainingText(lookupPage, "search");
143                    HtmlPage editPage = HtmlUnitUtil.clickAnchorContainingText(lookupPage, "edit", jobId.toString());
144                    //input bad dept, sal group, job location, pay type, pay grade
145                    //submit
146                    //confirm each error shows up
147    
148                    //use each of the above lookups to populate the page
149                    //submit
150                    //confirm submit worked
151    
152            }
153    }
154