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 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
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
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
69 page = TkTestUtils.fillOutForm(page, criteria);
70
71 Assert.assertNotNull(page);
72
73
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
81 page = TkTestUtils.clickLunchInOrOutButton(page, "LO");
82
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
87
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 }