1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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(getWebClient(), baseUrl, false);
61 Thread.sleep(3000);
62
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
69 page = TkTestUtils.fillOutForm(page, criteria);
70 Assert.assertNotNull(page);
71
72
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
79 page = TkTestUtils.clickLunchInOrOutButton(page, "LO");
80
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
85
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 }