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