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