001/**
002 * Copyright 2004-2015 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 */
016package org.kuali.hr.time.shiftdiff;
017
018import java.math.BigDecimal;
019
020import org.joda.time.LocalDate;
021import org.junit.Assert;
022import org.junit.Test;
023import org.kuali.hr.KPMEWebTestCase;
024import org.kuali.hr.util.HtmlUnitUtil;
025import org.kuali.kpme.core.FunctionalTest;
026import org.kuali.kpme.tklm.time.rules.shiftdifferential.ShiftDifferentialRule;
027import org.kuali.kpme.tklm.utils.TkTestConstants;
028import org.kuali.rice.krad.service.KRADServiceLocator;
029
030import com.gargoylesoftware.htmlunit.html.HtmlElement;
031import com.gargoylesoftware.htmlunit.html.HtmlForm;
032import com.gargoylesoftware.htmlunit.html.HtmlInput;
033import com.gargoylesoftware.htmlunit.html.HtmlPage;
034
035@FunctionalTest
036public class ShiftDifferentialRuleMaintTest extends KPMEWebTestCase{
037        private static final String TEST_CODE="_T";
038                
039        private static final BigDecimal TEST_NO=new BigDecimal(2);
040        private static String shiftDifferentialRuleId;
041
042        
043        
044        @Test
045        public void testShiftDifferentialRuleMaint() throws Exception {  
046                HtmlPage shiftDifferentialRuleLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.SHIFT_DIFFERENTIAL_RULE_MAINT_URL);
047                shiftDifferentialRuleLookup = HtmlUnitUtil.clickInputContainingText(shiftDifferentialRuleLookup, "search");
048                Assert.assertTrue("Page contains test Shift Differential Rule", shiftDifferentialRuleLookup.asText().contains(TEST_CODE.toString()));
049                HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(shiftDifferentialRuleLookup, "edit",shiftDifferentialRuleId.toString());
050                Assert.assertTrue("Maintenance Page contains test ShiftDifferentialRule",maintPage.asText().contains(TEST_CODE));        
051        }
052        
053        @Test
054        public void testRequiredFields() throws Exception {
055                String baseUrl = TkTestConstants.Urls.SHIFT_DIFFERENTIAL_RULE_MAINT_NEW_URL;
056                HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
057                Assert.assertNotNull(page);
058         
059                HtmlForm form = page.getFormByName("KualiForm");
060                Assert.assertNotNull("Search form was missing from page.", form);
061                
062                HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
063                Assert.assertNotNull("Could not locate submit button", input);
064                
065                HtmlElement element = page.getElementByName("methodToCall.route");
066                page = element.click();
067                // the following fields should have default values
068                String errorMessage = "Min. Hours (Min. Hours) is a required field.";
069                Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
070            errorMessage = "Begin Time (00:00 AM) (Begin Time) is a required field.";
071            Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
072            errorMessage = "End Time (00:00 AM) (End Time) is a required field.";
073            Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
074            errorMessage = "Max. Gap Minutes (Max. Gap Minutes) is a required field.";
075            Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
076                
077            //remove the default values
078                HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.minHours", "");
079                HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.beginTime", "");
080                HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.endTime", "");
081                HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.maxGap", "");
082                element = page.getElementByName("methodToCall.route");
083                HtmlPage nextPage = element.click();
084                errorMessage = "Effective Date (Effective Date) is a required field.";
085                Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
086            errorMessage = "Location (Location) is a required field.";
087            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
088            errorMessage = "Salary Group (Salary Group) is a required field.";
089            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
090            errorMessage = "Pay Grade (Pay Grade) is a required field.";
091            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
092            errorMessage = "Earn Code (Earn Code) is a required field.";
093            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
094            errorMessage = "From Earn Group (From Earn Group) is a required field.";
095            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
096            errorMessage = "Begin Time (00:00 AM) (Begin Time) is a required field.";
097            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
098            errorMessage = "End Time (00:00 AM) (End Time) is a required field.";
099            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
100            errorMessage = "Max. Gap Minutes (Max. Gap Minutes) is a required field.";
101            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
102            errorMessage = "Pay Calendar Group (Pay Calendar Group) is a required field.";
103            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
104            errorMessage = "Min. Hours (Min. Hours) is a required field.";
105            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
106            errorMessage = "At least one day must be checked."; // KPME-2635
107            Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
108        }
109
110
111        @Override
112        public void setUp() throws Exception {
113                super.setUp();
114
115                ShiftDifferentialRule shiftDifferentialRule = new ShiftDifferentialRule();
116                shiftDifferentialRule.setActive(true);
117                //shiftDifferentialRule.setBeginTime(TEST_TIME);
118                shiftDifferentialRule.setEarnCode(TEST_CODE);
119                shiftDifferentialRule.setEffectiveLocalDate(LocalDate.now().minusDays(1));
120                //shiftDifferentialRule.setEndTime(TEST_TIME);
121                shiftDifferentialRule.setLocation(TEST_CODE);
122                shiftDifferentialRule.setMaxGap(new BigDecimal(2));
123                shiftDifferentialRule.setMinHours(TEST_NO);
124                shiftDifferentialRule.setPayGrade(TEST_CODE);   
125                shiftDifferentialRule.setPyCalendarGroup("BW-CAL");
126                shiftDifferentialRule.setSunday(true);  
127                shiftDifferentialRule.setMonday(true);
128                shiftDifferentialRule.setTuesday(true);
129                shiftDifferentialRule.setWednesday(true);
130                shiftDifferentialRule.setThursday(true);
131                shiftDifferentialRule.setFriday(true);
132                shiftDifferentialRule.setSaturday(true);
133                shiftDifferentialRule.setPyCalendarGroup("TEST");
134        shiftDifferentialRule.setUserPrincipalId("admin");
135                
136                ShiftDifferentialRule rule = KRADServiceLocator.getBusinessObjectService().save(shiftDifferentialRule);
137                shiftDifferentialRuleId = rule.getTkShiftDiffRuleId();
138        }
139
140        @Override
141        public void tearDown() throws Exception {                               
142                ShiftDifferentialRule shiftDifferentialRuleObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(ShiftDifferentialRule.class, shiftDifferentialRuleId);             
143                KRADServiceLocator.getBusinessObjectService().delete(shiftDifferentialRuleObj);
144                super.tearDown();
145        }
146}
147