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  
25  import com.gargoylesoftware.htmlunit.html.HtmlElement;
26  import com.gargoylesoftware.htmlunit.html.HtmlForm;
27  import com.gargoylesoftware.htmlunit.html.HtmlInput;
28  import com.gargoylesoftware.htmlunit.html.HtmlPage;
29  
30  public class AssignmentMaintTest extends KPMETestCase {
31  	
32  	//data defined in boot strap script
33  	private static final String TEST_CODE="admin";
34  	final String ERROR_EFF_DATE = "Effective Date (Effective Date) is a required field.";
35  	final String ERROR_PRINCIPAL_ID = "Principal Id (Principal Id) is a required field.";
36  	final String ERROR_JOB_NUMBER = "Job Number (Job Number) is a required field.";
37  	final String ERROR_WORK_AREA = "Work Area (Work Area) is a required field.";
38  	final String ERROR_TASK = "Task (Task) is a required field.";
39  	final String ERROR_TASK_NULL = "The specified task 'null' does not exist.";
40  	final String ERROR_JOB_NUMBER_NULL = "The specified jobNumber 'null' does not exist.";
41  	final String ERROR_JOB_NUMBER_INVALID = "The specified jobNumber '1' does not exist.";
42  	
43  	
44  	@Test
45  	public void testAssignmentMaint() throws Exception {
46  		HtmlPage assignmentLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.ASSIGNMENT_MAINT_URL);
47  		setFieldValue(assignmentLookUp, "workArea", "30");
48  		assignmentLookUp = HtmlUnitUtil.clickInputContainingText(assignmentLookUp, "search");
49  		Assert.assertTrue("Page contains test assignment", assignmentLookUp.asText().contains(TEST_CODE.toString()));
50  		HtmlUnitUtil.createTempFile(assignmentLookUp);
51  		
52  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(assignmentLookUp, "edit");
53  		HtmlUnitUtil.createTempFile(maintPage);
54  		Assert.assertTrue("Maintenance Page contains test assignment",maintPage.asText().contains(TEST_CODE.toString()));	
55  	}
56  	
57  	@Test
58  	public void testAssignmentCreateNew() throws Exception {
59  		
60      	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.ASSIGNMENT_MAINT_NEW_URL);
61      	Assert.assertNotNull(page);
62      	HtmlForm form = page.getFormByName("KualiForm");
63      	Assert.assertNotNull("Search form was missing from page.", form);
64      	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
65      	Assert.assertNotNull("Could not locate submit button", input);
66      	
67      	setFieldValue(page, "document.documentHeader.documentDescription", "Assignment - test");
68      	HtmlElement element = page.getElementByName("methodToCall.route");
69          HtmlPage nextPage = element.click();
70          Assert.assertTrue("pagedoes not contain: " + ERROR_EFF_DATE, nextPage.asText().contains(ERROR_EFF_DATE));
71          Assert.assertTrue("page does not contain: " + ERROR_PRINCIPAL_ID, nextPage.asText().contains(ERROR_PRINCIPAL_ID));
72          Assert.assertTrue("page does not contain: " + ERROR_JOB_NUMBER, nextPage.asText().contains(ERROR_JOB_NUMBER));
73          Assert.assertTrue("page does not contain: " + ERROR_JOB_NUMBER_NULL, nextPage.asText().contains(ERROR_JOB_NUMBER_NULL));
74          Assert.assertTrue("page does not contain: " + ERROR_WORK_AREA, nextPage.asText().contains(ERROR_WORK_AREA));
75          // Task field is not required
76          Assert.assertFalse("page contains: " + ERROR_TASK, nextPage.asText().contains(ERROR_TASK));
77          // validating of task has been removed from AssignmentRule
78          Assert.assertFalse("page contains: " + ERROR_TASK_NULL, nextPage.asText().contains(ERROR_TASK_NULL));
79  	}
80  	
81  	@Test
82  	public void testAssignmentCreateNewJobValidation() throws Exception {
83  		
84  		HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.ASSIGNMENT_MAINT_NEW_URL);
85  		Assert.assertNotNull(page);
86  		HtmlForm form = page.getFormByName("KualiForm");
87  		Assert.assertNotNull("Search form was missing from page.", form);
88  		HtmlInput  descriptionText  = HtmlUnitUtil.getInputContainingText(form, "document.documentHeader.documentDescription");
89  		Assert.assertNotNull("Could not locate submit button", descriptionText);
90  		descriptionText.setValueAttribute("Creating new assignment");
91  		HtmlInput  effDateText  = HtmlUnitUtil.getInputContainingText(form, "document.newMaintainableObject.effectiveDate");
92  		Assert.assertNotNull("Could not locate submit button", effDateText);
93  		effDateText.setValueAttribute("06/27/2011");		
94  		HtmlInput  principalText  = HtmlUnitUtil.getInputContainingText(form, "document.newMaintainableObject.principalId");
95  		Assert.assertNotNull("Could not locate submit button", principalText);
96  		principalText.setValueAttribute("10008");		
97  		HtmlInput  jobNumberText  = HtmlUnitUtil.getInputContainingText(form, "document.newMaintainableObject.jobNumber");
98  		Assert.assertNotNull("Could not locate submit button", jobNumberText);
99  		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 }