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