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