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 com.gargoylesoftware.htmlunit.html.HtmlPage;
19  import org.joda.time.DateTime;
20  import org.joda.time.DateTimeZone;
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.kuali.hr.test.KPMETestCase;
24  import org.kuali.hr.time.service.base.TkServiceLocator;
25  import org.kuali.hr.time.syslunch.rule.SystemLunchRule;
26  import org.kuali.hr.time.test.HtmlUnitUtil;
27  import org.kuali.hr.time.test.TkTestConstants;
28  import org.kuali.hr.time.test.TkTestUtils;
29  import org.kuali.hr.time.util.TKContext;
30  import org.kuali.hr.time.util.TKUtils;
31  import org.kuali.hr.time.util.TkConstants;
32  
33  import java.sql.Date;
34  import java.util.LinkedHashMap;
35  import java.util.Map;
36  
37  public class SystemLunchRuleTest extends KPMETestCase {
38  
39  	SystemLunchRule systemLunchRule;
40  	Date date = new Date((new DateTime(2010, 1, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
41  
42  	@Test
43  	public void testSystemLunchRuleFetch() throws Exception{
44  		this.systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date);
45  		Assert.assertTrue("System lunch rule is pulled back", this.systemLunchRule!=null);
46  	}
47  
48  	/**
49  	 * Test if the lunch in/out button shows and if the time block is created with the correct clock action
50  	 */
51  
52  	@Test
53  	public void testSystemLunchRule() throws Exception {
54  
55  		systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date);
56  		Assert.assertTrue("System lunch rule is pulled back", systemLunchRule!=null);
57  
58          String baseUrl = TkTestConstants.Urls.CLOCK_URL;
59      	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl, false);
60          Thread.sleep(3000);
61  //    	HtmlPage page = HtmlUnitUtil.gotoPageAnBatchJobEntryTestdLogin(TkTestConstants.Urls.CLOCK_URL);
62      	Assert.assertNotNull(page);
63  
64      	Map<String, Object> criteria = new LinkedHashMap<String, Object>();
65      	criteria.put("selectedAssignment", new String[]{TkTestConstants.FormElementTypes.DROPDOWN, "2_1234_2"});
66  
67      	HtmlUnitUtil.createTempFile(page);
68      	// choose the first assignment from the drop down
69      	page = TkTestUtils.fillOutForm(page, criteria);
70  
71      	Assert.assertNotNull(page);
72          //Thread.sleep(3000);
73      	// clock in
74      	page = TkTestUtils.clickClockInOrOutButton(page);
75          Thread.sleep(3000);
76      	HtmlUnitUtil.createTempFile(page);
77  
78      	Assert.assertTrue("The take lunch button didn't appear", page.asXml().contains("lunchOut"));
79          Thread.sleep(3000);
80      	// the lunch in button should display after clocking in
81      	page = TkTestUtils.clickLunchInOrOutButton(page, "LO");
82          //Thread.sleep(3000);
83      	Assert.assertTrue("The return from lunch button didn't appear", page.asXml().contains("lunchIn"));
84      	Thread.sleep(3000);
85      	Assert.assertEquals(TkConstants.LUNCH_OUT, TkServiceLocator.getClockLogService().getLastClockLog(TKContext.getPrincipalId()).getClockAction());
86          //Thread.sleep(3000);
87      	// the lunch out button should display after lunching in
88      	page = TkTestUtils.clickLunchInOrOutButton(page, "LI");
89      	Thread.sleep(3000);
90      	Assert.assertEquals(TkConstants.LUNCH_IN, TkServiceLocator.getClockLogService().getLastClockLog(TKContext.getPrincipalId()).getClockAction());
91  
92  	}
93  }