1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.earncode.service;
17
18 import java.sql.Date;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.log4j.Logger;
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.assignment.Assignment;
28 import org.kuali.hr.time.earncode.EarnCode;
29 import org.kuali.hr.time.service.base.TkServiceLocator;
30 import org.kuali.hr.time.test.HtmlUnitUtil;
31 import org.kuali.hr.time.test.TkTestConstants;
32 import org.kuali.hr.time.util.TKUtils;
33
34 import com.gargoylesoftware.htmlunit.html.HtmlInput;
35 import com.gargoylesoftware.htmlunit.html.HtmlPage;
36 import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
37 import com.gargoylesoftware.htmlunit.html.HtmlSelect;
38 import org.kuali.rice.kim.api.identity.principal.Principal;
39 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
40
41 public class EarnCodeServiceImplTest extends KPMETestCase {
42
43
44 public static final String TEST_USER = "admin";
45 public static final Long TEST_ASSIGNMENT_JOB_NUMBER = 1L;
46 public static final Long TEST_ASSIGNMENT_JOB_NUMBER_2 = 2L;
47 public static final Long TEST_ASSIGNMENT_JOB_NUMBER_3 = 3L;
48 public static final Long TEST_ASSIGNMENT_JOB_NUMBER_4 = 4L;
49
50 @SuppressWarnings("unused")
51 private static final Logger LOG = Logger.getLogger(EarnCodeServiceImplTest.class);
52
53 EarnCodeService earnCodeService = null;
54
55
56 @Before
57 public void setUp() throws Exception {
58 super.setUp();
59 earnCodeService=TkServiceLocator.getEarnCodeService();
60 }
61
62 @Test
63 public void getEarnCodes() throws Exception {
64 Date asOfDate = TKUtils.getTimelessDate(null);
65 List<Assignment> assignments = TkServiceLocator.getAssignmentService().getAssignments(TEST_USER, asOfDate);
66 Assert.assertNotNull(assignments);
67 Assert.assertTrue("Emtpy assignment list", !assignments.isEmpty());
68
69 Assignment assignment1 = null;
70 Assignment assignment2 = null;
71 Assignment assignment3 = null;
72 Assignment assignment4 = null;
73 for (Assignment a : assignments) {
74 if (a.getJobNumber().equals(TEST_ASSIGNMENT_JOB_NUMBER)) {
75 assignment1 = a;
76 } else if (a.getJobNumber().equals(TEST_ASSIGNMENT_JOB_NUMBER_2)) {
77 assignment2 = a;
78 } else if (a.getJobNumber().equals(TEST_ASSIGNMENT_JOB_NUMBER_3)) {
79 assignment3 = a;
80 } else if (a.getJobNumber().equals(TEST_ASSIGNMENT_JOB_NUMBER_4)) {
81 assignment4 = a;
82 }
83 }
84
85
86 Assert.assertNotNull("Test assignment not found.", assignment1);
87 Assert.assertNotNull("Test assignment not found.", assignment2);
88 Assert.assertNotNull("Test assignment not found.", assignment3);
89 Assert.assertNotNull("Test assignment not found.", assignment4);
90
91
92
93
94 List<EarnCode> earnCodes1t = earnCodeService.getEarnCodesForTime(assignment1, asOfDate);
95 Assert.assertEquals("Wrong number of earn codes returned.", 7, earnCodes1t.size());
96 List<EarnCode> earnCodes1l = earnCodeService.getEarnCodesForLeave(assignment1, asOfDate, false);
97 Assert.assertEquals("Wrong number of earn codes returned.", 0, earnCodes1l.size());
98 List<EarnCode> earnCodes1lt= earnCodeService.getEarnCodesForLeaveAndTime(assignment1, asOfDate, false);
99 Assert.assertEquals("Wrong number of earn codes returned.", 7, earnCodes1lt.size());
100
101
102 List<EarnCode> earnCodes2t = earnCodeService.getEarnCodesForTime(assignment2, asOfDate);
103 Assert.assertEquals("Wrong number of earn codes returned.", 2, earnCodes2t.size());
104 List<EarnCode> earnCodes2l = earnCodeService.getEarnCodesForLeave(assignment2, asOfDate, false);
105 Assert.assertEquals("Wrong number of earn codes returned.", 0, earnCodes2l.size());
106 List<EarnCode> earnCodes2lt = earnCodeService.getEarnCodesForLeaveAndTime(assignment2, asOfDate, false);
107 Assert.assertEquals("Wrong number of earn codes returned.", 2, earnCodes2lt.size());
108
109
110 List<EarnCode> earnCodes3t = earnCodeService.getEarnCodesForTime(assignment3, asOfDate);
111 Assert.assertEquals("Wrong number of earn codes returned.",1, earnCodes3t.size());
112 List<EarnCode> earnCodes3l = earnCodeService.getEarnCodesForLeave(assignment3, asOfDate, false);
113 Assert.assertEquals("Wrong number of earn codes returned.",0, earnCodes3l.size());
114 List<EarnCode> earnCodes3lt = earnCodeService.getEarnCodesForLeaveAndTime(assignment3, asOfDate, false);
115 Assert.assertEquals("Wrong number of earn codes returned.",1, earnCodes3lt.size());
116 }
117
118 @Test
119 public void testEarnCodeMaintenancePage() throws Exception{
120
121 HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_MAINT_URL);
122 earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
123 Assert.assertTrue("Page contains SDR entry", earnCodeLookUp.asText().contains("SDR"));
124 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit","1");
125
126
127 HtmlSelect inputText= maintPage.getHtmlElementById("document.newMaintainableObject.recordMethod");
128 inputText.setDefaultValue("H");
129
130 HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
131 maintPage, "* Document Description");
132 inputForDescription.setValueAttribute("Description");
133
134
135
136 HtmlRadioButtonInput hb = maintPage.getHtmlElementById("document.newMaintainableObject.fractionalTimeAllowed99");
137 hb.setChecked(true);
138
139 HtmlPage resultantPageAfterEdit = HtmlUnitUtil
140 .clickInputContainingText(maintPage, "submit");
141 System.out.println(resultantPageAfterEdit.asText());
142
143
144
145
146
147
148
149
150
151
152 inputForDescription = HtmlUnitUtil.getInputContainingText(
153 maintPage, "* Document Description");
154 inputForDescription.setValueAttribute("Description");
155 resultantPageAfterEdit = HtmlUnitUtil
156 .clickInputContainingText(maintPage, "submit");
157
158
159 }
160
161 @Test
162 public void testGetEarnCodesForDisplay() throws Exception{
163
164 Principal testPrincipal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName("testUser");
165 Map<String, String> earnCodesDisplay = earnCodeService.getEarnCodesForDisplay(testPrincipal.getPrincipalId(), false);
166
167
168
169
170 }
171 }