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