View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.assignment;
17  
18  
19  import org.junit.Assert;
20  import org.junit.Test;
21  import org.kuali.hr.test.KPMETestCase;
22  import org.kuali.hr.time.test.HtmlUnitUtil;
23  import org.kuali.hr.time.test.TkTestConstants;
24  import com.gargoylesoftware.htmlunit.html.HtmlElement;
25  import com.gargoylesoftware.htmlunit.html.HtmlForm;
26  import com.gargoylesoftware.htmlunit.html.HtmlInput;
27  import com.gargoylesoftware.htmlunit.html.HtmlPage;
28  
29  public class AssignmentMaintTest extends KPMETestCase {
30  
31  	//data defined in boot strap script
32  	private static final String TEST_CODE="admin";
33  	final String ERROR_EFF_DATE = "Effective Date (Effective Date) is a required field.";
34  	final String ERROR_PRINCIPAL_ID = "Principal Id (Principal Id) is a required field.";
35  	final String ERROR_JOB_NUMBER = "Job Number (Job Number) is a required field.";
36  	final String ERROR_WORK_AREA = "Work Area (Work Area) is a required field.";
37  	final String ERROR_TASK = "Task (Task) is a required field.";
38  	final String ERROR_TASK_NULL = "The specified task 'null' does not exist.";
39  	final String ERROR_JOB_NUMBER_NULL = "The specified jobNumber 'null' does not exist.";
40  	final String ERROR_JOB_NUMBER_INVALID = "The specified jobNumber '1' does not exist.";
41  
42  
43  	@Test
44  	public void testAssignmentMaint() throws Exception {
45  		HtmlPage assignmentLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.ASSIGNMENT_MAINT_URL);
46  		setFieldValue(assignmentLookUp, "workArea", "30");
47  		assignmentLookUp = HtmlUnitUtil.clickInputContainingText(assignmentLookUp, "search");
48  		Assert.assertTrue("Page contains test assignment", assignmentLookUp.asText().contains(TEST_CODE.toString()));
49  		HtmlUnitUtil.createTempFile(assignmentLookUp);
50  		
51  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(assignmentLookUp, "edit");
52  		HtmlUnitUtil.createTempFile(maintPage);
53  		Assert.assertTrue("Maintenance Page contains test assignment",maintPage.asText().contains(TEST_CODE.toString()));	
54  	}
55  
56  	@Test
57  	public void testAssignmentCreateNew() throws Exception {
58  
59      	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.ASSIGNMENT_MAINT_NEW_URL);
60      	Assert.assertNotNull(page);
61      	HtmlForm form = page.getFormByName("KualiForm");
62      	Assert.assertNotNull("Search form was missing from page.", form);
63      	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
64      	Assert.assertNotNull("Could not locate submit button", input);
65  
66      	setFieldValue(page, "document.documentHeader.documentDescription", "Assignment - test");
67      	HtmlElement element = page.getElementByName("methodToCall.route");
68          HtmlPage nextPage = element.click();
69          Assert.assertTrue("pagedoes not contain: " + ERROR_EFF_DATE, nextPage.asText().contains(ERROR_EFF_DATE));
70          Assert.assertTrue("page does not contain: " + ERROR_PRINCIPAL_ID, nextPage.asText().contains(ERROR_PRINCIPAL_ID));
71          Assert.assertTrue("page does not contain: " + ERROR_JOB_NUMBER, nextPage.asText().contains(ERROR_JOB_NUMBER));
72          Assert.assertTrue("page does not contain: " + ERROR_JOB_NUMBER_NULL, nextPage.asText().contains(ERROR_JOB_NUMBER_NULL));
73          Assert.assertTrue("page does not contain: " + ERROR_WORK_AREA, nextPage.asText().contains(ERROR_WORK_AREA));
74          // Task field is not required
75          Assert.assertFalse("page contains: " + ERROR_TASK, nextPage.asText().contains(ERROR_TASK));
76          // validating of task has been removed from AssignmentRule
77          Assert.assertFalse("page contains: " + ERROR_TASK_NULL, nextPage.asText().contains(ERROR_TASK_NULL));
78  	}
79  
80  	@Test
81  	public void testAssignmentCreateNewJobValidation() throws Exception {
82  
83  		HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.ASSIGNMENT_MAINT_NEW_URL);
84  		Assert.assertNotNull(page);
85  		HtmlForm form = page.getFormByName("KualiForm");
86  		Assert.assertNotNull("Search form was missing from page.", form);
87  		HtmlInput  descriptionText  = HtmlUnitUtil.getInputContainingText(form, "document.documentHeader.documentDescription");
88  		Assert.assertNotNull("Could not locate submit button", descriptionText);
89  		descriptionText.setValueAttribute("Creating new assignment");
90  		HtmlInput  effDateText  = HtmlUnitUtil.getInputContainingText(form, "document.newMaintainableObject.effectiveDate");
91  		Assert.assertNotNull("Could not locate submit button", effDateText);
92  		effDateText.setValueAttribute("06/27/2011");
93  		HtmlInput  principalText  = HtmlUnitUtil.getInputContainingText(form, "document.newMaintainableObject.principalId");
94  		Assert.assertNotNull("Could not locate submit button", principalText);
95  		principalText.setValueAttribute("10008");
96  		HtmlInput  jobNumberText  = HtmlUnitUtil.getInputContainingText(form, "document.newMaintainableObject.jobNumber");
97  		Assert.assertNotNull("Could not locate submit button", jobNumberText);
98  		jobNumberText.setValueAttribute("1");
99  		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 }