1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.systemlunch;
17
18 import java.util.LinkedHashMap;
19 import java.util.Map;
20
21 import org.joda.time.DateTime;
22 import org.junit.Assert;
23 import org.junit.Test;
24 import org.kuali.hr.KPMEWebTestCase;
25 import org.kuali.hr.util.HtmlUnitUtil;
26 import org.kuali.kpme.core.FunctionalTest;
27 import org.kuali.kpme.core.util.HrTestConstants;
28 import org.kuali.kpme.core.util.TKUtils;
29 import org.kuali.kpme.tklm.common.TkConstants;
30 import org.kuali.kpme.tklm.time.rules.lunch.sys.SystemLunchRule;
31 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
32 import org.kuali.kpme.tklm.utils.TkTestConstants;
33
34 import com.gargoylesoftware.htmlunit.ElementNotFoundException;
35 import com.gargoylesoftware.htmlunit.html.HtmlForm;
36 import com.gargoylesoftware.htmlunit.html.HtmlPage;
37 import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
38
39 @FunctionalTest
40 public class SystemLunchRuleTest extends KPMEWebTestCase {
41
42 SystemLunchRule systemLunchRule;
43 DateTime date = new DateTime(2010, 1, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone());
44
45 @Test
46 public void testSystemLunchRuleFetch() throws Exception{
47 this.systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date.toLocalDate());
48 Assert.assertTrue("System lunch rule is pulled back", this.systemLunchRule!=null);
49 }
50
51
52
53
54
55 @Test
56 public void testSystemLunchRule() throws Exception {
57
58 systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date.toLocalDate());
59 Assert.assertTrue("System lunch rule is pulled back", systemLunchRule!=null);
60
61 String baseUrl = TkTestConstants.Urls.CLOCK_URL;
62 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl, false);
63 Thread.sleep(3000);
64
65 Assert.assertNotNull(page);
66
67 Map<String, Object> criteria = new LinkedHashMap<String, Object>();
68 criteria.put("selectedAssignment", new String[]{HrTestConstants.FormElementTypes.DROPDOWN, "2_1234_2"});
69 HtmlUnitUtil.createTempFile(page);
70
71 page = HtmlUnitUtil.fillOutForm(page, criteria);
72 Assert.assertNotNull(page);
73
74
75 page = HtmlUnitUtil.clickClockInOrOutButton(page);
76 Thread.sleep(3000);
77 HtmlUnitUtil.createTempFile(page);
78 Assert.assertTrue("The take lunch button didn't appear", page.asXml().contains("lunchOut"));
79 Thread.sleep(3000);
80
81 page = HtmlUnitUtil.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("admin").getClockAction());
86
87 if(systemLunchRule.getShowLunchButton()) {
88
89 HtmlForm defaultForm = HtmlUnitUtil.getDefaultForm(page);
90 try {
91 @SuppressWarnings("unused")
92 HtmlSubmitInput input = defaultForm.getInputByName("clockAction");
93 } catch (Exception e) {
94 Assert.assertTrue("Clock Out button should not be present", e instanceof ElementNotFoundException);
95 }
96
97 }
98
99
100 page = HtmlUnitUtil.clickLunchInOrOutButton(page, "LI");
101 Thread.sleep(3000);
102 Assert.assertEquals(TkConstants.LUNCH_IN, TkServiceLocator.getClockLogService().getLastClockLog("admin").getClockAction());
103
104 }
105 }