001/** 002 * Copyright 2004-2015 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.positionreportgroup; 017 018import java.util.List; 019 020import junit.framework.Assert; 021 022import org.apache.commons.collections.CollectionUtils; 023import org.joda.time.DateTime; 024import org.junit.Test; 025import org.kuali.hr.KPMEWebTestCase; 026import org.kuali.hr.util.HtmlUnitUtil; 027import org.kuali.kpme.core.FunctionalTest; 028import org.kuali.kpme.core.util.TKUtils; 029import org.kuali.kpme.pm.api.positionreportgroup.PositionReportGroupContract; 030import org.kuali.kpme.pm.positionreportgroup.PositionReportGroupBo; 031import org.kuali.kpme.pm.service.base.PmServiceLocator; 032import org.kuali.kpme.pm.utils.PmTestConstants; 033 034import com.gargoylesoftware.htmlunit.html.HtmlElement; 035import com.gargoylesoftware.htmlunit.html.HtmlForm; 036import com.gargoylesoftware.htmlunit.html.HtmlInput; 037import com.gargoylesoftware.htmlunit.html.HtmlPage; 038 039@FunctionalTest 040public class PositionReportGroupMaintTest extends KPMEWebTestCase { 041 042 @Test 043 public void testRequiredFields() throws Exception { 044/* String baseUrl = PmTestConstants.Urls.POSITION_REPORT_GROUP_MAINT_NEW_URL; 045 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), 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 (Effective Date) is a required field.", 057 page.asText().contains("Effective Date (Effective Date) is a required field.")); 058 Assert.assertTrue("page text does not contain:\n" + "Position Report Group (Position Report Group) is a required field.", 059 page.asText().contains("Position Report Group (Position Report Group) is a required field.")); 060 Assert.assertTrue("page text does not contain:\n" + "Institution (Institution) is a required field.", 061 page.asText().contains("Institution (Institution) is a required field.")); 062 Assert.assertTrue("page text does not contain:\n" + "Location (Location) is a required field.", 063 page.asText().contains("Location (Location) is a required field.")); 064 } 065 066 @Test 067 public void testAddNew() throws Exception { 068 DateTime effectiveDate = new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone()); 069 String prgString = "testPRG"; 070 List<? extends PositionReportGroupContract> prgList = PmServiceLocator.getPositionReportGroupService().getPositionReportGroupList(prgString, "testInst", "TS", effectiveDate.toLocalDate()); 071 Assert.assertTrue("There should NOT be Position Report Group with name " + prgString, CollectionUtils.isEmpty(prgList)); 072 073 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_GROUP_MAINT_NEW_URL; 074 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 075 Assert.assertNotNull(page); 076 077 HtmlForm form = page.getFormByName("KualiForm"); 078 Assert.assertNotNull("Search form was missing from page.", form); 079 080 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Position Report Group - test"); 081 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012"); 082 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportGroup", prgString); 083 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "nonExistInst"); //nonexisting institution 084 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "nonCam"); //nonexisting location 085 086 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 087 Assert.assertNotNull("Could not locate submit button", input); 088 HtmlElement element = page.getElementByName("methodToCall.route"); 089 page = element.click(); 090 HtmlUnitUtil.createTempFile(page); 091 Assert.assertTrue("page text contains:\n" + "The specified Instituion 'nonExistInst' does not exist.", 092 page.asText().contains("The specified Instituion 'nonExistInst' does not exist.")); 093 Assert.assertTrue("page text contains:\n" + "The specified Location 'nonCam' does not exist.", 094 page.asText().contains("The specified Location 'nonCam' does not exist.")); 095 096 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "testInst"); // existing institution 097 element = page.getElementByName("methodToCall.route"); 098 page = element.click(); 099 Assert.assertFalse("page text contains:\n" + "The specified Instituion 'testInst' does not exist.", 100 page.asText().contains("The specified Instituion 'testInst' does not exist.")); 101 102 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "BL"); // existing location 103 element = page.getElementByName("methodToCall.route"); 104 page = element.click(); 105 Assert.assertFalse("page text contains error", page.asText().contains("error")); 106 107 prgList = PmServiceLocator.getPositionReportGroupService().getPositionReportGroupList(prgString, "testInst", "BL", effectiveDate.toLocalDate()); 108 Assert.assertTrue("There should be Position Report Group with name " + prgString, CollectionUtils.isNotEmpty(prgList)); 109 */ 110 } 111}