1 /** 2 * Copyright 2004-2015 The Kuali Foundation 3 * 4 * Licensed under the Educational Community License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.opensource.org/licenses/ecl2.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.kuali.hr.pm.positionreportgroup; 17 18 import java.util.List; 19 20 import junit.framework.Assert; 21 22 import org.apache.commons.collections.CollectionUtils; 23 import org.joda.time.DateTime; 24 import org.junit.Test; 25 import org.kuali.hr.KPMEWebTestCase; 26 import org.kuali.hr.util.HtmlUnitUtil; 27 import org.kuali.kpme.core.FunctionalTest; 28 import org.kuali.kpme.core.util.TKUtils; 29 import org.kuali.kpme.pm.api.positionreportgroup.PositionReportGroupContract; 30 import org.kuali.kpme.pm.positionreportgroup.PositionReportGroupBo; 31 import org.kuali.kpme.pm.service.base.PmServiceLocator; 32 import org.kuali.kpme.pm.utils.PmTestConstants; 33 34 import com.gargoylesoftware.htmlunit.html.HtmlElement; 35 import com.gargoylesoftware.htmlunit.html.HtmlForm; 36 import com.gargoylesoftware.htmlunit.html.HtmlInput; 37 import com.gargoylesoftware.htmlunit.html.HtmlPage; 38 39 @FunctionalTest 40 public class PositionReportGroupMaintTest extends KPMEWebTestCase { 41 42 @Test 43 public void testRequiredFields() throws Exception { 44 /* String baseUrl = PmTestConstants.Urls.POSITION_REPORT_GROUP_MAINT_NEW_URL; 45 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 46 Assert.assertNotNull(page); 47 48 HtmlForm form = page.getFormByName("KualiForm"); 49 Assert.assertNotNull("Search form was missing from page.", form); 50 51 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 52 Assert.assertNotNull("Could not locate submit button", input); 53 54 HtmlElement element = page.getElementByName("methodToCall.route"); 55 page = element.click(); 56 Assert.assertTrue("page text does not contain:\n" + "Effective Date (Effective Date) is a required field.", 57 page.asText().contains("Effective Date (Effective Date) is a required field.")); 58 Assert.assertTrue("page text does not contain:\n" + "Position Report Group (Position Report Group) is a required field.", 59 page.asText().contains("Position Report Group (Position Report Group) is a required field.")); 60 Assert.assertTrue("page text does not contain:\n" + "Institution (Institution) is a required field.", 61 page.asText().contains("Institution (Institution) is a required field.")); 62 Assert.assertTrue("page text does not contain:\n" + "Location (Location) is a required field.", 63 page.asText().contains("Location (Location) is a required field.")); 64 } 65 66 @Test 67 public void testAddNew() throws Exception { 68 DateTime effectiveDate = new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone()); 69 String prgString = "testPRG"; 70 List<? extends PositionReportGroupContract> prgList = PmServiceLocator.getPositionReportGroupService().getPositionReportGroupList(prgString, "testInst", "TS", effectiveDate.toLocalDate()); 71 Assert.assertTrue("There should NOT be Position Report Group with name " + prgString, CollectionUtils.isEmpty(prgList)); 72 73 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_GROUP_MAINT_NEW_URL; 74 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 75 Assert.assertNotNull(page); 76 77 HtmlForm form = page.getFormByName("KualiForm"); 78 Assert.assertNotNull("Search form was missing from page.", form); 79 80 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Position Report Group - test"); 81 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012"); 82 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportGroup", prgString); 83 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "nonExistInst"); //nonexisting institution 84 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "nonCam"); //nonexisting location 85 86 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 87 Assert.assertNotNull("Could not locate submit button", input); 88 HtmlElement element = page.getElementByName("methodToCall.route"); 89 page = element.click(); 90 HtmlUnitUtil.createTempFile(page); 91 Assert.assertTrue("page text contains:\n" + "The specified Instituion 'nonExistInst' does not exist.", 92 page.asText().contains("The specified Instituion 'nonExistInst' does not exist.")); 93 Assert.assertTrue("page text contains:\n" + "The specified Location 'nonCam' does not exist.", 94 page.asText().contains("The specified Location 'nonCam' does not exist.")); 95 96 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "testInst"); // existing institution 97 element = page.getElementByName("methodToCall.route"); 98 page = element.click(); 99 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 }