1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.department.earncode;
17
18 import java.sql.Date;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.joda.time.DateTime;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.kuali.hr.lm.earncodesec.EarnCodeSecurity;
28 import org.kuali.hr.test.KPMETestCase;
29 import org.kuali.hr.time.test.HtmlUnitUtil;
30 import org.kuali.hr.time.test.TkTestConstants;
31 import org.kuali.hr.time.util.TKUtils;
32 import org.kuali.hr.time.util.TkConstants;
33 import org.kuali.rice.krad.service.KRADServiceLocator;
34
35 import com.gargoylesoftware.htmlunit.html.HtmlInput;
36 import com.gargoylesoftware.htmlunit.html.HtmlPage;
37
38 public class EarnCodeSecurityMaintenanceTest extends KPMETestCase{
39 private static final java.sql.Date TEST_DATE_OLD = new Date((new DateTime(2009, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
40 private static final java.sql.Date TEST_DATE_NEW = new Date((new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
41 private static final String EARN_CODE = "RGN";
42 private static final String DEPT = "TEST-DEPT";
43 private static final String SAL_GROUP = "SD1";
44 private static String hrDeptEarnCodeId;
45 private static String dupTkDeptEarnCodeId;
46
47 @Test
48 public void testEarnCodeSecurityMaint() throws Exception {
49 HtmlPage deptEarnCodeLookup = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_SECURITY_MAINT_URL);
50 deptEarnCodeLookup = HtmlUnitUtil.clickInputContainingText(deptEarnCodeLookup, "search");
51 Assert.assertTrue("Page contains test EarnCodeSecurity", deptEarnCodeLookup.asText().contains(DEPT));
52 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(deptEarnCodeLookup, "edit", "hrEarnCodeSecurityId=" + hrDeptEarnCodeId);
53 Assert.assertTrue("Maintenance Page contains test EarnCodeSecurity",maintPage.asText().contains(DEPT));
54 }
55
56 @Test
57 public void testEarnCodeSecurityMaintForErrorMessages() throws Exception {
58
59 String testDept = "testDept";
60 String testSalGroup = "testSalGroup";
61 String testEarnCode = "testEarnCode";
62
63
64 HtmlPage deptEarnCodeLookup = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_SECURITY_MAINT_URL);
65 deptEarnCodeLookup = HtmlUnitUtil.clickInputContainingText(deptEarnCodeLookup, "search");
66 Assert.assertTrue("Page contains test EarnCodeSecurity", deptEarnCodeLookup.asText().contains(DEPT));
67 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(deptEarnCodeLookup, "edit", "hrEarnCodeSecurityId");
68
69 HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
70 maintPage, "* Document Description");
71 inputForDescription.setValueAttribute("Test_Description");
72
73 HtmlInput inputForDept = HtmlUnitUtil.getInputContainingText(maintPage, "document.newMaintainableObject.dept");
74 inputForDept.setValueAttribute(testDept);
75
76 HtmlInput inputForSalGroup = HtmlUnitUtil.getInputContainingText(maintPage, "document.newMaintainableObject.hrSalGroup");
77 inputForSalGroup.setValueAttribute(testSalGroup);
78
79 HtmlInput inputForEarnCode = HtmlUnitUtil.getInputContainingText(maintPage, "document.newMaintainableObject.earnCode");
80 inputForEarnCode.setValueAttribute(testEarnCode);
81
82 HtmlPage resultantPageAfterEdit = HtmlUnitUtil
83 .clickInputContainingText(maintPage, "submit");
84
85
86 HtmlUnitUtil.createTempFile(resultantPageAfterEdit);
87 Assert.assertTrue("Maintenance Page contains test deptErrormessage",
88 resultantPageAfterEdit.asText().contains(
89 "The specified department '"
90 + testDept
91 + "' does not exist."));
92
93 Assert.assertTrue("Maintenance Page contains test SalGroupErrormessage",
94 resultantPageAfterEdit.asText().contains(
95 "The specified Salgroup '"
96 + testSalGroup
97 + "' does not exist."));
98
99 Assert.assertTrue("Maintenance Page contains test Earncode",
100 resultantPageAfterEdit.asText().contains(
101 "The specified Earncode '"
102 + testEarnCode
103 + "' does not exist."));
104
105
106 }
107
108 @Test
109 public void testEditingEarnCodeSecurityMaint() throws Exception {
110 HtmlPage deptEarnCodeLookup = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_SECURITY_MAINT_URL);
111 deptEarnCodeLookup = HtmlUnitUtil.clickInputContainingText(deptEarnCodeLookup, "search");
112 Assert.assertTrue("Page contains TEST-DEPT", deptEarnCodeLookup.asText().contains(DEPT));
113 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(deptEarnCodeLookup, "edit", "hrEarnCodeSecurityId=" + hrDeptEarnCodeId);
114 Assert.assertFalse("Maintenance Page contains Warnings",maintPage.asText().contains("Warnings for this Section:"));
115 Assert.assertFalse("Maintenance Page contains Warning message",maintPage.asText().contains("There is a newer version of this Department Earn Code."));
116
117 this.createDuplicateEarnCodeSecurity();
118 deptEarnCodeLookup = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_SECURITY_MAINT_URL);
119 this.setFieldValue(deptEarnCodeLookup, "earnCode", EARN_CODE);
120 this.setFieldValue(deptEarnCodeLookup, "dept", DEPT);
121 this.setFieldValue(deptEarnCodeLookup, "effectiveDate", "08/01/2010");
122 this.setFieldValue(deptEarnCodeLookup, "activeYes", "on");
123 this.setFieldValue(deptEarnCodeLookup, "historyYes", "on");
124
125 deptEarnCodeLookup = HtmlUnitUtil.clickInputContainingText(deptEarnCodeLookup, "search");
126 maintPage = HtmlUnitUtil.clickAnchorContainingText(deptEarnCodeLookup, "edit", "hrEarnCodeSecurityId="+hrDeptEarnCodeId);
127 Assert.assertTrue("Maintenance Page contains Warnings",maintPage.asText().contains("Warnings for this Section:"));
128 Assert.assertTrue("Maintenance Page contains Warning message",maintPage.asText().contains("There is a newer version of this Department Earn Code."));
129 }
130
131 public void createNewEarnCodeSecurity() {
132
133 Collection<EarnCodeSecurity> earnCodeSecurities = KRADServiceLocator.getBusinessObjectService().findMatching(EarnCodeSecurity.class, Collections.singletonMap("earnCode", EARN_CODE));
134 KRADServiceLocator.getBusinessObjectService().deleteMatching(EarnCodeSecurity.class, Collections.singletonMap("earnCode", EARN_CODE));
135 EarnCodeSecurity deptEarnCode = new EarnCodeSecurity();
136 deptEarnCode.setActive(true);
137 deptEarnCode.setEarnCode(EARN_CODE);
138 deptEarnCode.setDept(DEPT);
139 deptEarnCode.setHrSalGroup(SAL_GROUP);
140 deptEarnCode.setEmployee(false);
141 deptEarnCode.setEffectiveDate(TEST_DATE_OLD);
142 deptEarnCode.setLocation("test");
143 deptEarnCode.setEarnCodeType("T");
144 deptEarnCode = KRADServiceLocator.getBusinessObjectService().save(deptEarnCode);
145 hrDeptEarnCodeId = deptEarnCode.getHrEarnCodeSecurityId();
146 }
147
148 public void createDuplicateEarnCodeSecurity() {
149 EarnCodeSecurity deptEarnCode = new EarnCodeSecurity();
150 deptEarnCode.setActive(true);
151 deptEarnCode.setEarnCode(EARN_CODE);
152 deptEarnCode.setDept(DEPT);
153 deptEarnCode.setHrSalGroup(SAL_GROUP);
154 deptEarnCode.setEmployee(false);
155 deptEarnCode.setEffectiveDate(TEST_DATE_NEW);
156 deptEarnCode.setLocation("test");
157 deptEarnCode.setEarnCodeType("T");
158 deptEarnCode = KRADServiceLocator.getBusinessObjectService().save(deptEarnCode);
159 dupTkDeptEarnCodeId = deptEarnCode.getHrEarnCodeSecurityId();
160 }
161
162 @Override
163 public void tearDown() throws Exception {
164 EarnCodeSecurity deptEarnCodeObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCodeSecurity.class, hrDeptEarnCodeId);
165 KRADServiceLocator.getBusinessObjectService().delete(deptEarnCodeObj);
166 if (StringUtils.isNotBlank(dupTkDeptEarnCodeId)) {
167 deptEarnCodeObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(EarnCodeSecurity.class, dupTkDeptEarnCodeId);
168 KRADServiceLocator.getBusinessObjectService().delete(deptEarnCodeObj);
169 }
170 super.tearDown();
171 }
172
173
174 @Override
175 public void setUp() throws Exception {
176 super.setUp();
177 this.createNewEarnCodeSecurity();
178 }
179 }