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 List<EarnCode> earnCodes = earnCodeService.getEarnCodes(assignment1, asOfDate);
93 Assert.assertEquals("Wrong number of earn codes returned.", 8, earnCodes.size());
94
95
96 earnCodes = earnCodeService.getEarnCodes(assignment2, asOfDate);
97 Assert.assertEquals("Wrong number of earn codes returned.", 3, earnCodes.size());
98
99
100 earnCodes = earnCodeService.getEarnCodes(assignment3, asOfDate);
101 Assert.assertEquals("Wrong number of earn codes returned.",2, earnCodes.size());
102 }
103
104 @Test
105 public void testEarnCodeMaintenancePage() throws Exception{
106
107 HtmlPage earnCodeLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.EARN_CODE_MAINT_URL);
108 earnCodeLookUp = HtmlUnitUtil.clickInputContainingText(earnCodeLookUp, "search");
109 Assert.assertTrue("Page contains SDR entry", earnCodeLookUp.asText().contains("SDR"));
110 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(earnCodeLookUp, "edit","1");
111
112
113 HtmlSelect inputText= maintPage.getHtmlElementById("document.newMaintainableObject.recordMethod");
114 inputText.setDefaultValue("H");
115
116 HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
117 maintPage, "* Document Description");
118 inputForDescription.setValueAttribute("Description");
119
120
121
122 HtmlPage resultantPageAfterEdit = HtmlUnitUtil
123 .clickInputContainingText(maintPage, "submit");
124 System.out.println(resultantPageAfterEdit.asText());
125
126
127
128
129
130
131
132
133
134
135 inputForDescription = HtmlUnitUtil.getInputContainingText(
136 maintPage, "* Document Description");
137 inputForDescription.setValueAttribute("Description");
138 resultantPageAfterEdit = HtmlUnitUtil
139 .clickInputContainingText(maintPage, "submit");
140
141
142 }
143
144 }