001    /**
002     * Copyright 2004-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.hr.time.systemlunch.rule;
017    
018    import java.sql.Date;
019    import java.util.LinkedHashMap;
020    import java.util.Map;
021    
022    import org.joda.time.DateTime;
023    import org.joda.time.DateTimeZone;
024    import org.junit.Assert;
025    import org.junit.Test;
026    import org.kuali.hr.test.KPMETestCase;
027    import org.kuali.hr.time.service.base.TkServiceLocator;
028    import org.kuali.hr.time.syslunch.rule.SystemLunchRule;
029    import org.kuali.hr.time.test.HtmlUnitUtil;
030    import org.kuali.hr.time.test.TkTestConstants;
031    import org.kuali.hr.time.test.TkTestUtils;
032    import org.kuali.hr.time.util.TKContext;
033    import org.kuali.hr.time.util.TKUtils;
034    import org.kuali.hr.time.util.TkConstants;
035    
036    import com.gargoylesoftware.htmlunit.html.HtmlPage;
037    
038    public class SystemLunchRuleTest extends KPMETestCase {
039            
040            SystemLunchRule systemLunchRule;
041            Date date = new Date((new DateTime(2010, 1, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
042            
043            @Test
044            public void testSystemLunchRuleFetch() throws Exception{
045                    this.systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date);
046                    Assert.assertTrue("System lunch rule is pulled back", this.systemLunchRule!=null);
047            }
048            
049            /**
050             * Test if the lunch in/out button shows and if the time block is created with the correct clock action
051             */
052            
053            @Test
054            public void testSystemLunchRule() throws Exception {
055                    
056                    systemLunchRule = TkServiceLocator.getSystemLunchRuleService().getSystemLunchRule(date);
057                    Assert.assertTrue("System lunch rule is pulled back", systemLunchRule!=null);
058    
059            String baseUrl = TkTestConstants.Urls.CLOCK_URL;
060            HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl, false);
061            Thread.sleep(3000);
062    //      HtmlPage page = HtmlUnitUtil.gotoPageAnBatchJobEntryTestdLogin(TkTestConstants.Urls.CLOCK_URL);
063            Assert.assertNotNull(page);
064            
065            Map<String, Object> criteria = new LinkedHashMap<String, Object>();
066            criteria.put("selectedAssignment", new String[]{TkTestConstants.FormElementTypes.DROPDOWN, "2_1234_2"});
067            HtmlUnitUtil.createTempFile(page);
068            // choose the first assignment from the drop down
069            page = TkTestUtils.fillOutForm(page, criteria);
070            Assert.assertNotNull(page);
071            //Thread.sleep(3000);
072            // clock in
073            page = TkTestUtils.clickClockInOrOutButton(page);
074            Thread.sleep(3000);
075            HtmlUnitUtil.createTempFile(page);
076            Assert.assertTrue("The take lunch button didn't appear", page.asXml().contains("lunchOut"));
077            Thread.sleep(3000);
078            // the lunch in button should display after clocking in
079            page = TkTestUtils.clickLunchInOrOutButton(page, "LO");
080            //Thread.sleep(3000);
081            Assert.assertTrue("The return from lunch button didn't appear", page.asXml().contains("lunchIn"));
082            Thread.sleep(3000);
083            Assert.assertEquals(TkConstants.LUNCH_OUT, TkServiceLocator.getClockLogService().getLastClockLog(TKContext.getPrincipalId()).getClockAction());
084            //Thread.sleep(3000);
085            // the lunch out button should display after lunching in
086            page = TkTestUtils.clickLunchInOrOutButton(page, "LI");
087            Thread.sleep(3000);
088            Assert.assertEquals(TkConstants.LUNCH_IN, TkServiceLocator.getClockLogService().getLastClockLog(TKContext.getPrincipalId()).getClockAction());
089            
090            }
091    }