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