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.pm.positionreportcat;
017
018 import java.util.List;
019
020 import junit.framework.Assert;
021
022 import org.apache.commons.collections.CollectionUtils;
023 import org.joda.time.DateTime;
024 import org.junit.Test;
025 import org.kuali.hr.KPMEWebTestCase;
026 import org.kuali.hr.util.HtmlUnitUtil;
027 import org.kuali.kpme.core.FunctionalTest;
028 import org.kuali.kpme.core.util.TKUtils;
029 import org.kuali.kpme.pm.positionreportcat.PositionReportCategory;
030 import org.kuali.kpme.pm.service.base.PmServiceLocator;
031 import org.kuali.kpme.pm.utils.PmTestConstants;
032
033 import com.gargoylesoftware.htmlunit.html.HtmlElement;
034 import com.gargoylesoftware.htmlunit.html.HtmlForm;
035 import com.gargoylesoftware.htmlunit.html.HtmlInput;
036 import com.gargoylesoftware.htmlunit.html.HtmlPage;
037
038 @FunctionalTest
039 public class PositionReportCatMaintTest extends KPMEWebTestCase {
040
041 @Test
042 public void testRequiredFields() throws Exception {
043 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_CAT_MAINT_NEW_URL;
044 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
045 Assert.assertNotNull(page);
046
047 HtmlForm form = page.getFormByName("KualiForm");
048 Assert.assertNotNull("Search form was missing from page.", form);
049
050 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
051 Assert.assertNotNull("Could not locate submit button", input);
052
053 HtmlElement element = page.getElementByName("methodToCall.route");
054 page = element.click();
055 Assert.assertTrue("page text does not contain:\n" + "Effective Date (Effective Date) is a required field.",
056 page.asText().contains("Effective Date (Effective Date) is a required field."));
057 Assert.assertTrue("page text does not contain:\n" + "Position Report Category (Position Report Category) is a required field.",
058 page.asText().contains("Position Report Category (Position Report Category) is a required field."));
059 Assert.assertTrue("page text does not contain:\n" + "Position Report Type (Position Report Type) is a required field.",
060 page.asText().contains("Position Report Type (Position Report Type) is a required field."));
061 Assert.assertTrue("page text does not contain:\n" + "Institution (Institution) is a required field.",
062 page.asText().contains("Institution (Institution) is a required field."));
063 Assert.assertTrue("page text does not contain:\n" + "Location (Location) is a required field.",
064 page.asText().contains("Location (Location) is a required field."));
065 }
066
067 @Test
068 public void testAddNew() throws Exception {
069 DateTime effectiveDate = new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
070 String prcString = "testPRC";
071 String prtString = "testPRT";
072 List<PositionReportCategory> prcList = PmServiceLocator.getPositionReportCatService().getPositionReportCatList(prcString, prtString, "testInst", "TS", effectiveDate.toLocalDate());
073 Assert.assertTrue("There should NOT be Position Report Category with name " + prcString, CollectionUtils.isEmpty(prcList));
074
075 String baseUrl = PmTestConstants.Urls.POSITION_REPORT_CAT_MAINT_NEW_URL;
076 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
077 Assert.assertNotNull(page);
078
079 HtmlForm form = page.getFormByName("KualiForm");
080 Assert.assertNotNull("Search form was missing from page.", form);
081
082 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Position Report Category - test");
083 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
084 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportCat", prcString);
085 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportType", "noType"); // non-existing positionReportType
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 Assert.assertTrue("page text contains:\n" + "The specified PositionReportType 'noType' does not exist.",
099 page.asText().contains("The specified PositionReportType 'noType' does not exist."));
100
101 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportType", prtString); // postionReportType and location do not match
102 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "NN"); // existing, non-matching location
103 element = page.getElementByName("methodToCall.route");
104 page = element.click();
105 Assert.assertFalse("page text contains:\n" + "The specified Location 'NN' does not exist.",
106 page.asText().contains("The specified Locaiton 'NN' does not exist."));
107 Assert.assertTrue("page text contains:\n" + "Institution 'nonExistInst' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'",
108 page.asText().contains("Institution 'nonExistInst' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'"));
109
110 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "II"); // existing, non-matching institution
111 element = page.getElementByName("methodToCall.route");
112 page = element.click();
113 Assert.assertTrue("page text contains:\n" + "Institution 'II' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'",
114 page.asText().contains("Institution 'II' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'"));
115 Assert.assertFalse("page text contains:\n" + "The specified Instituion 'II' does not exist.",
116 page.asText().contains("The specified Instituion 'II' does not exist."));
117
118 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "testInst"); // matching institution
119 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "BL"); // matching location
120 element = page.getElementByName("methodToCall.route");
121 page = element.click();
122 Assert.assertFalse("page text contains error", page.asText().contains("error"));
123
124 prcList = PmServiceLocator.getPositionReportCatService().getPositionReportCatList(prcString, prtString, "testInst", "BL", effectiveDate.toLocalDate());
125 Assert.assertTrue("There should be Position Report Category with name " + prcString, CollectionUtils.isNotEmpty(prcList));
126
127 }
128 }