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.time.systemlunch.rule; 017 018 import com.gargoylesoftware.htmlunit.html.HtmlPage; 019 import org.joda.time.DateTime; 020 import org.joda.time.DateTimeZone; 021 import org.junit.Assert; 022 import org.junit.Test; 023 import org.kuali.hr.test.KPMETestCase; 024 import org.kuali.hr.time.service.base.TkServiceLocator; 025 import org.kuali.hr.time.syslunch.rule.SystemLunchRule; 026 import org.kuali.hr.time.test.HtmlUnitUtil; 027 import org.kuali.hr.time.test.TkTestConstants; 028 import org.kuali.hr.time.test.TkTestUtils; 029 import org.kuali.hr.time.util.TKContext; 030 import org.kuali.hr.time.util.TKUtils; 031 import org.kuali.hr.time.util.TkConstants; 032 033 import java.sql.Date; 034 import java.util.LinkedHashMap; 035 import java.util.Map; 036 037 public class SystemLunchRuleTest extends KPMETestCase { 038 039 SystemLunchRule systemLunchRule; 040 Date date = new Date((new DateTime(2010, 1, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis()); 041 042 @Test 043 public void testSystemLunchRuleFetch() throws Exception{ 044 this.systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date); 045 Assert.assertTrue("System lunch rule is pulled back", this.systemLunchRule!=null); 046 } 047 048 /** 049 * Test if the lunch in/out button shows and if the time block is created with the correct clock action 050 */ 051 052 @Test 053 public void testSystemLunchRule() throws Exception { 054 055 systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date); 056 Assert.assertTrue("System lunch rule is pulled back", systemLunchRule!=null); 057 058 String baseUrl = TkTestConstants.Urls.CLOCK_URL; 059 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl, false); 060 Thread.sleep(3000); 061 // HtmlPage page = HtmlUnitUtil.gotoPageAnBatchJobEntryTestdLogin(TkTestConstants.Urls.CLOCK_URL); 062 Assert.assertNotNull(page); 063 064 Map<String, Object> criteria = new LinkedHashMap<String, Object>(); 065 criteria.put("selectedAssignment", new String[]{TkTestConstants.FormElementTypes.DROPDOWN, "2_1234_2"}); 066 067 HtmlUnitUtil.createTempFile(page); 068 // choose the first assignment from the drop down 069 page = TkTestUtils.fillOutForm(page, criteria); 070 071 Assert.assertNotNull(page); 072 //Thread.sleep(3000); 073 // clock in 074 page = TkTestUtils.clickClockInOrOutButton(page); 075 Thread.sleep(3000); 076 HtmlUnitUtil.createTempFile(page); 077 078 Assert.assertTrue("The take lunch button didn't appear", page.asXml().contains("lunchOut")); 079 Thread.sleep(3000); 080 // the lunch in button should display after clocking in 081 page = TkTestUtils.clickLunchInOrOutButton(page, "LO"); 082 //Thread.sleep(3000); 083 Assert.assertTrue("The return from lunch button didn't appear", page.asXml().contains("lunchIn")); 084 Thread.sleep(3000); 085 Assert.assertEquals(TkConstants.LUNCH_OUT, TkServiceLocator.getClockLogService().getLastClockLog(TKContext.getPrincipalId()).getClockAction()); 086 //Thread.sleep(3000); 087 // the lunch out button should display after lunching in 088 page = TkTestUtils.clickLunchInOrOutButton(page, "LI"); 089 Thread.sleep(3000); 090 Assert.assertEquals(TkConstants.LUNCH_IN, TkServiceLocator.getClockLogService().getLastClockLog(TKContext.getPrincipalId()).getClockAction()); 091 092 } 093 }