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.positionreportcat;
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.positionreportcat.PositionReportCategoryContract;
030import org.kuali.kpme.pm.positionreportcat.PositionReportCategoryBo;
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 PositionReportCatMaintTest extends KPMEWebTestCase {
041        
042        @Test
043        public void testRequiredFields() throws Exception {
044          /* KPME-3088: converting to krad broke tests, need to fix when KRAD testing is figured out
045                String baseUrl = PmTestConstants.Urls.POSITION_REPORT_CAT_MAINT_NEW_URL;
046
047                HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
048                Assert.assertNotNull(page);
049         
050                HtmlForm form = page.getFormByName("KualiForm");
051                Assert.assertNotNull("Search form was missing from page.", form);
052                
053                HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
054                Assert.assertNotNull("Could not locate submit button", input);
055                
056                HtmlElement element = page.getElementByName("methodToCall.route");
057                page = element.click();
058                Assert.assertTrue("page text does not contain:\n" + "Effective Date (Effective Date) is a required field.", 
059                                page.asText().contains("Effective Date (Effective Date) is a required field."));
060                Assert.assertTrue("page text does not contain:\n" + "Position Report Category (Position Report Category) is a required field.", 
061                                page.asText().contains("Position Report Category (Position Report Category) is a required field."));
062                Assert.assertTrue("page text does not contain:\n" + "Position Report Type (Position Report Type) is a required field.", 
063                                page.asText().contains("Position Report Type (Position Report Type) is a required field."));
064                Assert.assertTrue("page text does not contain:\n" + "Institution (Institution) is a required field.",
065                                page.asText().contains("Institution (Institution) is a required field."));
066                Assert.assertTrue("page text does not contain:\n" + "Location (Location) is a required field.", 
067                                page.asText().contains("Location (Location) is a required field."));
068        }
069        
070        @Test
071        public void testAddNew() throws Exception {
072                DateTime effectiveDate =  new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
073                String prcString = "testPRC";
074                String prtString = "testPRT";
075                List<? extends PositionReportCategoryContract> prcList = PmServiceLocator.getPositionReportCatService().getPositionReportCatList(prcString, prtString, "testInst", "TS", effectiveDate.toLocalDate());
076                Assert.assertTrue("There should NOT be Position Report Category with name " + prcString, CollectionUtils.isEmpty(prcList));
077                
078                String baseUrl = PmTestConstants.Urls.POSITION_REPORT_CAT_MAINT_NEW_URL;
079                HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
080                Assert.assertNotNull(page);
081         
082                HtmlForm form = page.getFormByName("KualiForm");
083                Assert.assertNotNull("Search form was missing from page.", form);
084                
085                HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Position Report Category - test");
086            HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
087            HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportCat", prcString);
088            HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportType", "noType"); // non-existing positionReportType
089            HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "nonExistInst");     //nonexisting institution
090            HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "nonCam");      //nonexisting location
091                
092                HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
093                Assert.assertNotNull("Could not locate submit button", input);
094                HtmlElement element = page.getElementByName("methodToCall.route");
095                page = element.click();
096                HtmlUnitUtil.createTempFile(page);
097                Assert.assertTrue("page text contains:\n" + "The specified Instituion 'nonExistInst' does not exist.", 
098                                page.asText().contains("The specified Instituion 'nonExistInst' does not exist."));
099                Assert.assertTrue("page text contains:\n" + "The specified Location 'nonCam' does not exist.", 
100                                page.asText().contains("The specified Location 'nonCam' does not exist."));
101                Assert.assertTrue("page text contains:\n" + "The specified PositionReportType 'noType' does not exist.", 
102                                page.asText().contains("The specified PositionReportType 'noType' does not exist."));
103                
104                HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.positionReportType", prtString); // postionReportType and location do not match
105                HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "NN"); // existing, non-matching location
106                element = page.getElementByName("methodToCall.route");
107                page = element.click();
108                Assert.assertFalse("page text contains:\n" + "The specified Location 'NN' does not exist.", 
109                                page.asText().contains("The specified Locaiton 'NN' does not exist."));
110                Assert.assertTrue("page text contains:\n" + "Institution 'nonExistInst' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'", 
111                                page.asText().contains("Institution 'nonExistInst' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'"));
112                
113                HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "II"); // existing, non-matching institution
114                element = page.getElementByName("methodToCall.route");
115                page = element.click();
116                Assert.assertTrue("page text contains:\n" + "Institution 'II' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'", 
117                                page.asText().contains("Institution 'II' is inconsistent with institution 'testInst' of PositionReportType 'testPRT'"));
118                Assert.assertFalse("page text contains:\n" + "The specified Instituion 'II' does not exist.", 
119                                page.asText().contains("The specified Instituion 'II' does not exist."));
120                
121                HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.institution", "testInst"); // matching institution             
122                HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "BL"); // matching location
123                element = page.getElementByName("methodToCall.route");
124                page = element.click();
125                Assert.assertFalse("page text contains error", page.asText().contains("error"));
126                
127                prcList = PmServiceLocator.getPositionReportCatService().getPositionReportCatList(prcString, prtString, "testInst", "BL", effectiveDate.toLocalDate());
128                Assert.assertTrue("There should be Position Report Category with name " + prcString, CollectionUtils.isNotEmpty(prcList));
129          */
130        }
131}