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.core.assignment;
017
018
019import org.junit.Assert;
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.core.util.HrTestConstants;
025
026import com.gargoylesoftware.htmlunit.html.HtmlElement;
027import com.gargoylesoftware.htmlunit.html.HtmlForm;
028import com.gargoylesoftware.htmlunit.html.HtmlInput;
029import com.gargoylesoftware.htmlunit.html.HtmlPage;
030
031@FunctionalTest
032public class AssignmentMaintTest extends KPMEWebTestCase {
033        
034        //data defined in boot strap script
035        private static final String TEST_CODE="admin";
036        final String ERROR_EFF_DATE = "Effective Date (Effective Date) is a required field.";
037        final String ERROR_PRINCIPAL_ID = "Principal Id (Principal Id) is a required field.";
038        final String ERROR_JOB_NUMBER = "Job Number (Job Number) is a required field.";
039        final String ERROR_WORK_AREA = "Work Area (Work Area) is a required field.";
040        final String ERROR_TASK = "Task (Task) is a required field.";
041        final String ERROR_TASK_NULL = "The specified task 'null' does not exist.";
042        final String ERROR_JOB_NUMBER_NULL = "The specified jobNumber 'null' does not exist.";
043        final String ERROR_JOB_NUMBER_INVALID = "The specified jobNumber '1' does not exist.";
044        
045        
046        @Test
047        public void testAssignmentMaint() throws Exception {
048                HtmlPage assignmentLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.ASSIGNMENT_MAINT_URL);
049                HtmlUnitUtil.setFieldValue(assignmentLookUp, "workArea", "30");
050                assignmentLookUp = HtmlUnitUtil.clickInputContainingText(assignmentLookUp, "search");
051                Assert.assertTrue("Page contains test assignment", assignmentLookUp.asText().contains(TEST_CODE.toString()));
052                HtmlUnitUtil.createTempFile(assignmentLookUp);
053                
054                HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(assignmentLookUp, "edit");
055                HtmlUnitUtil.createTempFile(maintPage);
056                Assert.assertTrue("Maintenance Page contains test assignment",maintPage.asText().contains(TEST_CODE.toString()));       
057        }
058        
059        @Test
060        public void testAssignmentCreateNew() throws Exception {
061                
062        HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.ASSIGNMENT_MAINT_NEW_URL);
063        Assert.assertNotNull(page);
064        HtmlForm form = page.getFormByName("KualiForm");
065        Assert.assertNotNull("Search form was missing from page.", form);
066        HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
067        Assert.assertNotNull("Could not locate submit button", input);
068        
069        HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Assignment - test");
070        HtmlElement element = page.getElementByName("methodToCall.route");
071        HtmlPage nextPage = element.click();
072        Assert.assertTrue("pagedoes not contain: " + ERROR_EFF_DATE, nextPage.asText().contains(ERROR_EFF_DATE));
073        Assert.assertTrue("page does not contain: " + ERROR_PRINCIPAL_ID, nextPage.asText().contains(ERROR_PRINCIPAL_ID));
074        Assert.assertTrue("page does not contain: " + ERROR_JOB_NUMBER, nextPage.asText().contains(ERROR_JOB_NUMBER));
075        Assert.assertTrue("page does not contain: " + ERROR_JOB_NUMBER_NULL, nextPage.asText().contains(ERROR_JOB_NUMBER_NULL));
076        Assert.assertTrue("page does not contain: " + ERROR_WORK_AREA, nextPage.asText().contains(ERROR_WORK_AREA));
077        // Task field is not required
078        Assert.assertFalse("page contains: " + ERROR_TASK, nextPage.asText().contains(ERROR_TASK));
079        // validating of task has been removed from AssignmentRule
080        Assert.assertFalse("page contains: " + ERROR_TASK_NULL, nextPage.asText().contains(ERROR_TASK_NULL));
081        }
082        
083        @Test
084        public void testAssignmentCreateNewJobValidation() throws Exception {
085                
086                HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.ASSIGNMENT_MAINT_NEW_URL);
087                Assert.assertNotNull(page);
088                HtmlForm form = page.getFormByName("KualiForm");
089                Assert.assertNotNull("Search form was missing from page.", form);
090                HtmlInput  descriptionText  = HtmlUnitUtil.getInputContainingText(form, "document.documentHeader.documentDescription");
091                Assert.assertNotNull("Could not locate document overview description field", descriptionText);
092                descriptionText.setValueAttribute("Creating new assignment");
093                HtmlInput  effDateText  = HtmlUnitUtil.getInputContainingText(form, "document.newMaintainableObject.effectiveDate");
094                Assert.assertNotNull("Could not locate effective date field", effDateText);
095                effDateText.setValueAttribute("06/27/2011");            
096                HtmlInput  principalText  = HtmlUnitUtil.getInputContainingText(form, "document.newMaintainableObject.principalId");
097                Assert.assertNotNull("Could not locate principal id field", principalText);
098                principalText.setValueAttribute("10008");               
099                HtmlInput  jobNumberText  = HtmlUnitUtil.getInputContainingText(form, "document.newMaintainableObject.jobNumber");
100                Assert.assertNotNull("Could not locate job number field", jobNumberText);
101                jobNumberText.setValueAttribute("1");           
102                HtmlInput  workAreaText  = HtmlUnitUtil.getInputContainingText(form, "document.newMaintainableObject.workArea");
103                Assert.assertNotNull("Could not locate work area field", workAreaText);
104                workAreaText.setValueAttribute("1016");         
105                HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
106                Assert.assertNotNull("Could not locate submit button", input);
107                HtmlUnitUtil.createTempFile(page);
108                HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Assignment - test");
109                HtmlElement element = page.getElementByName("methodToCall.route");
110                HtmlPage nextPage = element.click();
111                HtmlUnitUtil.createTempFile(nextPage);
112                Assert.assertTrue("pagedoes not contain: " + ERROR_JOB_NUMBER_INVALID, nextPage.asText().contains(ERROR_JOB_NUMBER_INVALID));
113                
114        }
115
116}