1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leaveCalendar;
17
18 import org.apache.log4j.Logger;
19 import org.joda.time.DateTime;
20 import org.junit.Assert;
21 import org.kuali.hr.KPMEWebTestCase;
22 import org.kuali.hr.TestAutoLoginFilter;
23 import org.kuali.hr.util.HtmlUnitUtil;
24 import org.kuali.kpme.core.util.TKUtils;
25 import org.kuali.kpme.tklm.utils.TkTestConstants;
26 import org.kuali.rice.kim.api.identity.Person;
27 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
28
29 import com.gargoylesoftware.htmlunit.html.HtmlPage;
30
31 public abstract class LeaveCalendarWebTestBase extends KPMEWebTestCase {
32 private static final Logger LOG = Logger.getLogger(LeaveCalendarWebTestBase.class);
33 public static final DateTime JAN_AS_OF_DATE = new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
34 public static final String USER_PRINCIPAL_ID = "admin";
35
36 private String baseDetailURL = "";
37
38 @Override
39 public void setUp() throws Exception {
40 super.setUp();
41 setBaseDetailURL(TkTestConstants.Urls.LEAVE_CALENDAR_URL + "?documentId=");
42 }
43
44 @Override
45 public void tearDown() throws Exception {
46 super.tearDown();
47
48 TestAutoLoginFilter.OVERRIDE_ID = "";
49 }
50
51 public String getLeaveCalendarUrl(String tdocId) {
52 return getBaseDetailURL() + tdocId;
53 }
54
55
56
57
58
59 public synchronized HtmlPage loginAndGetLeaveCalendarHtmlPage(String principalId, String tdocId, boolean assertValid) throws Exception {
60
61 Person person = KimApiServiceLocator.getPersonService().getPerson(principalId);
62 Assert.assertNotNull(person);
63 Assert.assertEquals(person.getPrincipalId(), principalId);
64 TestAutoLoginFilter.OVERRIDE_ID = principalId;
65 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), getLeaveCalendarUrl(tdocId));
66 TestAutoLoginFilter.OVERRIDE_ID = "";
67 Assert.assertNotNull(page);
68 HtmlUnitUtil.createTempFile(page, "Login-"+principalId);
69 LOG.debug(page.asText());
70 String pageAsText = page.asText();
71 if (assertValid) {
72 Assert.assertTrue("Login info not present.", pageAsText.contains("Employee Id:"));
73 Assert.assertTrue("Login info not present for " + person.getName() , pageAsText.contains(person.getName()));
74 Assert.assertTrue("Wrong Document Loaded.", pageAsText.contains(tdocId));
75 }
76
77 return page;
78 }
79
80
81
82
83
84 public synchronized HtmlPage login(String principalId, String tdocId, boolean assertValid) throws Exception {
85
86 Person person = KimApiServiceLocator.getPersonService().getPerson(principalId);
87 Assert.assertNotNull(person);
88 Assert.assertEquals(person.getPrincipalId(), principalId);
89 TestAutoLoginFilter.OVERRIDE_ID = principalId;
90 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), getLeaveCalendarUrl(tdocId));
91 TestAutoLoginFilter.OVERRIDE_ID = "";
92 Assert.assertNotNull(page);
93
94 return page;
95 }
96
97 public String getBaseDetailURL() {
98 return baseDetailURL;
99 }
100
101 public void setBaseDetailURL(String baseDetailURL) {
102 this.baseDetailURL = baseDetailURL;
103 }
104 }