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