View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.systemlunch.rule;
17  
18  import java.sql.Date;
19  import java.util.LinkedHashMap;
20  import java.util.Map;
21  
22  import org.joda.time.DateTime;
23  import org.joda.time.DateTimeZone;
24  import org.junit.Assert;
25  import org.junit.Test;
26  import org.kuali.hr.test.KPMETestCase;
27  import org.kuali.hr.time.service.base.TkServiceLocator;
28  import org.kuali.hr.time.syslunch.rule.SystemLunchRule;
29  import org.kuali.hr.time.test.HtmlUnitUtil;
30  import org.kuali.hr.time.test.TkTestConstants;
31  import org.kuali.hr.time.test.TkTestUtils;
32  import org.kuali.hr.time.util.TKContext;
33  import org.kuali.hr.time.util.TKUtils;
34  import org.kuali.hr.time.util.TkConstants;
35  
36  import com.gargoylesoftware.htmlunit.html.HtmlPage;
37  
38  public class SystemLunchRuleTest extends KPMETestCase {
39  	
40  	SystemLunchRule systemLunchRule;
41  	Date date = new Date((new DateTime(2010, 1, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
42  	
43  	@Test
44  	public void testSystemLunchRuleFetch() throws Exception{
45  		this.systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date);
46  		Assert.assertTrue("System lunch rule is pulled back", this.systemLunchRule!=null);
47  	}
48  	
49  	/**
50  	 * Test if the lunch in/out button shows and if the time block is created with the correct clock action
51  	 */
52  	
53  	@Test
54  	public void testSystemLunchRule() throws Exception {
55  		
56  		systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date);
57  		Assert.assertTrue("System lunch rule is pulled back", systemLunchRule!=null);
58  
59          String baseUrl = TkTestConstants.Urls.CLOCK_URL;
60      	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl, false);
61          Thread.sleep(3000);
62  //    	HtmlPage page = HtmlUnitUtil.gotoPageAnBatchJobEntryTestdLogin(TkTestConstants.Urls.CLOCK_URL);
63      	Assert.assertNotNull(page);
64      	
65      	Map<String, Object> criteria = new LinkedHashMap<String, Object>();
66      	criteria.put("selectedAssignment", new String[]{TkTestConstants.FormElementTypes.DROPDOWN, "2_1234_2"});
67      	HtmlUnitUtil.createTempFile(page);
68      	// choose the first assignment from the drop down
69      	page = TkTestUtils.fillOutForm(page, criteria);
70      	Assert.assertNotNull(page);
71          //Thread.sleep(3000);
72      	// clock in
73      	page = TkTestUtils.clickClockInOrOutButton(page);
74          Thread.sleep(3000);
75      	HtmlUnitUtil.createTempFile(page);
76      	Assert.assertTrue("The take lunch button didn't appear", page.asXml().contains("lunchOut"));
77          Thread.sleep(3000);
78      	// the lunch in button should display after clocking in
79      	page = TkTestUtils.clickLunchInOrOutButton(page, "LO");
80          //Thread.sleep(3000);
81      	Assert.assertTrue("The return from lunch button didn't appear", page.asXml().contains("lunchIn"));
82      	Thread.sleep(3000);
83      	Assert.assertEquals(TkConstants.LUNCH_OUT, TkServiceLocator.getClockLogService().getLastClockLog(TKContext.getPrincipalId()).getClockAction());
84          //Thread.sleep(3000);
85      	// the lunch out button should display after lunching in
86      	page = TkTestUtils.clickLunchInOrOutButton(page, "LI");
87      	Thread.sleep(3000);
88      	Assert.assertEquals(TkConstants.LUNCH_IN, TkServiceLocator.getClockLogService().getLastClockLog(TKContext.getPrincipalId()).getClockAction());
89      	
90  	}
91  }