1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leaveadjustment;
17
18 import junit.framework.Assert;
19
20 import org.apache.log4j.Logger;
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.tklm.utils.TkTestConstants;
26
27 import com.gargoylesoftware.htmlunit.html.HtmlElement;
28 import com.gargoylesoftware.htmlunit.html.HtmlForm;
29 import com.gargoylesoftware.htmlunit.html.HtmlInput;
30 import com.gargoylesoftware.htmlunit.html.HtmlPage;
31
32 @FunctionalTest
33 public class LeaveAdjustmentMaintTest extends KPMEWebTestCase{
34 private static final Logger LOG = Logger.getLogger(LeaveAdjustmentMaintTest.class);
35 private static final String PRINCIPAL_ID = "admin";
36
37 private static final String EFFECTIVE_DATE_REQUIRED = "Effective Date (Effective Date) is a required field.";
38 private static final String PRINCIPAL_ID_REQUIRED = "Principal Id (Principal Id) is a required field.";
39 private static final String LEAVE_PLAN_REQUIRED = "Leave Plan (Leave Plan) is a required field.";
40 private static final String EARN_CODE_REQUIRED = "Earn Code (Earn Code) is a required field.";
41 private static final String ACCRUAL_CATEGORY_REQUIRED = "Accrual Category (Accrual Category) is a required field.";
42 private static final String DES_REQUIRED = "Description (Description) is a required field.";
43 private static final String ADJUSTMENT_AMOUNT_REQUIRED = "Adjustment Amount (Adjustment Amount) is a required field.";
44
45 @Test
46 public void testRequiredFields() throws Exception {
47 String baseUrl = TkTestConstants.Urls.LEAVE_ADJUSTMENT_MAINT_NEW_URL;
48 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
49 Assert.assertNotNull(page);
50
51 HtmlForm form = page.getFormByName("KualiForm");
52 Assert.assertNotNull("Search form was missing from page.", form);
53
54 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
55 Assert.assertNotNull("Could not locate submit button", input);
56
57 HtmlElement element = page.getElementByName("methodToCall.route");
58 page = element.click();
59 Assert.assertTrue("page text does not contain:\n" + EFFECTIVE_DATE_REQUIRED, page.asText().contains(EFFECTIVE_DATE_REQUIRED));
60 Assert.assertTrue("page text does not contain:\n" + PRINCIPAL_ID_REQUIRED, page.asText().contains(PRINCIPAL_ID_REQUIRED));
61 Assert.assertTrue("page text does not contain:\n" + LEAVE_PLAN_REQUIRED, page.asText().contains(LEAVE_PLAN_REQUIRED));
62 Assert.assertTrue("page text does not contain:\n" + ACCRUAL_CATEGORY_REQUIRED, page.asText().contains(ACCRUAL_CATEGORY_REQUIRED));
63 Assert.assertTrue("page text does not contain:\n" + EARN_CODE_REQUIRED, page.asText().contains(EARN_CODE_REQUIRED));
64 Assert.assertTrue("page text does not contain:\n" + DES_REQUIRED, page.asText().contains(DES_REQUIRED));
65 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.adjustmentAmount", "");
66 element = page.getElementByName("methodToCall.route");
67 page = element.click();
68 Assert.assertTrue("page text does not contain:\n" + ADJUSTMENT_AMOUNT_REQUIRED, page.asText().contains(ADJUSTMENT_AMOUNT_REQUIRED));
69 }
70
71 @Test
72 public void testLookupPage() throws Exception {
73 HtmlPage leaveAdjustmentLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_ADJUSTMENT_MAINT_URL);
74 leaveAdjustmentLookup = HtmlUnitUtil.clickInputContainingText(leaveAdjustmentLookup, "search");
75 LOG.debug(leaveAdjustmentLookup.asXml());
76 Assert.assertTrue("Page contains test LeaveAdjustment", leaveAdjustmentLookup.asText().contains("AC1"));
77 Assert.assertFalse("Page should not contain edit action", leaveAdjustmentLookup.asText().contains("edit"));
78 }
79
80 @Test
81 public void testAddNew() throws Exception {
82 String baseUrl = TkTestConstants.Urls.LEAVE_ADJUSTMENT_MAINT_NEW_URL;
83 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
84 Assert.assertNotNull(page);
85
86 HtmlForm form = page.getFormByName("KualiForm");
87 Assert.assertNotNull("Search form was missing from page.", form);
88
89 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Leave Adjustment - test");
90 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
91 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.principalId", "admin");
92 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.accrualCategory", "myAC");
93 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.earnCode", "myLC");
94
95 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
96 Assert.assertNotNull("Could not locate submit button", input);
97 HtmlElement element = page.getElementByName("methodToCall.route");
98 page = element.click();
99 HtmlUnitUtil.createTempFile(page);
100 Assert.assertTrue("page text contains:\n" + "'myAC' does not exist", page.asText().contains("'myAC' does not exist"));
101
102 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.accrualCategory", "AC1");
103 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.earnCode", "testLC");
104 element = page.getElementByName("methodToCall.route");
105 page = element.click();
106 Assert.assertFalse("page text contains:\n" + "'AC1' does not exist", page.asText().contains("'AC1' does not exist"));
107
108 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.principalId", "admin");
109 element = page.getElementByName("methodToCall.route");
110 page = element.click();
111 Assert.assertFalse("page text contains:\n" + "'IU-SM' does not exist", page.asText().contains("'IU-SM' does not exist"));
112
113 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.earnCode", "EC");
114 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.adjustmentAmount", "2.45");
115 element = page.getElementByName("methodToCall.route");
116 page = element.click();
117 Assert.assertTrue("page text does not contain amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 1 decimal point."));
118 }
119 }