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