1 /**
2 * Copyright 2004-2014 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;
17
18 import org.joda.time.DateTime;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.kuali.hr.KPMEWebTestCase;
22 import org.kuali.kpme.core.FunctionalTest;
23 import org.kuali.kpme.core.util.TKUtils;
24 import org.kuali.kpme.tklm.time.rules.lunch.sys.SystemLunchRule;
25 import org.kuali.kpme.tklm.time.service.TkServiceLocator;
26
27 @FunctionalTest
28 public class SystemLunchRuleTest extends KPMEWebTestCase {
29
30 SystemLunchRule systemLunchRule;
31 DateTime date = new DateTime(2010, 1, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone());
32
33 @Test
34 public void testSystemLunchRuleFetch() throws Exception{
35 this.systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date.toLocalDate());
36 Assert.assertTrue("System lunch rule is pulled back", this.systemLunchRule!=null);
37 }
38
39 /**
40 * Test if the lunch in/out button shows and if the time block is created with the correct clock action
41 */
42 // KPME-3532 system lunch is always off now, so there is no need for this test
43 /*
44 @Test
45 public void testSystemLunchRule() throws Exception {
46
47 systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date.toLocalDate());
48 Assert.assertTrue("System lunch rule is pulled back", systemLunchRule!=null);
49
50 String baseUrl = TkTestConstants.Urls.CLOCK_URL;
51 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl, false);
52 Thread.sleep(3000);
53 // HtmlPage page = HtmlUnitUtil.gotoPageAnBatchJobEntryTestdLogin(TkTestConstants.Urls.CLOCK_URL);
54 Assert.assertNotNull(page);
55
56 Map<String, Object> criteria = new LinkedHashMap<String, Object>();
57 criteria.put("selectedAssignment", new String[]{HrTestConstants.FormElementTypes.DROPDOWN, "IU-BL_2_1234_2"});
58 HtmlUnitUtil.createTempFile(page);
59 // choose the first assignment from the drop down
60 page = HtmlUnitUtil.fillOutForm(page, criteria);
61 Assert.assertNotNull(page);
62 //Thread.sleep(3000);
63 // clock in
64 page = HtmlUnitUtil.clickClockInOrOutButton(page);
65 Thread.sleep(3000);
66 HtmlUnitUtil.createTempFile(page);
67 Assert.assertTrue("The take lunch button didn't appear", page.asXml().contains("lunchOut"));
68 Thread.sleep(3000);
69 // the lunch in button should display after clocking in
70 page = HtmlUnitUtil.clickLunchInOrOutButton(page, "LO");
71 //Thread.sleep(3000);
72 Assert.assertTrue("The return from lunch button didn't appear", page.asXml().contains("lunchIn"));
73 Thread.sleep(3000);
74 Assert.assertEquals(TkConstants.LUNCH_OUT, TkServiceLocator.getClockLogService().getLastClockLog("admin").getClockAction());
75
76 if(systemLunchRule.getShowLunchButton()) {
77 //should be in its own test case, but do not want to expect the exception for purposes of another operation encountering it.
78 HtmlForm defaultForm = HtmlUnitUtil.getDefaultForm(page);
79 try {
80 @SuppressWarnings("unused")
81 HtmlSubmitInput input = defaultForm.getInputByName("clockAction");
82 } catch (Exception e) {
83 Assert.assertTrue("Clock Out button should not be present", e instanceof ElementNotFoundException);
84 }
85
86 }
87 //Thread.sleep(3000);
88 // the lunch out button should display after lunching in
89 page = HtmlUnitUtil.clickLunchInOrOutButton(page, "LI");
90 Thread.sleep(3000);
91 Assert.assertEquals(TkConstants.LUNCH_IN, TkServiceLocator.getClockLogService().getLastClockLog("admin").getClockAction());
92
93 } */
94 }