1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.workarea;
17
18 import java.sql.Date;
19
20 import org.joda.time.DateTime;
21 import org.joda.time.DateTimeZone;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.kuali.hr.test.KPMETestCase;
26 import org.kuali.hr.time.department.Department;
27 import org.kuali.hr.time.service.base.TkServiceLocator;
28 import org.kuali.hr.time.test.HtmlUnitUtil;
29 import org.kuali.hr.time.test.TkTestConstants;
30 import org.kuali.hr.time.util.TKUtils;
31 import org.kuali.hr.time.util.TkConstants;
32 import org.kuali.rice.krad.service.KRADServiceLocator;
33
34 import com.gargoylesoftware.htmlunit.html.HtmlElement;
35 import com.gargoylesoftware.htmlunit.html.HtmlForm;
36 import com.gargoylesoftware.htmlunit.html.HtmlInput;
37 import com.gargoylesoftware.htmlunit.html.HtmlPage;
38
39 public class WorkAreaMaintenanceDocumentTest extends KPMETestCase {
40
41 final String ERROR_MESSAGE = "At least one active role must be defined.";
42 final String ERROR_ROLE_MESSAGE = "Cannot define both Principal Id and Position Number for Role.";
43 final String SUCCESS_MESSAGE = "Document was successfully submitted.";
44 private static final String TEST_CODE_DEPARTMENT_VALID = "_TEST";
45 private static final Date TEST_DATE = new Date((new DateTime(2011,1,1,1,0,0,0,TKUtils.getSystemDateTimeZone())).getMillis());
46
47 @Before
48 public void setUp() throws Exception {
49 super.setUp();
50 Department department = new Department();
51 department.setDept(TEST_CODE_DEPARTMENT_VALID);
52 department.setChart(TEST_CODE_DEPARTMENT_VALID);
53 department.setDescription(TEST_CODE_DEPARTMENT_VALID);
54 department.setOrg(TEST_CODE_DEPARTMENT_VALID);
55 department.setLocation("TST");
56 department.setEffectiveDate(TEST_DATE);
57 department.setActive(true);
58 KRADServiceLocator.getBusinessObjectService().save(department);
59 }
60
61
62 @Test
63 public void testCreateNew() throws Exception {
64 String baseUrl = TkTestConstants.Urls.WORK_AREA_MAINT_NEW_URL;
65 Long workArea = this.maxWorkArea()+1;
66 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
67 Assert.assertNotNull(page);
68
69 HtmlForm form = page.getFormByName("KualiForm");
70 Assert.assertNotNull("Search form was missing from page.", form);
71
72 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
73 Assert.assertNotNull("Could not locate submit button", input);
74
75 setFieldValue(page, "document.documentHeader.documentDescription", "Work Area - test");
76 setFieldValue(page, "document.newMaintainableObject.effectiveDate", "4/01/2011");
77 setFieldValue(page, "document.newMaintainableObject.active", "on");
78 setFieldValue(page, "document.newMaintainableObject.description", "test");
79 setFieldValue(page, "document.newMaintainableObject.dept", TEST_CODE_DEPARTMENT_VALID);
80 setFieldValue(page, "document.newMaintainableObject.adminDescr", "TEST");
81 setFieldValue(page, "document.newMaintainableObject.overtimeEditRole", "TK_APPROVER");
82
83 HtmlElement element = page.getElementByName("methodToCall.route");
84 HtmlPage nextPage = element.click();
85 Assert.assertTrue("page does not contain:\n" + ERROR_MESSAGE, nextPage.asText().contains(ERROR_MESSAGE));
86
87 setFieldValue(page, "document.newMaintainableObject.add.roles.effectiveDate", "04/01/2011");
88 setFieldValue(page, "document.newMaintainableObject.add.roles.principalId", "admin");
89 setFieldValue(page, "document.newMaintainableObject.add.roles.positionNumber", "123");
90 setFieldValue(page, "document.newMaintainableObject.add.roles.active", "on");
91
92 element = HtmlUnitUtil.getInputContainingText(page,"methodToCall.addLine.roles");
93 nextPage = element.click();
94 Assert.assertTrue("page does not contain:\n" + ERROR_ROLE_MESSAGE, nextPage.asText().contains(ERROR_ROLE_MESSAGE));
95
96 setFieldValue(nextPage, "document.newMaintainableObject.add.roles.positionNumber", "");
97 element = HtmlUnitUtil.getInputContainingText(nextPage,"methodToCall.addLine.roles");
98 nextPage = element.click();
99 Assert.assertFalse("page contains:\n" + ERROR_MESSAGE, nextPage.asText().contains(ERROR_MESSAGE));
100 Assert.assertFalse("page contains:\n" + ERROR_ROLE_MESSAGE, nextPage.asText().contains(ERROR_ROLE_MESSAGE));
101
102 form = nextPage.getFormByName("KualiForm");
103 Assert.assertNotNull("Search form was missing from page.", form);
104
105 input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
106 Assert.assertNotNull("Could not locate submit button", input);
107
108 element = nextPage.getElementByName("methodToCall.route");
109 HtmlPage lastPage = element.click();
110 Assert.assertFalse("page contains:\n" + ERROR_MESSAGE, lastPage.asText().contains(ERROR_MESSAGE));
111 Assert.assertTrue("page does not contains:\n" + SUCCESS_MESSAGE, lastPage.asText().contains(SUCCESS_MESSAGE));
112 Assert.assertTrue("page does not contains:\n" + workArea.toString(), lastPage.asText().contains(workArea.toString()));
113
114
115 HtmlPage searchPage = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.WORK_AREA_MAINT_URL);
116 searchPage = HtmlUnitUtil.clickInputContainingText(searchPage, "search");
117 Assert.assertTrue("Page contains test Earn Code", searchPage.asText().contains(workArea.toString()));
118
119 java.sql.Date aDate = new Date((new DateTime(2011, 5, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
120 WorkArea wa = TkServiceLocator.getWorkAreaService().getWorkArea(workArea, aDate);
121 String workAreaId = wa.getTkWorkAreaId().toString();
122
123
124 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(searchPage, "edit", workAreaId);
125 HtmlElement e = maintPage.getHtmlElementById("document.oldMaintainableObject.roles[0].effectiveDate.div");
126 Assert.assertNotNull("Maintenance Page does not contain role ", e);
127 }
128
129 public Long maxWorkArea() {
130 return TkServiceLocator.getWorkAreaService().getNextWorkAreaKey();
131
132 }
133
134 @Override
135 public void tearDown() throws Exception {
136 Department deptObj = TkServiceLocator.getDepartmentService().getDepartment(TEST_CODE_DEPARTMENT_VALID, TKUtils.getCurrentDate());
137 KRADServiceLocator.getBusinessObjectService().delete(deptObj);
138 super.tearDown();
139 }
140 }