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.time.calendar; 017 018 019 import org.junit.Assert; 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 CalendarMaintTest extends KPMETestCase { 031 032 public static final String TEST_USER = "admin"; 033 private static final String CAL_NAME_REQUIRED = "Calendar Name (Calendar Name) is a required field."; 034 private static final String CAL_DESP_REQUIRED = "Calendar Descriptions (Calendar Descriptions) is a required field."; 035 private static final String FLSA_DAY_REQUIRED = "Flsa Begin Day (Flsa Begin Day) is a required field."; 036 private static final String FLSA_TIME_REQUIRED = "Flsa Begin Time (00:00 AM) (Flsa Begin Time) is a required field."; 037 038 @Test 039 public void testDisplayCalendarTypeRadioOptions() throws Exception { 040 041 //verify the lookup page doesn't contain the both radio button 042 HtmlPage calendarPage = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.CALENDAR_MAINT_URL); 043 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(calendarPage, "search"); 044 HtmlUnitUtil.createTempFile(resultPage); 045 Assert.assertFalse("Lookup page contains:\n" + "The both radio button is not present", resultPage.asText().contains("Both")); 046 047 //verify the lookup page doesn't contain the both radio button 048 HtmlPage calendarMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit"); //click on the first result 049 HtmlUnitUtil.createTempFile(calendarMaintPage); 050 Assert.assertFalse("Maintenance page contains:\n" + "The both radio button is not present", calendarMaintPage.asText().contains("Both")); 051 052 } 053 054 @Test 055 public void testRequiredFields() throws Exception { 056 String baseUrl = TkTestConstants.Urls.CALENDAR_MAINT_NEW_URL; 057 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(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 Assert.assertFalse("page text contains: Incident Report", page.asText().contains("Incident Report")); 069 Assert.assertTrue("page text does not contain:\n" + CAL_NAME_REQUIRED, page.asText().contains(CAL_NAME_REQUIRED)); 070 Assert.assertTrue("page text does not contain:\n" + CAL_DESP_REQUIRED, page.asText().contains(CAL_DESP_REQUIRED)); 071 072 setFieldValue(page, "document.newMaintainableObject.calendarName", "testCal"); 073 setFieldValue(page, "document.newMaintainableObject.calendarDescriptions", "testDes"); 074 // when calendar type is Pay, flsa day and time are required 075 page = page.getElementByName("methodToCall.route").click(); 076 Assert.assertTrue("page text does not contain:\n" + FLSA_DAY_REQUIRED, page.asText().contains(FLSA_DAY_REQUIRED)); 077 Assert.assertTrue("page text does not contain:\n" + FLSA_TIME_REQUIRED, page.asText().contains(FLSA_TIME_REQUIRED)); 078 } 079 }