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.lm.leaveadjustment;
017    
018    import junit.framework.Assert;
019    
020    import org.apache.log4j.Logger;
021    import org.junit.Test;
022    import org.kuali.hr.test.KPMETestCase;
023    import org.kuali.hr.time.test.HtmlUnitUtil;
024    import org.kuali.hr.time.test.TkTestConstants;
025    
026    import com.gargoylesoftware.htmlunit.html.HtmlElement;
027    import com.gargoylesoftware.htmlunit.html.HtmlForm;
028    import com.gargoylesoftware.htmlunit.html.HtmlInput;
029    import com.gargoylesoftware.htmlunit.html.HtmlPage;
030    
031    public class LeaveAdjustmentMaintTest extends KPMETestCase{
032        private static final Logger LOG = Logger.getLogger(LeaveAdjustmentMaintTest.class);
033            private static final String PRINCIPAL_ID = "admin";
034            
035            private static final String EFFECTIVE_DATE_REQUIRED = "Effective Date (Effective Date) is a required field.";
036            private static final String PRINCIPAL_ID_REQUIRED = "Principal Id (Principal Id) is a required field.";
037            private static final String LEAVE_PLAN_REQUIRED = "Leave Plan (Leave Plan) is a required field.";
038            private static final String EARN_CODE_REQUIRED = "Earn Code (Earn Code) is a required field.";
039            private static final String ACCRUAL_CATEGORY_REQUIRED = "Accrual Category (Accrual Category) is a required field.";
040            private static final String DES_REQUIRED = "Description (Description) is a required field.";
041            private static final String ADJUSTMENT_AMOUNT_REQUIRED = "Adjustment Amount (Adjustment Amount) is a required field.";
042            
043            @Test
044            public void testRequiredFields() throws Exception {
045                    String baseUrl = TkTestConstants.Urls.LEAVE_ADJUSTMENT_MAINT_NEW_URL;
046                    HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
047                    Assert.assertNotNull(page);
048             
049                    HtmlForm form = page.getFormByName("KualiForm");
050                    Assert.assertNotNull("Search form was missing from page.", form);
051                    
052                    HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
053                    Assert.assertNotNull("Could not locate submit button", input);
054                    
055                    HtmlElement element = page.getElementByName("methodToCall.route");
056                    page = element.click();
057                    Assert.assertTrue("page text does not contain:\n" + EFFECTIVE_DATE_REQUIRED, page.asText().contains(EFFECTIVE_DATE_REQUIRED));
058                    Assert.assertTrue("page text does not contain:\n" + PRINCIPAL_ID_REQUIRED, page.asText().contains(PRINCIPAL_ID_REQUIRED));
059                    Assert.assertTrue("page text does not contain:\n" + LEAVE_PLAN_REQUIRED, page.asText().contains(LEAVE_PLAN_REQUIRED));
060                    Assert.assertTrue("page text does not contain:\n" + ACCRUAL_CATEGORY_REQUIRED, page.asText().contains(ACCRUAL_CATEGORY_REQUIRED));
061                    Assert.assertTrue("page text does not contain:\n" + EARN_CODE_REQUIRED, page.asText().contains(EARN_CODE_REQUIRED));
062                    Assert.assertTrue("page text does not contain:\n" + DES_REQUIRED, page.asText().contains(DES_REQUIRED));
063                setFieldValue(page, "document.newMaintainableObject.adjustmentAmount", "");
064                element = page.getElementByName("methodToCall.route");
065                    page = element.click();
066                    Assert.assertTrue("page text does not contain:\n" + ADJUSTMENT_AMOUNT_REQUIRED, page.asText().contains(ADJUSTMENT_AMOUNT_REQUIRED));
067            }
068            
069            @Test
070            public void testLookupPage() throws Exception {  
071                    HtmlPage leaveAdjustmentLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_ADJUSTMENT_MAINT_URL);
072                    leaveAdjustmentLookup = HtmlUnitUtil.clickInputContainingText(leaveAdjustmentLookup, "search");
073                    LOG.debug(leaveAdjustmentLookup.asXml());
074                    Assert.assertTrue("Page contains test LeaveAdjustment", leaveAdjustmentLookup.asText().contains("AC1"));
075                    Assert.assertFalse("Page should not contain edit action", leaveAdjustmentLookup.asText().contains("edit")); 
076            }
077            
078            @Test
079            public void testAddNew() throws Exception {
080                    String baseUrl = TkTestConstants.Urls.LEAVE_ADJUSTMENT_MAINT_NEW_URL;
081                    HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
082                    Assert.assertNotNull(page);
083             
084                    HtmlForm form = page.getFormByName("KualiForm");
085                    Assert.assertNotNull("Search form was missing from page.", form);
086                    
087                    setFieldValue(page, "document.documentHeader.documentDescription", "Leave Adjustment - test");
088                setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
089                setFieldValue(page, "document.newMaintainableObject.principalId", "admin");
090                setFieldValue(page, "document.newMaintainableObject.accrualCategory", "myAC");      //nonexist accrual catetory
091                setFieldValue(page, "document.newMaintainableObject.earnCode", "myLC");     //nonexist leave Code
092                    
093                    HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
094                    Assert.assertNotNull("Could not locate submit button", input);
095                    HtmlElement element = page.getElementByName("methodToCall.route");
096                    page = element.click();
097                    HtmlUnitUtil.createTempFile(page);
098                    Assert.assertTrue("page text contains:\n" + "'myAC' does not exist", page.asText().contains("'myAC' does not exist"));
099                            
100                    setFieldValue(page, "document.newMaintainableObject.accrualCategory", "AC1"); // existing accrual category
101                    setFieldValue(page, "document.newMaintainableObject.earnCode", "testLC");
102                    element = page.getElementByName("methodToCall.route");
103                    page = element.click();
104                    Assert.assertFalse("page text contains:\n" + "'AC1' does not exist", page.asText().contains("'AC1' does not exist"));
105                    
106                    setFieldValue(page, "document.newMaintainableObject.principalId", "admin"); // existing principal hr attributes
107                    element = page.getElementByName("methodToCall.route");
108                    page = element.click();
109                    Assert.assertFalse("page text contains:\n" + "'IU-SM' does not exist", page.asText().contains("'IU-SM' does not exist"));
110                    
111                    setFieldValue(page, "document.newMaintainableObject.earnCode", "EC");   //fraction allowed is 99.9
112                    setFieldValue(page, "document.newMaintainableObject.adjustmentAmount", "2.45");
113                    element = page.getElementByName("methodToCall.route");
114                    page = element.click();
115                    Assert.assertTrue("page text does not contain amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 1 decimal point."));
116            }
117    }