1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leave.approval;
17
18 import org.junit.After;
19 import org.junit.Assert;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.kuali.hr.KPMEWebTestCase;
23 import org.kuali.hr.util.HtmlUnitUtil;
24 import org.kuali.kpme.core.FunctionalTest;
25 import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
26 import org.kuali.kpme.core.calendar.entry.CalendarEntryBo;
27 import org.kuali.kpme.core.service.HrServiceLocator;
28 import org.kuali.kpme.tklm.leave.calendar.LeaveCalendarDocument;
29 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
30 import org.kuali.kpme.tklm.utils.TkTestConstants;
31
32 import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
33 import com.gargoylesoftware.htmlunit.WebClient;
34 import com.gargoylesoftware.htmlunit.html.HtmlButton;
35 import com.gargoylesoftware.htmlunit.html.HtmlPage;
36
37 @FunctionalTest
38 public class LeaveCalendarWebTest extends KPMEWebTestCase {
39
40 private String documentId;
41
42 @Before
43 public void setUp() throws Exception {
44 super.setUp();
45
46 CalendarEntry firstCalendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry("202");
47 LeaveCalendarDocument firstLeaveCalendarDocument = LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", firstCalendarEntry);
48 documentId = firstLeaveCalendarDocument.getDocumentId();
49
50 CalendarEntry secondCalendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry("203");
51 LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", secondCalendarEntry);
52
53 CalendarEntry thirdCalendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry("204");
54 LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", thirdCalendarEntry);
55 }
56
57 @After
58 public void tearDown() throws Exception {
59 super.tearDown();
60 }
61
62 @Override
63 public void setWebClient(WebClient webClient) {
64 super.setWebClient(webClient);
65 webClient.setAjaxController(new NicelyResynchronizingAjaxController());
66 webClient.waitForBackgroundJavaScript(10000);
67 }
68
69 @Test
70 public void testLeaveCalendarPage() throws Exception {
71
72 HtmlPage leaveCalendarPage = HtmlUnitUtil
73 .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_CALENDAR_URL+"?documentId=" + documentId, true);
74 Assert.assertNotNull("Leave Request page not found" ,leaveCalendarPage);
75
76
77
78 Assert.assertTrue("Page does not have Current calendar ", leaveCalendarPage.asText().contains("March 2012"));
79
80
81 HtmlButton nextButton = (HtmlButton) leaveCalendarPage
82 .getElementById("nav_next_lc");
83 Assert.assertNotNull(nextButton);
84
85 HtmlPage page = nextButton.click();
86 Assert.assertNotNull(page);
87
88 synchronized (page) {
89 page.wait(5000);
90 }
91 String pageText = page.asText();
92 LOG.info(pageText);
93
94 HtmlButton prevButton = (HtmlButton) page
95 .getElementById("nav_prev_lc");
96 Assert.assertNotNull(prevButton);
97 page = prevButton.click();
98 Assert.assertNotNull(page);
99
100 }
101
102 }