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