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