1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.missedpunch.validation;
17
18 import java.util.List;
19
20 import org.apache.log4j.Logger;
21 import com.gargoylesoftware.htmlunit.html.*;
22 import org.junit.After;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.kuali.hr.test.KPMETestCase;
27 import org.kuali.hr.time.test.HtmlUnitUtil;
28 import org.kuali.hr.time.test.TkTestConstants;
29
30 import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
31 import com.gargoylesoftware.htmlunit.WebClient;
32 import com.google.common.collect.Lists;
33
34 public class MissedPunchDocumentTest extends KPMETestCase {
35 private static final Logger LOG = Logger.getLogger(MissedPunchDocumentTest.class);
36
37 @Before
38 public void setUp() throws Exception {
39 super.setUp();
40 }
41
42 @After
43 public void tearDown() throws Exception {
44 super.tearDown();
45 }
46
47 public void updateWebClient() {
48 WebClient webClient = getWebClient();
49 webClient.setJavaScriptEnabled(true);
50 webClient.setThrowExceptionOnScriptError(true);
51 webClient.setAjaxController(new NicelyResynchronizingAjaxController());
52 webClient.waitForBackgroundJavaScript(10000);
53 }
54
55 @Test
56 public void testMissedPunch() throws Exception {
57
58 String baseUrl = TkTestConstants.Urls.CLOCK_URL;
59 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
60 Assert.assertNotNull(page);
61 Assert.assertTrue("Clock Page contains Missed Punch Button", page.asText()
62 .contains("Missed Punch"));
63 updateWebClient();
64
65 LOG.debug("Page is : " + page.asText());
66
67
68 HtmlSelect assOption = (HtmlSelect) page
69 .getElementByName("selectedAssignment");
70 Iterable<HtmlElement> it = assOption.getChildElements();
71 List<HtmlElement> assList = Lists.newLinkedList(it);
72
73 LOG.debug("Second ele is : "+assList.get(2));
74
75
76 HtmlOption ho = null;
77 if(assList.size() > 2) {
78 ho = (HtmlOption) assList.get(2);
79 } else {
80 ho= (HtmlOption) assList.get(0);
81 }
82 LOG.debug("ho is : " + ho.asText());
83 assOption.setSelectedAttribute(ho, true);
84
85
86
87 HtmlTableDataCell htmlTable = (HtmlTableDataCell) page.getByXPath(
88 "//tbody//tr//td").get(9);
89 LOG.debug("htmlTable.getTextContent();"
90 + htmlTable.getTextContent());
91
92 String docId = htmlTable.getTextContent();
93
94
95 HtmlPage mPunchPage = HtmlUnitUtil
96 .gotoPageAndLogin(getWebClient(), HtmlUnitUtil.getBaseURL()
97 + "/missedPunch.do?methodToCall=docHandler&command=initiate&docTypeName=MissedPunchDocumentType&tdocid="
98 + docId);
99 Assert.assertNotNull(mPunchPage);
100
101
102 HtmlElement element = (HtmlElement)mPunchPage.getElementById("document.clockAction");
103 Assert.assertNotNull(element);
104 element = (HtmlElement)mPunchPage.getElementById("document.assignment");
105 Assert.assertNotNull(element);
106
107 LOG.debug("Page1 is : " + mPunchPage.asText());
108
109
110 setFieldValue(mPunchPage, "document.documentHeader.documentDescription",
111 "Missed Punch- test");
112 setFieldValue(mPunchPage, "document.clockAction", "CO");
113 setFieldValue(mPunchPage, "document.actionDate", "01/16/2012");
114 setFieldValue(mPunchPage, "document.actionTime", "5:5");
115 setFieldValue(mPunchPage, "document.assignment", "2_1234_2");
116
117 HtmlElement elementSubmit = mPunchPage
118 .getElementByName("methodToCall.route");
119 mPunchPage = elementSubmit.click();
120
121 LOG.debug("After first click >>>>> page is : "
122 + mPunchPage.asText());
123
124 Assert.assertTrue("page text:\n" + mPunchPage.asText() + "\n does not contain:\n",
125 mPunchPage.asText().contains("5:5 is not a valid time."));
126
127
128 setFieldValue(mPunchPage, "document.actionDate", "01/20/2020");
129 setFieldValue(mPunchPage, "document.actionTime", "5:50 AM");
130
131 elementSubmit = mPunchPage.getElementByName("methodToCall.route");
132 mPunchPage = elementSubmit.click();
133
134 Assert.assertTrue(
135 "page text:\n" + mPunchPage.asText() + "\n does not contain:\n",
136 mPunchPage.asText().contains(
137 "Missed Punch Action Date cannot be a future date"));
138
139 LOG.debug("After second click >>>>> page is : "
140 + mPunchPage.asText());
141
142
143 setFieldValue(mPunchPage, "document.clockAction", "CI");
144 setFieldValue(mPunchPage, "document.actionDate", "12/20/2009");
145 setFieldValue(mPunchPage, "document.actionTime", "5:50 AM");
146
147
148 elementSubmit = mPunchPage.getElementByName("methodToCall.route");
149
150 mPunchPage = elementSubmit.click();
151 LOG.debug("After third click >>>>> page is : "
152 + mPunchPage.asText());
153
154 Assert.assertTrue(
155 "page text:\n" + mPunchPage.asText() + "\n does not contain:\n",
156 mPunchPage.asText()
157 .contains(
158 "Assignment is not effective as of date chosen."));
159
160
161
162 setFieldValue(mPunchPage, "document.actionDate", "01/19/2012");
163 setFieldValue(mPunchPage, "document.actionTime", "5:50 AM");
164 setFieldValue(mPunchPage, "document.clockAction", "CI");
165
166
167 HtmlElement elementSubmit1 = mPunchPage.getElementByName("methodToCall.route");
168 mPunchPage = elementSubmit1.click();
169
170 LOG.debug("After forth click >>>>> page is : "
171 + mPunchPage.asText());
172
173 Assert.assertTrue("page text:\n" + mPunchPage.asText() + "\n does not contain:\n",
174 mPunchPage.asText().contains("Document was successfully submitted."));
175
176
177 mPunchPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HtmlUnitUtil.getBaseURL()
178 + "/missedPunch.do?methodToCall=docHandler&command=initiate&docTypeName=MissedPunchDocumentType&tdocid="
179 + docId);
180 Assert.assertNotNull(mPunchPage);
181 element = (HtmlElement)mPunchPage.getElementById("document.clockAction");
182 Assert.assertNotNull(element);
183
184 element = (HtmlElement)mPunchPage.getElementById("document.assignment");
185 Assert.assertNull(element);
186 Assert.assertTrue("page text:does not contain: \n",
187 mPunchPage.asText().contains("Assignment: work area description : $0.00 Rcd 2 TEST-DEPT description 2"));
188
189 }
190 }