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