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.pm.positionreportsubcat; 017 018import junit.framework.Assert; 019 020import org.junit.Test; 021import org.kuali.hr.KPMEWebTestCase; 022import org.kuali.hr.util.HtmlUnitUtil; 023import org.kuali.kpme.core.FunctionalTest; 024import org.kuali.kpme.pm.api.positionreportsubcat.PositionReportSubCategoryContract; 025import org.kuali.kpme.pm.positionreportsubcat.PositionReportSubCategoryBo; 026import org.kuali.kpme.pm.service.base.PmServiceLocator; 027import org.kuali.kpme.pm.utils.PmTestConstants; 028 029import com.gargoylesoftware.htmlunit.html.HtmlElement; 030import com.gargoylesoftware.htmlunit.html.HtmlForm; 031import com.gargoylesoftware.htmlunit.html.HtmlInput; 032import com.gargoylesoftware.htmlunit.html.HtmlPage; 033 034@FunctionalTest 035public class PositionReportSubCatMaintTest extends KPMEWebTestCase { 036 037 @Test 038 public void testRequiredFields() throws Exception { 039 //KPME-3086: converted Position Report Sub Category to KRAD which broke these tests, 040 //need TODO: rewrite this code once KRAD web tests are developed 041 /* 042 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_SUB_CAT_MAINT_NEW_URL; 043 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 044 Assert.assertNotNull(page); 045 046 HtmlForm form = page.getFormByName("KualiForm"); 047 Assert.assertNotNull("Search form was missing from page.", form); 048 049 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 050 Assert.assertNotNull("Could not locate submit button", input); 051 052 HtmlElement element = page.getElementByName("methodToCall.route"); 053 page = element.click(); 054 Assert.assertTrue("page text does not contain:\n" + "Effective Date (Effective Date) is a required field.", 055 page.asText().contains("Effective Date (Effective Date) is a required field.")); 056 Assert.assertTrue("page text does not contain:\n" + "Position Report Sub Category (Position Report Sub Category) is a required field.", 057 page.asText().contains("Position Report Sub Category (Position Report Sub Category) is a required field.")); 058 Assert.assertTrue("page text does not contain:\n" + "Position Report Category (Position Report Category) is a required field.", 059 page.asText().contains("Position Report Category (Position Report Category) is a required field.")); 060 Assert.assertTrue("page text does not contain:\n" + "Position Report Type (Position Report Type) is a required field.", 061 page.asText().contains("Position Report Type (Position Report Type) is a required field.")); 062 Assert.assertTrue("page text does not contain:\n" + "Institution (Institution) is a required field.", 063 page.asText().contains("Institution (Institution) is a required field.")); 064 Assert.assertTrue("page text does not contain:\n" + "Location (Location) is a required field.", 065 page.asText().contains("Location (Location) is a required field.")); 066 } 067 068 @Test 069 public void testAddNew() throws Exception { 070 String prscString = "testPRSC"; 071 PositionReportSubCategoryContract prsc = PmServiceLocator.getPositionReportSubCatService().getPositionReportSubCatById("1000"); 072 Assert.assertTrue("There should NOT be Position Report Sub Category with name " + prscString, prsc == null); 073 074 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_SUB_CAT_MAINT_NEW_URL; 075 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 076 Assert.assertNotNull(page); 077 078 HtmlForm form = page.getFormByName("KualiForm"); 079 Assert.assertNotNull("Search form was missing from page.", form); 080 081 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Position Report Category - test"); 082 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012"); 083 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportSubCat", prscString); 084// HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportCat", "nonCat"); // non-existing PositionReportCategory 085// HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportType.div", "testPRT"); 086 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "nonExistInst"); //nonexisting institution 087 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "nonCam"); //nonexisting location 088 089 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 090 Assert.assertNotNull("Could not locate submit button", input); 091 HtmlElement element = page.getElementByName("methodToCall.route"); 092 page = element.click(); 093 HtmlUnitUtil.createTempFile(page); 094 Assert.assertTrue("page text contains:\n" + "The specified Instituion 'nonExistInst' does not exist.", 095 page.asText().contains("The specified Instituion 'nonExistInst' does not exist.")); 096 Assert.assertTrue("page text contains:\n" + "The specified Location 'nonCam' does not exist.", 097 page.asText().contains("The specified Location 'nonCam' does not exist.")); 098 099 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "testInst"); // matching institution 100 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "BL"); // matching Location 101 element = page.getElementByName("methodToCall.route"); 102 page = element.click(); 103 Assert.assertFalse("page text should NOT contain:\n" + "The specified Instituion 'nonExistInst' does not exist.", 104 page.asText().contains("The specified Instituion 'nonExistInst' does not exist.")); 105 Assert.assertFalse("page text should NOT contain:\n" + "The specified Location 'nonCam' does not exist.", 106 page.asText().contains("The specified Location 'nonCam' does not exist.")); 107 */ 108 } 109 110}