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